UFS file system space allocation policy

Ivan Voras has an interesting post explaining UFS file system space allocation:

Users coming from other systems don’t usually know it (and probably don’t care, in today’s environment of multi-TB drives), but UFS has a rather interesting approach to space allocation which is different from the “usual suspects” like ext2/3, NTFS and FAT(32). Though it sometimes feels “interesting” in the sense of the Chinese proverb, it’s time-tested to work.
I’m talking about clustering, blocks and fragments.

As in more common file systems like ext2/3, NTFS and FAT/FAT32, there is a concept of a “block” or a “cluster” of sectors. Typically, 8 sectors of 512 bytes are clustered together to form a block of 4 kB in size – with time this has become the “traditional” cluster size and is used by default on ext2/3, NTFS and, if drive sizes permit, FAT/FAT32.

This form of clustering means the operating system must maintain less data about what blocks are allocated and where. Since average file size is certainly larger than the sector size (which is the absolute minimum size allocatable on the drive), it makes sense to use a bigger amount of space and consider it “atomic”.

This has two obvious consequences: first, a 1-byte file takes 1 block of space, eg 4 kB and there is nothing to be done about it. Second, all “normal” files usually have some padding at their end to fit on a 4 kB boundary. Even if the operating system records that a file is exactly 5000 bytes in size, it will internally consider this file to take 2 blocks (8 kB). The space between the logical end of the file (5000 bytes) and the accounted space (8 kB) is irrevocably wasted. All usable file systems have variable block sizes; some file systems like FAT and FAT32 have built-in limitations that dictate minimum block (cluster) sizes depending on the drive size – a FAT32 file system of 64 GB will have to use a minimum cluster size of 32 kB to avoid memory and performance problems, meaning up to 32 kB is wasted on small files and there is usually large padding space at the files’ ends.

More

More about UFS on Wikipedia

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>