Comp111: Operating Systems
Classroom Exercise 16 Answers
Disks and Layers
Fall 2017

  1. Over time, disks naturally become "fragmented", in the sense that the blocks of a single file are spread out all over the disk. Why?
    Answer: As files are created and grow, they are not pre-allocated, but instead, are incrementally allocated as the file is written. With many processes simultaneously writing files, the result is external fragmentation (at the level of the disk) because contiguous blocks are simply not available when a new block is needed.
  2. A disk can be "defragmented" by ensuring that -- to the extent possible -- blocks from a single file are stored next to one another on the same track. Why is this advantageous?
    Answer: A disk is -- first and foremost -- a spinning physical device. Putting the blocks for a file on the same track means that they can be read in one rotation of the disk. Multiple tracks require multiple rotations (and intervening arm seeks) to be read.
  3. Is there any conceivable advantage for the filesystem driver to know the geometry of the disk (rather than just the number of blocks)? Why or why not?
    Answer: It would be better to say that there is not enough advantage. The filesystem driver does not know the geometry, because allocating by block numbers is "close enough" to the geometry to give the same advantages.In other words, contiguous blocks in logical (block numbering) space are at most one track away from each other, and at least statistically, they are contiguous. Thus there is little performance advantage from knowing "for sure" whether blocks are contiguous or not.
  4. Physically, a disk is striped with alternating inode groups and block groups, rather than having one large section of inode groups and one large section of block groups. Why is this a good practice?
    Answer: If all inodes were in one place, then every operation that changed an inode would have to wait for the scheduler to schedule that place. However, the answer is a bit more subtle than that. Disk blocks that have not been written yet represent a risk; they can be lost. By distributing the groups, one lowers the average time until the data is updated on disk from memory. Thus the risk of data loss decreases!
  5. The swap partition is not organized like a filesystem; in particular, it allocates each process memory segment as a contiguous set of blocks on the disk. Why is this a good practice?
    Answer: This is so the whole process can be swapped in and out via one (or at most two) disk requests. This reduces the time taken to swap the whole process in or out, which improves performance.

    One might ask why we can actually do this. The reason is that the swap partition is managed by the OS, and thus, can be itself defragmented to improve performance.

  6. (Advanced) When a disk becomes severely corrupted, it is often possible to recover all the files, but without knowing their names. Why?
    Answer: A directory is a special kind of file. If a directory is lost, the files in it remain on disk, but only have numbers. Their names are lost.
  7. (Advanced) The disk scheduler uses the concept of geometry in its scheduling, but the geometry is fake. How can the scheduler deal with the fact that the geometry of tracks is only approximate?
    Answer: The key is the same as the key for an earlier problem. The only thing that is important is what data is on the same track. On average, telling the disk driver to write a contiguous set of blocks (in numbering) is the same thing as instructing it to write a contiguous section of track.