You are not logged in.

#1 2010-03-14 01:01:56

thetrivialstuff
Member
Registered: 2006-05-10
Posts: 191

checking fragmentation on reiserfs

My root partition has been the same one through many, many big pacman -Syu's now, and I was beginning to wonder if it was getting fragmented (I wouldn't blame it). So I wrote this little perl script:

#!/usr/bin/perl

#quick & dirty script to see how fragmented a filesystem is,
#including a list of the worst-fragged files ('cause even if
#a filesystem is only 1% fragged, if a program you use every
#day is in that 1% it might be worth fixing...).

$dir = shift @ARGV;

$dir =~ s/'/\\'/g;

$filefrag = `find \$'$dir' -xdev -type f -print0 | xargs -0 filefrag`;

@files = split /\n/ , $filefrag;


$extents = 0;
$files = 0;
$fragmented = 0;
$reallyfragmented = 0;
$badlist = "";
foreach (@files) {
    $files++;
    
    $_ =~ m/: (\d+) extents{0,1} found$/;
    $extents += $1;
    
    if ($1 > 1) {
        $fragmented++;
    }   
    if ($1 > 4) {
        $reallyfragmented++;
    }   
    if ($1 > 20) {
        $badlist .= "$_\n";
    }   
}   

print "$extents extents in $files files,".
    " $fragmented files are fragmented (".
        (((0.0+$fragmented)/$files) * 100).
    "%), but only $reallyfragmented (".
        (((0.0+$reallyfragmented)/$files) * 100).
    "%) are in more than 4 pieces.
    
Worst files:

$badlist\n";

...on the off chance that that's useful to anyone. Yeah, there's a similar one on the Gentoo forums, but it seemed more complicated to me.

Using this I confirmed that my web browser, e-mail client, and most of openoffice are indeed in tens/hundreds of fragments... so I'm gonna go fix that.

This should work on any filesystem, but reiser is of particular interest because its fsck doesn't show fragmentation.

~Felix.

Offline

#2 2010-03-15 01:06:43

orphius1970
Member
From: Modesto (HELL) California
Registered: 2009-02-27
Posts: 151

Re: checking fragmentation on reiserfs

my only question is. If it shows how fragmented a reiser partition is, what do you do after that, I mean fsck doesn't
defrag the partition does it?


AMD Phenomx3, 4gb ram, Nvidia Gforce 9400gt,
MSI K9N2 Diamond Motherboard, Arch x86_64

Offline

#3 2010-03-15 01:25:36

thetrivialstuff
Member
Registered: 2006-05-10
Posts: 191

Re: checking fragmentation on reiserfs

orphius1970 wrote:

my only question is. If it shows how fragmented a reiser partition is, what do you do after that, I mean fsck doesn't
defrag the partition does it?

No, it doesn't. The most straightforward way is to just move everything off of the partition and then move it back. To do that with the root partition you have to boot to something else, obviously :)

~Felix.

Offline

Board footer

Powered by FluxBB