[comp.unix.wizards] Disk Fragmentation

eichelbe@nadc.arpa (J. Eichelberger) (07/24/87)

Is there a disk defragmenter utility for 4.3 BSD UNIX on VAXes?
That is, a utility to move files around on the disk so that they are
less fragmented (more contiguous) and larger free space areas exist on
the disk.

At least four companies sell utilities for VAX/VMS to do what I just
mentioned.  And there is even such a utility for the CDC NOS.

Please don't suggest a dump and restore unless you'll come in on weekends
and do it for me.

Then again, maybe UNIX doesn't need such a utility.  But why would 4.3 BSD
fsck report on the fragmentation, then?

Thanks.
	Jon Eichelberger
	eichelbe@NADC.ARPA

chris@mimsy.UUCP (Chris Torek) (07/24/87)

In article <8441@brl-adm.ARPA> eichelbe@nadc.arpa (J. Eichelberger) writes:
>Is there a disk defragmenter utility for 4.3 BSD UNIX on VAXes?
>That is, a utility to move files around on the disk so that they are
>less fragmented (more contiguous) and larger free space areas exist on
>the disk.

Yes.  It is called `cp'.

(!)

All you need is enough empty space; blocks are allocated `optimally'
as long as there is an optimally placed block.  The block allocation
routines seem to work off state encoded in the in-core superblock
and cylinder group summaries, so I think this works best if you
are the only one doing file activity.  A dump-and-restore would
work, but you could also just use tar to copy a directory tree
while the machine is otherwise idle.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690)
Domain:	chris@mimsy.umd.edu	Path:	seismo!mimsy!chris

hedrick@topaz.rutgers.edu (Charles Hedrick) (07/25/87)

In article <8441@brl-adm.ARPA> eichelbe@nadc.arpa (J. Eichelberger) writes:
>Is there a disk defragmenter utility for 4.3 BSD UNIX on VAXes?
>That is, a utility to move files around on the disk so that they are
>less fragmented (more contiguous) and larger free space areas exist on
>the disk.

In article <7674@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) replies:
>Yes.  It is called `cp'.

Chris is right, of course, but it is probably worth one more comment
about why he is right.  He alludes to the fancy allocation strategies
used by the Berkeley fast file system.  That's certainly important,
because it lets your system make the best use of free space.  You
don't need literally contiguous space in order to get reasonable
performance.  But their most important trick is the 90% rule.  Note
that fragmentation is a problem mostly when disks are very nearly
full.  If you just have a few blocks free, they'll probably be
scattered all over the place.  But if you have lots of free space,
with reasonable algorithms you can avoid fragmentation, and thus never
need to reorganize.  So what Berkeley did is to make sure that you
never fill your disk.  When you get to 90% of the capacity, the system
pretends it is full.  By never letting you completely fill the disk,
the fast file system makes sure that there is enough free space that
it can normally find a fairly good location for the next block of a
file.  Most of us think it is worth wasting 10% of our disk to avoid
having to do defragmentation all the time.  Most Unix installations
depend upon this, and don't do disk space reorganizations.

dave@micropen (David F. Carlson) (07/27/87)

In article <7674@mimsy.UUCP>, chris@mimsy.UUCP (Chris Torek) writes:
> In article <8441@brl-adm.ARPA> eichelbe@nadc.arpa (J. Eichelberger) writes:
> >Is there a disk defragmenter utility for 4.3 BSD UNIX on VAXes?
> >That is, a utility to move files around on the disk so that they are
> >less fragmented (more contiguous) and larger free space areas exist on
> >the disk.
> 
> Yes.  It is called `cp'.
> In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690)
> Domain:	chris@mimsy.umd.edu	Path:	seismo!mimsy!chris

Although its clear the original question is about BSD, it should be noted that
SystemV has just such a utility:  dcopy(1M).  It's man page claims it will
deflate large empty directories and place file blocks with optimal rotational 
gap.  Also subdirectories are placed at the beginning of a directory in hopes
of speeding depth first directory searches.  Given that AT&T went to the 
trouble to do this, cp(1) sounds too easy (and no directory re-organization
is done to the best of my knowledge.)  

David F. Carlson, Micropen, Inc.
...!{seismo}!rochester!ur-valhalla!micropen!dave

"The faster I go, the behinder I get." --Lewis Carroll
-- 
David F. Carlson, Micropen, Inc.
...!{seismo}!rochester!ur-valhalla!micropen!dave

"The faster I go, the behinder I get." --Lewis Carroll

guy%gorodish@Sun.COM (Guy Harris) (07/28/87)

> SystemV has just such a utility:  dcopy(1M).  It's man page claims it will
> deflate large empty directories and place file blocks with optimal
> rotational gap.  Also subdirectories are placed at the beginning of a
> directory in hopes of speeding depth first directory searches.  Given that
> AT&T went to the trouble to do this, cp(1) sounds too easy (and no directory
> re-organization is done to the best of my knowledge.)  

The secret here is that, indeed, the original posting *was* about
4.3BSD.  The 4.[23]BSD file system uses a bitmap, not a free list, to
keep track of free blocks, and when a new block is needed it tries as
best it can to allocate one radially as close to a related block as
possible, preferably (at least in the case of blocks in a file)
rotationally positioned as optimally as possible as well.  It also
tries to keep directories close to the files in them; the 4.3BSD
version will also deflate large directories when possible.
	Guy Harris
	{ihnp4, decvax, seismo, decwrl, ...}!sun!guy
	guy@sun.com

rbj@icst-cmr.arpa (Root Boy Jim) (07/31/87)

   Is there a disk defragmenter utility for 4.3 BSD UNIX on VAXes?
   That is, a utility to move files around on the disk so that they are
   less fragmented (more contiguous) and larger free space areas exist on
   the disk.

   At least four companies sell utilities for VAX/VMS to do what I just
   mentioned.  And there is even such a utility for the CDC NOS.

VMS for one likes files (especially executables) to be contiguous. Also,
I don't know whether it has the equivalent of the buffer caching scheme
that UNIX does. If not, both points would suggest that VMS suffers more
degradation than UNIX does (note that I did not say anything about the
relative efficiency of either).

   Please don't suggest a dump and restore unless you'll come in on weekends
   and do it for me.

That's exactly what I will suggest, connected with a pipe, thus
obviating the need for magtape. Of course, you need a spare partition
(or disk pack), and you might have to do it twice, or use dd first. Still,
it will go much faster than using tape.

   Then again, maybe UNIX doesn't need such a utility.  But why would 4.3 BSD
   fsck report on the fragmentation, then?

Just to bug you :-)

   Thanks.
	   Jon Eichelberger
	   eichelbe@NADC.ARPA

	(Root Boy) Jim Cottrell	<rbj@icst-cmr.arpa>
	National Bureau of Standards
	Flamer's Hotline: (301) 975-5688