

Moving file F so it can be one contiguous file of the new, larger size.Moving files in the way of the expansion elsewhere, to allow F to remain contiguous.Adding a new block somewhere else and indicating that F has a second extent.If subsequently F needs to be expanded, since the space immediately following it is occupied, there are three options for the file system: If another new file called G, which needs only three blocks, is added, it could then occupy the space after F and before C. Now, a new file called F, which requires seven blocks of space, can be placed into the first seven blocks of the newly freed space formerly holding the file B, and the three blocks following it will remain available. The file system could defragment the disk immediately after a deletion, but doing so would incur a severe performance penalty at unpredictable times. The empty space is simply left there, marked as and available for later use, then used again as needed. If the file B is deleted, a second region of ten blocks of free space is created, and the disk becomes fragmented. Thus, additional files can be created and saved after the file E. (Here, the block size is unimportant.) The remainder of the disk space is one free block. Consider the following scenario: A new disk has had five files, named A, B, C, D and E, saved continuously and sequentially in that order. The following example is a simplification of an otherwise complicated subject. Simplified example of how free space fragmentation and file fragmentation occur This is especially true when the file system becomes full and large contiguous regions of free space are unavailable. Shorter regions of free space also mean that the file system is no longer able to allocate new files contiguously, and has to break them into fragments. As time goes on, and the same factors are continuously present, free space as well as frequently appended files tend to fragment more. When existing files are appended to, it is often impossible to resume the write exactly where the file used to end, as another file may already be allocated there thus, a new fragment has to be allocated. When the operating system and applications are installed or archives are unpacked, separate files end up occurring sequentially so related files are positioned close to each other.Īs existing files are deleted or truncated, new regions of free space are created.

For some time after creation, files can be laid out near-optimally. This means that the file system is able to place newly created files anywhere on the partition. When a file system is first initialized on a partition, it contains only a few small internal structures and is otherwise one contiguous block of empty space.
