Operating Systems · File Allocation Methods
Linked List Allocation
Overview
Linked-list allocation is a non-contiguous file allocation method in which a file's logical blocks are scattered across any free physical disk blocks and chained together by pointers.
It matters because it eliminates external fragmentation and lets every disk block be used, at the cost of slow random access and per-block pointer overhead.
Key concepts
- Linked-list allocation: a non-contiguous file allocation method.
A file does not need contiguous disk blocks; its logical blocks can be stored in any free physical disk blocks, and each block contains a pointer to the next block of the same file. - Starting physical block: every file stores the physical block of its first file block, usually in its file metadata / directory entry. From that starting block, the system follows pointers to reach the remaining blocks.
- Pointer placement: the pointer can be kept at the beginning or at the end of the block. Keeping it at the beginning is better because the system does not have to go to the end of the block to find the next-block pointer.
- End of file: the last block must indicate end of file.
- External fragmentation avoided: if a file needs 4 blocks and those blocks are not available contiguously but are available at random free locations, the file can still be allocated.
A free block lying in the middle of other allocated blocks can still become part of some file's linked chain. - Internal fragmentation in the last block: the only space lost. It cannot be avoided: if a file needs only part of a block, a full block must still be allocated.
- Pointer overhead: each block must store a pointer, which takes a few bytes; contiguous allocation needs no such per-block pointers.
- Slow random access: reading a file may require moving to the track containing physical block 4, then to another track containing physical block 7 if 7 is on a different track, and so on, causing additional read/write head movement and delay.
How it works
- The file's directory entry / metadata records only the starting physical block of the first file block.
- The physical blocks assigned to the file may be scattered over the disk; they are linked by pointers stored in each block.
- To read the file in order, start at the starting block, read the block, follow its pointer to the next block, and repeat until a block indicates end of file.
- To access a later logical block, the system must first access block 0 to get the pointer to block 1, then access block 1 to get the pointer to block 2, and so on — even for random access, the chain is traversed from the beginning.
Worked examples
File A uses linked-list allocation:
| Logical file block | Physical disk block | Pointer stored in this physical block | Meaning |
|---|---|---|---|
| 0 | 4 | 7 | next file block is at physical block 7 |
| 1 | 7 | 12 | next file block is at physical block 12 |
| 2 | 12 | 10 | next file block is at physical block 10 |
| 3 | 10 | end of file | no further block in file A |
The physical blocks 4, 7, 12, 10 are not contiguous. File A's directory entry / metadata stores: start physical block = 4.
Reading the file in order:
- Start from physical block 4. Read file block 0. Pointer says next block is 7.
- Go to physical block 7. Read file block 1. Pointer says next block is 12.
- Go to physical block 12. Read file block 2. Pointer says next block is 10.
- Go to physical block 10. Read file block 3. Pointer indicates end of file.
Accessing logical block 2 of file A:
- Start at directory entry: start = 4.
- Read physical block 4 to get pointer 7.
- Read physical block 7 to get pointer 12.
- Read physical block 12, which contains logical block 2.
Reaching logical block 2 requires following the chain from block 0 through block 1 to block 2; it is not a direct random seek to the desired block.
Comparison
| Aspect | Contiguous allocation | Linked-list allocation |
|---|---|---|
| Physical placement | File blocks are contiguous | File blocks may be scattered, e.g. 4, 7, 12, 10 |
| External fragmentation | Can occur | Avoided; randomly available blocks can still be used |
| Disk block usage | Not every block may be usable if it is not contiguous with a free run | Every disk block can be used |
| Internal fragmentation | Last-block internal fragmentation remains | Last-block internal fragmentation remains; cannot be avoided |
| Random access | Once the head seeks to a track, it can stay there until the file is fully read | Slow; may require head movement from track to track following pointers |
| Pointer overhead | No per-block pointer | Each block stores a pointer, taking a few bytes |
Revision summary
- Linked-list allocation is non-contiguous: the file stores only the starting physical block; each block points to the next.
- Place the pointer at the beginning of the block so it is found without scanning to the end.
- The last block must indicate end of file.
- Main advantage: external fragmentation is avoided; every disk block can be used.
- Only internal fragmentation in the last block remains, and it cannot be avoided.
- Main disadvantage: random access is slow because the disk head may move between tracks while following pointers.
- Additional disadvantage: each block carries a pointer consuming a few bytes.
- To reach a later block, the chain must be followed from the starting block through all preceding blocks; this limitation motivates a changed implementation in the next method.
Previous-year exam insights
- In linked allocation, inserting or deleting a block in the middle of a file only requires updating a constant number of pointers (the predecessor's pointer and the new block's pointer), so insertion and deletion are easy; contiguous allocation requires shifting all subsequent blocks.
Asked inUGC NET 2015 - External fragmentation is absent in linked and indexed allocation (and present in contiguous allocation); internal fragmentation in the last block is present in all three.
Asked inGATE 2017 - In linked allocation, a new block can be inserted in the middle of a file without moving any existing data blocks, since the new block may be placed in any free disk block and linked in; in contiguous allocation, inserting in the middle requires shifting all following blocks (or copying the whole file).
Asked inGATE 2022 - Indexed allocation stores all block pointers of a file in a single index block, giving direct (random) access to any logical block without traversing a chain; the index block itself costs one block of overhead and limits the maximum file size unless multilevel (indirect) indexing is used.
Asked inUGC NET 2020GATE 2017 - For UNIX-style inodes: with block size B and pointer size P, the number of addresses per block is B/P;
maximum file size = (number of direct blocks + + ... ) × B, counting each indirect level once.
Asked inUGC NET 2020 - Linked allocation does not support efficient direct/random access: accessing the k-th block requires k sequential block reads, so it is suitable for sequential-access files but poor for random access.
Asked inGATE 2022