In: Other
Consider a file currently consisting of 200 blocks. Assume that the file control block (and the index block, in the case of indexed allocation) is already in memory. Calculate how many disk I/O operations are required for contiguous, linked, and indexed (single-level) allocation strategies, if the following conditions hold. In the contiguous allocation case, assume that there is no room to grow in the beginning, but there is room to grow in the end. Assume that the block information to be added is stored in memory. For linked allocation, there is a tail pointer pointing to the last node.
More Assumptions:
Read one whole block = one I/O operation
Write one whole block = one I/O operation
For linked allocation, a file allocation table (FAT) is not used, i.e., only the address of the starting block is in memory
All preparation of a block (including putting in the data and any link value) is done in main memory and then the block is written to disk with one write operation
The file control block does not have to be written to disk after a change (this is typical where many operations are performed on a file)
At most one index block is required per file and it does not have to be written to disk after a change.
For contiguous, linked and indexed allocations, assume that no I/O operations are necessary to add a freed block to the free list
Note that while calculating the total number of I/O operations for each, also indicate how many came from r(read) and w(write).
Contiguous | Linked | Indexed | |
1. The block is added at the beginning |
401 | 1 | 1 |
2. The block is added at the end |
1 | 2 | 1 |
3. The block is removed from the beginning |
0 or 398 | 1 | 0 |
4. The block is removed from the end |
0 | 200 | 0 |
1. The block is added at the the beginning.
Contiguous: Shift all the block down and an extra operation to write. As a result, there are 401 I/O operations.
Linked: Add to block at the beginning 1 write operation.
Indexed: Add to block at the beginning 1 write operation.
2. The block is added at the end
Contiguous: Add to block at the end 1 write operation.
Linked: Add to block at the end - 1 write operation and to fix the last pointer -1 write operation. So 2
Indexed: Add to block at the end 1 write operation.
3. The block is removed from the beginning
Contiguous: Only the FCB has to be updated which is in memory so there are 0. Or, the last 199 blocks can be shifted down for which 199*2 = 398 I/O
Linked: 1 I/O operation - reset the starting pointer
Indexed: 0 I/O operations - index block has to be updated
4. The block is removed from the end
Contiguous: 0 I/O operations file control block has to be updated
Linked: 200 I/O operations. Read first 199 blocks and reset the pointer.
Indexed: 0 I/O operations index block has to be updated