10.3 File Allocation Methods: Contiguous, Linked & Indexed Allocation
💡 Core Intuition
🍳 The Everyday Analogy: The City Warehouse Storage Strategies
Imagine managing a massive municipal warehouse where cargo shipments of varying sizes arrive daily:
The Warehouse Allocation Paradigms
Contrasting physical storage strategies with operating system disk allocation
Reserved Adjacent Aisles
Shipment A occupies consecutive bays 10 through 14. A forklift can zip down the aisle in one continuous straight line, but if bay 15 is occupied, shipment A cannot expand.
Scattered Bays with Clue Slips
Crates are placed in any empty bay. Inside crate 1 is a note with the address of crate 2. No empty space is wasted, but finding crate 10 requires visiting crates 1 through 9.
Master Control Ledger
A single master clipboard at the manager's desk lists the exact bay coordinates of every crate in the shipment. Any crate can be located immediately with zero searching.
In an operating system, the file allocation problem fundamentally addresses two competing engineering goals:
- Effective Disk Space Utilization: Minimizing fragmentation and eliminating wasted storage capacity.
- Fast File Access Performance: Minimizing mechanical disk seek times and rotational delays when performing both sequential and random file I/O operations.
The three primary file allocation methods employed across operating systems are:
- Contiguous Allocation
- Linked Allocation (including the File Allocation Table / FAT optimization)
- Indexed Allocation (including multi-level and hybrid indexing)
🏛️ Method 1: Contiguous Allocation
Structural Architecture
Under contiguous allocation, each file is required to occupy a set of linearly consecutive disk blocks. Because disk block addresses define a linear ordering on the storage media, accessing block immediately after block requires zero actuator head seek movement (assuming the blocks reside on the same cylinder/track).
| File Name | Starting Block () | Length () | Physical Disk Blocks Allocated |
|---|---|---|---|
count | 0 | 2 | Blocks 0, 1 |
f | 6 | 2 | Blocks 6, 7 |
tr | 14 | 3 | Blocks 14, 15, 16 |
mail | 19 | 6 | Blocks 19, 20, 21, 22, 23, 24 |
list | 28 | 4 | Blocks 28, 29, 30, 31 |
The directory entry for a contiguously allocated file is exceptionally compact, requiring only two fields:
- Starting Block Address ()
- Length () (number of consecutive blocks allocated)
Access Mechanics & Formulas
Advantages and Engineering Drawbacks
⏱️ Mathematical Case Study: Contiguous vs. Non-Contiguous Read Latency
Consider a disk subsystem with the following parameters:
- Geometry: 8 sectors per track, 512 bytes per sector
- Rotational Speed:
- Average Seek Time ():
- Workload: Read an entire file consisting of 8 sectors.
1. Fundamental Timing Derivations:
- Time for one full rotation ():
- Average Rotational Latency ():
- Track Transfer Time ():
2. Case I: Contiguous Allocation
All 8 sectors are stored sequentially on the same track. The disk head seeks to the target cylinder once, waits for the initial sector to arrive underneath the head, and then streams all 8 sectors in one continuous revolution:
3. Case II: Non-Contiguous Allocation (Scattered Blocks)
The 8 sectors are scattered randomly across different tracks across the disk platters. For every individual sector, the actuator arm must perform a separate seek and rotational wait:
Non-contiguous allocation takes versus for contiguous allocation—nearly a performance penalty purely due to mechanical seek and rotational overhead!
🌀 Sector Interleaving
In early disk systems, disk controllers required a brief processing delay after reading a sector into the controller's internal SRAM buffer before it could accept the next sector. If sectors were numbered sequentially (), by the time the controller finished processing sector , sector had already rotated past the read head, forcing the head to wait an entire revolution () to read sector !
To solve this, hardware engineers introduced Sector Interleaving:
- Single Interleaving: Requires 2 complete rotations to read all sectors of 1 track. .
- Double Interleaving: Requires 2.75 to 3 rotations to read 1 track. .
🔗 Method 2: Linked Allocation
Structural Architecture
Linked allocation eliminates external fragmentation entirely. Each file is represented as a linked list of disk blocks. Disk blocks may be scattered arbitrarily across the entire storage volume.
| File Name | Start Block | End Block |
|---|---|---|
jeep | 9 | 25 |
Linked File Block Pointer Chain
Dynamic allocation chain for file 'jeep' (Start: Block 9, End: Block 25)
Initial Block (Head)
Stores first 508 bytes of file data; tail pointer addresses Block 16.
Second Block
Stores next payload bytes; tail pointer addresses Block 1.
Third Block
Stores next payload bytes; tail pointer addresses Block 10.
Fourth Block
Stores next payload bytes; tail pointer addresses Block 25.
Terminal Block (Tail)
Stores final payload bytes; tail pointer stores -1 (EOF / Nil).
The directory entry stores only two block pointers:
- Start Block
- End Block
Each physical disk block dedicates a small portion of its internal storage (e.g., 4 or 8 bytes) to store a pointer to the next allocated block.
Usable Data Capacity per Block
If disk block size is bytes and a disk block pointer requires bytes:
For example, with and :
- Data payload .
- Pointer space overhead .
Advantages and Engineering Vulnerabilities
💾 The File Allocation Table (FAT) Solution
To solve the slow random access and reliability hazards of linked allocation without reintroducing external fragmentation, MS-DOS and early Windows designed the File Allocation Table (FAT):
| Disk Block Number | Value (Next Block Entry) | Status / Meaning |
|---|---|---|
0 | 0 (Free) | Unallocated disk block |
| ... | ... | ... |
9 | 16 | Start block of jeep points to Block 16 |
10 | 25 | Part of jeep chain points to Block 25 |
16 | 1 | Part of jeep chain points to Block 1 |
1 | 10 | Part of jeep chain points to Block 10 |
25 | -1 (0xFFFF) | End-of-File (EOF) marker for jeep |
FAT Acceleration Architecture
Decoupling pointer navigation from physical disk head travel
The FAT table is stored at the beginning of the volume and cached entirely in RAM during system boot.
To find logical block k, the kernel chases pointers inside the RAM-cached FAT table at nanosecond CPU speeds.
Once the physical target block address is discovered in RAM, the disk head seeks directly to that exact target block.
📑 Method 3: Indexed Allocation
Structural Architecture
Indexed allocation completely resolves the limitations of both contiguous allocation (fragmentation, expansion limits) and linked allocation (slow random access, pointer corruption).
Instead of scattering pointers across individual data blocks, indexed allocation brings all block pointers together into a single dedicated block: the Index Block.
| File Name | Index Block Address |
|---|---|
jeep | Block 19 |
| Index Block Entry | Target Physical Disk Block | File Logical Block Mapping |
|---|---|---|
Entry 0 | Block 9 | Logical Block 0 (Bytes 0 – 511) |
Entry 1 | Block 16 | Logical Block 1 (Bytes 512 – 1023) |
Entry 2 | Block 1 | Logical Block 2 (Bytes 1024 – 1535) |
Entry 3 | Block 10 | Logical Block 3 (Bytes 1536 – 2047) |
Entry 4 | Block 25 | Logical Block 4 (Bytes 2048 – 2559) |
Entry 5 .. N | -1 (Nil) | Unallocated pointer slots |
- Each file has its own private Index Block.
- The -th entry in the index block points to the -th physical data block of the file.
- The directory entry contains only one pointer: the physical address of the file's index block.
Operational Characteristics
Scaling to Very Large Files
If a disk block is and a block address is , one index block holds:
A file size ceiling is unacceptably small for modern workloads. Operating systems resolve this limitation through three indexing architectures:
Large File Indexing Architectures
Strategies to scale index block capacity beyond a single physical block
Linked Indexing Scheme
Multilevel Indexing Scheme
Combined Scheme (UNIX Inode)
📊 Comprehensive Allocation Methods Comparison Matrix
| Architectural Feature | Contiguous Allocation | Linked Allocation | FAT (Linked in RAM) | Indexed Allocation |
|---|---|---|---|---|
| Directory Entry | [Start Block, Length] | [Start, End] | [Start Block] | [Index Block] |
| Sequential Access Speed | Fastest (Zero seek between adjacent blocks) | Slow (Seeks between scattered blocks) | Moderate (Head seeks between blocks) | Moderate (Index lookup + seek) |
| Direct / Random Access | Instant () | Impossible ( seeks) | Fast (RAM pointer chase + 1 seek) | Fast (1 index read + 1 seek) |
| External Fragmentation | Severe | Zero | Zero | Zero |
| Internal Fragmentation | Only in the final allocated block | Only in the final allocated block | Only in the final allocated block | Final block + Index block waste |
| File Expansion Ease | Difficult (Requires relocation) | Trivial (Append to tail) | Trivial (Link new FAT entry) | Trivial (Add pointer to index block) |
| Metadata Space Overhead | Lowest (2 integers) | bytes per block (Payload misaligned) | Table size total disk capacity | 1 entire block per file |
| Reliability / Fault Tolerance | High | Low (Broken link corrupts file) | High (FAT duplicated on disk) | High (Pointers centralized) |
🧮 Numerical & Conceptual Exam Problems
Problem 1: Linked Allocation Pointer Capacity Calculation
Question:
A storage system has a disk block size of (). It employs linked allocation where each block devotes for the next-block pointer.
- What is the usable payload of each disk block?
- If a file has an exact size of (), how many total disk blocks must be allocated to store this file?
- How many bytes of internal fragmentation occur in the final block?
Step-by-Step Solution:
-
Usable Payload per Block:
-
Total Blocks Required:
-
Internal Fragmentation in Block 36:
- The first 35 blocks store: .
- Remaining bytes to store in the 36th block:
- Internal fragmentation in the 36th block:
Problem 2: Two-Level Indexed Allocation Maximum File Size
Question:
A file system uses a two-level indexed allocation scheme. The disk block size is () and disk block addresses are () long.
The directory entry points to a Master Index Block. Each entry in the Master Index Block points to a Second-Level Index Block, and each entry in the Second-Level Index Block points to a Data Block.
Calculate:
- The number of pointers per index block.
- The maximum possible file size supported by this two-level scheme.
- How many disk block reads are required to read the first byte of data from logical block 500 (assuming cold cache)?
Step-by-Step Solution:
-
Number of Pointers per Block ():
-
Maximum File Size:
- The Master Index Block holds 512 pointers to second-level index blocks.
- Each second-level index block holds 512 pointers to data blocks.
- Total addressable data blocks:
- Maximum File Size:
-
Disk I/O Operations for Cold Read: To access any byte in data block 500:
- Read 1: Read the Master Index Block from disk into RAM.
- Read 2: Read the appropriate Second-Level Index Block () from disk.
- Read 3: Read the physical data block () from disk.