Advice for hacking on ufs/ffs

Rick C. Petty rick-freebsd at kiwi-computer.com
Thu Jul 27 17:54:38 UTC 2006


On Thu, Jul 27, 2006 at 09:14:41AM +0200, Dag-Erling Sm?rgrav wrote:
> "Rick C. Petty" <rick-freebsd at kiwi-computer.com> writes:
> > On Tue, Jul 25, 2006 at 10:53:31AM -0700, Shane Adams wrote:
> > > I used dd to create 1G file.
> > A faster way is:
> >     touch filename
> >     truncate -s 1g filename
> 
> no, this will result in a fragmented image, which will hurt run-time
> performance.

Not necessarily.  If you install a variant of windoze, the installer will
format the disk first, writing zeros (and metadata) sequentially, and
thus the allocation will not be fragmented.  In the case of UFS newfs
only the metadata will be written for each cylinder group and thus the
logical blocks for all metadata will be contiguous.

I wouldn't say this type of fragmenting absolutely *will* hurt
performance but that it "may" hurt-- certainly tools like fsck would see
a performance improvement.  There are some performance advantages to 
reducing the seek time (in the underlying storage mechanism) for metadata
operations, especially with larger disk caches.  Without benchmarks, it's
hard to say in general whether performance would be degraded due to the
"random" allocation, if you also include FreeBSD's caching mechanisms.
And UFS block allocation is quite predictable.

But you are correct-- truncate(1) just changes the size of the file and
doesn't allocate the underlying blocks.  So there is a tendancy for it to
become fragmented as blocks get allocated out of order.

Also, I discovered that in my example, touch(1) isn't necessary...
truncate(1) works on non-existent files.

-- Rick C. Petty


More information about the freebsd-fs mailing list