Hacker News new | ask | show | jobs
by wenc 1648 days ago
I can't conduct the experiment anymore obviously, but to qualify my perceptions -- if you try to do a linear read from a 90% fragmented filesystem, performance would definitely suck and defragging would obviously provide perceptible benefit.

Most of the time however, my disk was probably only about 30% fragmented (if I recall correctly from Speed Disk). I was running DOS on a FAT file system where there was no swap file or anything that would cause massive fragmentation except deleting and installing programs, and maybe some temp files created by certain programs. The performance delta for me was barely noticeable on a 40MB Seagate IDE drive.

2 comments

> I can't conduct the experiment anymore obviously

Why not?

  $ virt-make-fs --type=msdos /usr/share/doc /var/tmp/disk.img
  $ export file=/var/tmp/disk.img
  $ nbdkit eval \
       after_fork=' echo 0 > $tmpdir/read ' \
       get_size=' stat -Lc %s $file ' \
       pread='
           diff=$(($4 - `cat $tmpdir/read`))
           echo $4 > $tmpdir/read
           if [ $diff -lt -10000 ] || [ $diff -gt 10000 ]; then
               # simulate a seek
               sleep 0.1
           fi
           dd if=$file skip=$4 count=$3 iflag=count_bytes,skip_bytes
       '
  $ sudo nbd-client localhost /dev/nbd0
  $ sudo mount /dev/nbd0 /tmp/mnt
The tricky thing is probably making a deliberately fragmented disk image for testing using modern tools.
In Vista defragging was one of my goto's for getting the thing to act nicely.

I would use process monitor from sysinternals to measure which files are loaded as the system boots. Then use jkdefrag/mydefrag to take said list and rebuild drive into different zones. Try to put small files that are used together in the same area of the disk. Put huge things like 'isos/vhds/acrivezips' etc near the end of the drive. Put small frequently used files near the front in used order if possible. Smash out any gaps if possible. This helps NTFS from creating more fragments. Defrag any files that 7zip unarchives immediately as it has a bad habit of creating highly fragmented files (contig from sysinternals). Try to put file index in its own 'area' as one reason it runs so badly is the drive fragmentation it causes to itself. It got so bad I would put the index on its own partition sometimes. Try to put files that fragment frequently in their own 'zone' as NTFS will tend to pick the next available gap to where the file is (not always).

That made a real noticeable difference in perceived speed.

These days with nvme and ssd I might just defrag the files themselves once a year if I feel like it. There is a difference but the perceived is pretty much not there anymore. The difference is there is a chain of sectors in the MFT that windows will have to traverse if you ask for something in the middle of a file. That is about the only thing you save with newer drives. ext4 has a similar issue. But it seems to be better about picking spots where it will not fragment. It will however fragment badly in low space conditions. Most filesystems will.