Saturday, 31 May 2008

Defragmenters for Linux

There were a lot of words were told about defragmentation of Linux filesystems. Summing them up, one can say: if fsck tells that fragmentation is below 10% then defrag is not necessary. But a few defragmentators for Linux were written. So let's discuss them.


Search results
A brief look at defragmentation tools for Linux is enough to find two utilites, a defrag and a shake. The defrag utility by Cone Colivas seems to be outdated. But there is a shake that can defragment a selected directory in a file system. There is also a useful
script frag.perl located here that can measure fragmentation level of directories:

sudo ./frag.pl /root
3.2258064516129% non contiguous files, 1.04838709677419 average fragments.
Using these tools, shake and frag.perl, we are going to fight with filesystem's fragmentation in Linux.

Setting it up
The setup of shake is slightly complicated process. The sources are located here, and if you are using Ubuntu you can take the binary file here. And here I had experienced some difficulties...

Firstly, latest versions of shake depends from fresh version of cdbs; that is why it is better to use older version. For the shake to be built, following packages are reqiured:
dpkg-checkbuilddeps: Unmet build dependencies: cdbs (>= 0.4.50) cmake (>= 2.4) help2man (>= 1.26) libattr1-dev (>= 2.0.0)
The program had compiled as well as her auxiliary tool unattr. For using shake more efficiently you might to mount a filesystem with user_xattr. To do such you need to edit /etc/fstab such like:
/dev/sda2 /mnt/flash/exthdd ext3 rw,user_xattr,user,auto 0 0
Then rmount: mount -o remount /dev/sda2
This trick allows the shake to works faster. And the last but not least, both shake и frag.perl are required root privileges so use sudo.


An example
I had tested shake on Hardy Heron repository that I downloaded. Checking fragmentation level gives:
./frag.perl /home/beast/flash/exthdd/linux/i386/ubuntu/pool/main 0.795800880460549% non contiguous files, 1.00998984083982 average fragments.
That is not a Windows situationan apocalypse. Then I had started shake:
./shake /home/beast/flash/exthdd/linux/i386/ubuntu/pool/main
The defragmentation took about 15-20 and all MD5SUMs are correct. So we can use shake for more extended experiments.


The extended experiment
For such experiment I had used to defragment Firefox's profile on my laptop: Firefox 2.0.0.4, ReiserFS, Asus M5200AE (P-M 1.75, 512Mb RAM).

There are a lot of files, and even worse: in Firefox profile there is a huge collection of webpages captured by Scrapbook. Estimated fragmentation is:
./frag.perl /home/beast/.mozilla/
3.24491439557299% non contiguous files, 1.12239224753839 average fragments.
I should say that my Firefox is covered with extensions like a Christmas tree, so it starts very sloooooooowly:
time /opt/firefox2/firefox
real 0m40.467s
user 0m5.389s
sys 0m0.407s

time /opt/firefox2/firefox
real 0m41.383s
user 0m5.453s
sys 0m0.403s
Firefox had been started two times with laptop clod-start each time.

Then defragmentation had been performed by shake. It took about 9 minutes. After that I started Firefox again:
time /opt/firefox2/firefox
real 0m39.522s
user 0m5.398s
sys 0m0.374s

time /opt/firefox2/firefox
real 0m39.214s
user 0m5.279s
sys 0m0.370s
There are no miracles, and 39 seconds are not fantastical results.

Conclusion
Sure, I can defrag something else but it is unlikely that results will be different. The analogous results are
here and there.
Read more...