Minimizing Space Consumption

Most filesystems allocate space to files in blocks, which are typically power-of-two multiples of 512 bytes in size (that is, 21 x 512, 22 x 512, 23 x 512, and so on). Common block sizes for Linux filesystems range from 1 KB to 4KB (the range for ext2fs and ext3fs). XFS supports block sizes ranging from 512 bytes to 64KB, although in practice block size is limited by CPU architecture (4KB for IA-32 and PowerPC; 8KB for Alpha and Sparc). ReiserFS and Linux's JFS currently support only 4KB blocks, although JFS's data structures support blocks as small as 512 bytes. The default block size is 4KB for all of these filesystems except ext2fs and ext3fs, for which the default is based on the filesystem size.

You can minimize the space used by files, and hence maximize the number of files you can fit on a filesystem, by using smaller block sizes. This practice may slightly degrade performance, though, as files may become more fragmented and require more pointers to completely describe the file's location on the disk.

ReiserFS is unusual in that it supports storing file tails—the ends of files that don't occupy all of an allocation block—from multiple files together in one block. This feature can greatly enhance ReiserFS's capacity to store many small files, such as those found on a news server's spool directory. XFS uses a different approach to achieve a similar benefit—it stores small files entirely within the inode (a disk structure that points to the file on disk, holds the file's time stamp, and so on) whenever possible.

None of these features has much impact when average file sizes are large. For instance, saving 2KB by storing file tails in a single allocation block won't be important if a filesystem has just two 1GB files. If the filesystem has 2,000,000 1 KB files, though, such space-saving features can make a difference between fitting all the files on a disk or having to buy a new disk.

Another aspect of disk space consumption is the space devoted to the journal. On most disks, this isn't a major consideration; however, it is a concern on small disks, such as Zip disks. On a 100MB Zip disk, ReiserFS devotes 32MB to its journal and ext3fs and XFS both devote 4MB. JFS devotes less space to its journal initially, but it may grow with use.

Ext2fs and ext3fs suffer from another problem: By default, they reserve five percent of their disk space for emergency use by root. The idea is to give root space to work in case a filesystem fills up. This may be a reasonable plan for critical filesystems such as the root filesystem and /var, but for some it's pointless; for instance, root doesn't need space on /home or on removable media. The upcoming section, "Creating a Filesystem for Optimal Performance," describes how to reduce the reserved space percentage.

0 0

Post a comment