Subject: Re: defrag?
To: Dave Huang <khym@bga.com.clock.org>
From: Erik E. Fair <fair@clock.org>
List: port-mac68k
Date: 07/17/1997 03:03:26
When people talk about "fragmentation" on a disk, they most often mean that
the blocks of a file are spread all over the disk, so it takes lots of
seeks to get to all of it. FFS deals with this problem on an ongoing basis
in its block allocation mechanism so that, in principle, you should never
have to "defrag" an FFS. This block allocation mechanism will become
suboptimal if less than 10% of the filesystem is free space, however...

Now you know why there really isn't a market for "defrag" utilities for
UNIX; it was taken care of in the OS itself in the early 80's. One wonders
where Microsoft and Apple were when this work was done.

The meaning of "fragmentation" in FFS has to do with the *sizes* of blocks
allocated. In the default FFS (these are tunable parameters), a block is 8K
bytes and a fragment is 1K. A 9K file will take one block, and one
fragment. Disk fragmentation is a function of how many fragments have been
allocated (as opposed to whole blocks). A high fragmentation percentage
simply means you have lots of odd-sized files relative to the filesystem
block size, often bazillions of small files (any MH users out there?).

To cut down on fragmentation, you can go to a 4K/512b, or you can (to
increase performance at the expense of disk space) go to a 16K/2K, or
32K/4K set up. Or you can cut back on the number of files that are not
multiples of the filesystem block size.

See newfs(8) and tunefs(8).

N.B.: some systems' boot PROMs will not deal with FFS of other than default
parameters (8K/1K; Suns are this way), so be careful of doing this with
your root partition.

	Erik <fair@clock.org>