Java Reference
In-Depth Information
This example illustrates why it is important to keep disk files from be-
coming fragmented, and why so-called “disk defragmenters” can speed up
file processing time. File fragmentation happens most commonly when the
disk is nearly full and the file manager must search for free space whenever
a file is created or changed.
8.3
Buers and Buer Pools
Given the specifications of the disk drive from Example 8.1, we find that it takes
about 9:5+11:11:5 = 26:2 ms to read one track of data on average. It takes about
9:5 + 11:1=2 + (1=256)11:1 = 15:1 ms on average to read a single sector of data.
This is a good savings (slightly over half the time), but less than 1% of the data on
the track are read. If we want to read only a single byte, it would save us effectively
no time over that required to read an entire sector. For this reason, nearly all disk
drives automatically read or write an entire sector's worth of information whenever
the disk is accessed, even when only one byte of information is requested.
Once a sector is read, its information is stored in main memory. This is known
as buffering or caching the information. If the next disk request is to that same
sector, then it is not necessary to read from disk again because the information
is already stored in main memory. Buffering is an example of one method for
minimizing disk accesses mentioned at the beginning of the chapter: Bring off
additional information from disk to satisfy future requests. If information from files
were accessed at random, then the chance that two consecutive disk requests are to
the same sector would be low. However, in practice most disk requests are close
to the location (in the logical file at least) of the previous request. This means that
the probability of the next request “hitting the cache” is much higher than chance
would indicate.
This principle explains one reason why average access times for new disk drives
are lower than in the past. Not only is the hardware faster, but information is also
now stored using better algorithms and larger caches that minimize the number of
times information needs to be fetched from disk. This same concept is also used
to store parts of programs in faster memory within the CPU, using the CPU cache
that is prevalent in modern microprocessors.
Sector-level buffering is normally provided by the operating system and is of-
ten built directly into the disk drive controller hardware. Most operating systems
maintain at least two buffers, one for input and one for output. Consider what
would happen if there were only one buffer during a byte-by-byte copy operation.
The sector containing the first byte would be read into the I/O buffer. The output
operation would need to destroy the contents of the single I/O buffer to write this
byte. Then the buffer would need to be filled again from disk for the second byte,
Search WWH ::




Custom Search