[ Enlarge Image ]  
 
 
<< Back 
Posted: 2006/01/09 by: fcruz. Linux - Unix Blogs.
Is there any need to "defragment" Linux partitions as there is in Windows/NT systems? Is this yet another reason why running a Linux server is better than NT, in that you don't really need to worry so much about fragmentation on Linux partitions?

 

Linux and Windows filesystem fragmentation and related issues.

Fragmentaion of Linux/extX and Windows NTFS-X Filesystems

Most filesystems out there (including linux ext2, NTFS-X, and the newer linux filesystems) can eventually run into some fragmentation issues sooner or later. And as most Sys-Admins know, heavy fragmentation translates to a decreased system disk I/O performance. And while fragmentation can have a direct impact on your server's performance, it is not nearly as common on modern filesystems as it was on older legacy filesystems.

Answering the first question, fragmentation is not as much of an issue as it was in older FSs (filesystems) such as DOS/Win9x FAT/VFAT, where files were written to the FS without regards to contiguous FS space. This is not the case with extX and NFTS-X--as files are laid down on the FS in a more contiguous space aware manner. It is not until the FS begins filling up (where abundant contiguous space begins to become more rare) that much file fragmentation begins to occur.

Built-in fragmentation limiting with Linux/ext2 is realized through three things:

  • Block Groups: block groups within the extX filesystem(s) naturally group file-data together in "clumps".
  • Contiguous-First Writes: The OS/FS is configured to try to (whenever possible) only write files to unused portions of the disk that are not fragmented. i.e. small files get written to small contiguous blocks, and large files to large groups.
  • Defrag Utils: Although rarely needed, there are last resort defrag tools such as "ext2fs defrag" that can be used with extX and likewise Windows now has its own defrag tools also.
  • The Block Groups usage and Contiguous-Write First aspects of the extX filesystem is usually enough to keep most all Linux systems fragmentation free (for the most part).

    If want to simply check your level of extX fragmentation, a simple way of doing so on a live filesystem is:

    # e2fsck -nv /dev/hda5|grep config         
    e2fsck 1.19, 13-Jul-2000 for EXT2 FS 0.5b, 95/08/09
    1614 non-contiguous inodes (1.2%) <------Fragmentation
    #

    Fragmentation should be less than 5% most of the time.

    If for some reason your fragmentation starts getting very high (over 10-20%), there are other options to running defrag. Contact your support team to discuss these options.

    To answer the second question, traditionally YES there is some slight fragmentation on both extX and NTFS-X--but usually only as you really start getting the to very end (mx capacity) of a given partition or drive. But due to the Contiguous-Write First nature of these newer OSs this is much less of a problem. On older NT and NT-4 systems, there was no native defrag utility, so this gave rise to concern about fragmentation on NTFS, but this is more of a Sys-Admin legend than a valid day to day concern (unlike what you see on DOS/Win9x systems). But just to address this concern, newer versions of NT based OSs (e.g. Win2k and XP) now come with built in defrag utilities. The XP defrag utility is built into the GUI, and Win2k's is a plugin option in the Computer Management interface.

    But with NTFS-X as with extX, you should not attempt to defrag a live production server. If it should fail, this type of failure can cause irreparable damage, which can incur very high support service charges as a result. If you think that you truly need to defrag your extX or NTFS-X filesystem, please talk to your support team about scheduling to have it done correctly and safely. A slightly fragmented filesystem is better than no filesystem at all.

    I made a defrag check on a server we use to host some content management system  and an  affiliate directory application , it took a little while to load , so if you get a delay of 2 -3 minutes on the command above , dont worry , it might be normal depending on the size of the filesystem.






    [ Back ]