Subject: Re: Defragmenting a NetBSD drive
To: Brian Buhrow , Simon Burge <simonb@netbsd.org>
From: Brian C. Grayson <bgrayson@marvin.ece.utexas.edu>
List: netbsd-ports
Date: 09/15/1999 18:28:03
On Wed, Sep 15, 1999 at 09:48:15AM +0000, Brian Buhrow wrote:
> 	The kernel already collects unused blocks of directories.  Given a
> directory that takes up 2 512 byte blocks, if you remove enough directory
> entries to cause the required space to drop to 1 512 byte block, as soon as
> you create another directory entry, the compaction occurs.

  Only if you have removed all entries that are in the second
block.  If you use my example from before, ____...____h is in the
second block, and is the only valid entry left (besides . and ..,
of course).  If you touch foo, the directory still takes 1024
bytes -- compaction doesn't happen (yet).

  If you remove __...__h, it still takes 1024 bytes.  Once
you touch a _new_ file, _and_ if the trailing block(s) contains no
valid entries, then the directory is compacted.  (Verified on a
1.4K machine, but not from looking at the source).  In my
experience, like in my home directory, my file usage is not in
such a FIFO order -- I may create ten files today, one of which
will stay around for years, thus preventing compaction beyond its
current location in the directory entry list.

  I didn't know it _ever_ did compaction -- cool that it does!

  Brian