TutorialsOperating Systems
Core CS

Contiguous Allocation

Contiguous allocation is a file allocation technique where an operating system assigns each file a single, unbroken set of consecutive physical blocks on the disk. Because all data blocks reside side by side, reading or writing a file requires minimal disk head movement, making file access exceptionally fast. However, it requires knowing the final file size in advance and frequently leaves unused, fragmented gaps between allocated spaces.

<p></p><h2><!--StartFragment--><p><b style="font-family:Inter, ui-sans-serif, system-ui, -apple-system,">Detailed Definition</b></p><p>Contiguous allocation is a method of disk space management in operating systems where every file is assigned a single, continuous sequence of linear disk blocks. Accessing block $i$ of a file simply requires calculating {Starting Block} + i, enabling direct hardware access without navigating pointers or index tables.</p><p><b>Key Points</b></p><ul><li><p><b>Single contiguous span:</b> A file cannot be split across different parts of the disk; all its data blocks must be adjacent.</p></li><li><p><b>Minimal metadata:</b> The directory entry only stores two values: the <b>start block address</b> and the <b>length</b> (number of blocks).</p></li><li><p><b>Dual access support:</b> It naturally supports both <b>sequential access</b> (reading block by block) and <b>direct/random access</b> (jumping straight to a specific block using basic math).</p></li></ul><p><b>Significance</b></p><ul><li><p><b>Peak I/O speed:</b> It minimizes mechanical disk arm movement (seek time) and rotational latency because the read/write head moves smoothly across adjacent sectors.</p></li><li><p><b>Standard for read-only media:</b> It is widely used in systems where file sizes are fixed and known beforehand, such as optical media (CDs, DVDs) and static embedded firmware.</p></li></ul><p><b>Advantages</b></p><ul><li><p><b>Fast performance:</b> Sequential reads and writes are extremely fast due to zero head repositioning between adjacent blocks.</p></li><li><p><b>Simple implementation:</b> Directory entries remain small and easy to manage since they only store two integers per file.</p></li><li><p><b>Easy random access:</b> Directly accessing the n-th block requires no traversing; the system calculates the exact disk address instantly.</p></li></ul><p><b>Disadvantages</b></p><ul><li><p><b>External fragmentation:</b> Over time, creating and deleting files leaves scattered, small free spaces across the disk that may be too small to hold new files, wasting usable storage.</p></li><li><p><b>File growth limitations:</b> Expanding an existing file is difficult. If the block immediately following the file is already occupied, the entire file must either be moved to a larger free space or denied growth.</p></li><li><p><b>Pre-allocation overhead:</b> The system must know or estimate the final file size at creation time, which often leads to either overestimating (wasting space internally) or running out of room.</p></li></ul></h2><p></p>