13.07.2015 Views

An Operating Systems Vade Mecum

An Operating Systems Vade Mecum

An Operating Systems Vade Mecum

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

216 File Structures Chapter 6When a file is to be created, if it is large enough to require at least one cylinder, itmay be given a number of entire cylinders from the free-cylinder bit map. We would usecylinder 0 for a one-cylinder file. A two-cylinder file could fit either in cylinders 2 and 3or in cylinders 6 and 7. <strong>An</strong>y larger file will have to be satisfied with non-contiguouscylinders.If a file requires less than a cylinder, we will measure its requirements in tracks. Afile that needs only one track can fit in cylinder 1, either track 1 or 3, or in cylinder 5,track 3. A two-track file can be placed in cylinder 5, tracks 0 and 1. If there are notenough contiguous tracks, cylinders may be converted to tracks. For a three-track file,we can allocate cylinder 0 and mark it in use. We could then use its tracks 0, 1, and 2,and leave 3 marked as available.When a file is deleted and its space becomes available, the tracks it used are madeavailable in the track map. If all the tracks in a cylinder become free, that cylinder ismarked available in the cylinder map, and all the tracks are marked in use.Allocating a file in a single contiguous region has several advantages. The directoryentry (which must also be stored on the disk) needs to indicate only the starting pointand the length of the file. Direct access in the file is easy because the file manager cancompute the block number of any byte in the file. Clustering within files is perfect.Unfortunately, this method produces substantial internal waste, because most filesneed far less than a single track, and even large files are likely to waste about half of thelast track (or cylinder) allocated to them. Also, it depends on knowledge of the size ofthe file before the allocation is made. In many situations the size can be estimated onlyroughly. This deficiency leads to internal waste in some cases and inability to fit the filein other cases. If the file doesn’t fit, it can be broken into individually contiguous piecescalled extents. Within an extent, sequential and direct access are very fast, but the filemanager needs to record where each extent is. That information must be read before anyextent can be found, so access is slower than it would be with a single contiguous region.OS/360 allocates contiguous regions in integral numbers of cylinders or tracks and allowsup to 15 extents.External waste can also be a problem with contiguous allocation. When the diskbecomes relatively full, it may be impossible to create a new file because there are notenough contiguous tracks, even though the total amount of free space is sufficient.Shuffling the files is possible but usually requires that the entire disk be copied to a stagingarea (another disk or magnetic tape) and then copied back.At the other extreme, a file manager can be designed to allocate all files by singleblocks. If a file needs many blocks, they may end up scattered across the disk; we willsee how this dispersion can be controlled. Free-storage allocation can again make use ofa bit map. The map would have a bit for each block on the disk instead of each track oreach cylinder. However, this bit map might be unacceptably large. A medium-large diskhas about 256M bytes. If each block contains 512 bytes, the disk has 512K blocks. Thebit map occupies 64K bytes. We could cache part of the bit map in main store and keepthe full map on the disk, where it would use 128 blocks.One nice trick is to place parts of the map in the free blocks themselves. Instead ofallocating a fixed region of 128 blocks for the bit map, a single block is allocated. Thisblock does not hold a bit map but rather stores the numbers of up to 256 free blocks.(We assume that a block number occupies two bytes.) Each of these free blocks maystore numbers of other free blocks. Thus free space is organized as a tree with a verylarge fan-out. The exercises at the end of this chapter develop this idea further.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!