I'm looking for a tool that can give me a visual representation of my ext4 fragmentation. Something similar to how Defraggler, Puran Defrag, and many others (UltraDefrag being the best) display your disk... (most good UIs display the files in the block you're hovering your mouse over)

Is there anything related for Linux?

I want to watch my disk and see just how "unneeded" defragmentation really is.

I don't want to use e4defrag, because I'm not sure it can show me what exactly it's doing to my disk.

  • There is absolutely no need to defrag a linux machine. – ZaxLofful Sep 16 '15 at 21:12
  • 7
    That is nonsense. The "need" of defragmentation depends on the FS type and usage pattern. In some cases defragmentation makes a huge difference. (I guess this is one of the linux myths) – David Balažic Sep 16 '15 at 22:05
  • 1
    @DavidBalažic - reference please ? I see no need to defragment a a disk / file system with 0.2 % fragmentation. Please provide benchmarks to show defragmenting a ext2/3/4 / XFS / or any linux native file system significantly affects performance. – Panther Sep 17 '15 at 15:19
  • 2
    @bodhi.zazen --> "depends on the FS type and usage pattern". In some cases it has a big effect, in others none. If that 0.2% is a 2GB database file that is in heavy use, then it will have a big effect. It is a few small rarely used files, then of course not. – David Balažic Sep 17 '15 at 16:03
  • 1
    @DavidBalažic- Define "big effect" and post benchmarks. The i/o of the disk is going to hundreds of times more limiting then a small amount of fragmentation, it will take you a long time to write a 2 GB database to the disk and writing a part of a 2 Gb file is not going to be affected by 0.2% fragmentation, still have to re-write the data to disk. Any modern databse that is in heavy use will be in RAM and if you are writing to disk the limiting factor is RAM, not fragmentation. – Panther Sep 17 '15 at 16:31

The question is not if there is fragmentation. All file systems have some fragmentation.

The question is if the fragmentation is enough to affect performance.

On Linux file systems, fragmentation is typically less then 5%, often 1 or 2% unless the disk is 99% full. In the event of a full disk, you can see significant fragmentation, but in that case the problem is a full disk.

$ sudo fsck.ext2 -fn /dev/sda1
e2fsck 1.42 (29-Nov-2011)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
Ubuntu_Rescue: 291595/1222992 files (**0.2% non-contiguous**), 1927790/4882432 blocks

So yes, there is 0.2 % fragmentation, but this is well below the 85% threshold to affect performance.

See the blog post Why doesn't Linux need defragmenting?.

On Windows, it is not uncommon to see 50% or higher rates of fragmentation (I have seen 200% plus). Thus windows needs defragmentation tools.

On Windows they advise defragmentation at thresholds of about 85%.


So, bottom line, defragmentation is not a large enough problem on Linux to affect performance, so there are no significant defragmentation tools and you are sort of wasting your time worrying about it.

  • well I've got time to waste to clear up another issue regarding this, so thanks, also, it's always good to be a skeptic ;) – Tcll Sep 16 '15 at 15:55
  • I'm intrigued: what is meant by fragmentation of > 100%? Files are fragmented multiple times? – Doddy Sep 17 '15 at 11:46
  • @doddy apparently so, or the fragments are fragmented. I am not familiar enough with either windows or NTFS to know how the fragmentation is measured . – Panther Sep 17 '15 at 15:15
  • FWIW - Just today (been running this system with upgrades from Fedora 18 -> several updates -> now Fedora 22 ) fsck.ext2 -fn /dev/mapper/fedora-root /dev/mapper/fedora-root: 525176/3276800 files (0.6% non-contiguous) and /dev/mapper/fedora-home: 149180/11149312 files (1.1% non-contiguous) so not much fragmentation over years and several upgrades – Panther Oct 9 '15 at 21:24
  • I also want to add to the discussion that of course no system lasts forever and no matter if HDD or SSD, every write access is a consumption with possible loss. A defragmentation process is maybe the most challenging process for a HDD with all parts moving maximal (reading and writing at different sectors). So if the performance is not heavily affected, please do NOT try to defrag forcely. – zulu34sx Oct 21 '15 at 23:59

Let's keep it simple...

1) If you use EXT4, there is no need to defrag unless your disk is ~90% full and under heavy IO (Delete, Read, Write).

2) If you find yourself with a ~90% full disk that is heavily fragmented, then your problem is (IMHO) insufficient disk space and not fragmentation. Get a larger disk!

3) If you can't get a larger disk for any valid reason, then simply copy the whole lot (or by large chunks) to another disk, then copy it back. The advanced EXT4 FS writes it back contiguously eliminating fragmentation. This can be scheduled as a cron.daily job using Gnome Scheduler for the converts coming from Windows.

BEST FIX if you have the problem from point 2 above, get a larger disk!

  • I would still like to watch the fragmentation and take care of things when it does happen (not through the terminal like most spud-head developers prefer) ;) – Tcll Sep 17 '15 at 13:48
  • hence why I said use Gnome Scheduler for the "copy away and back pattern" – DanglingPointer Sep 17 '15 at 23:08

There is no need for defragmentation on Linux systems.
So that is why there are not many defrag tools available.

  • 3
    I'm not convinced, show me the fragmentation of a full ext4 HDD after 2 weeks of use with constant deletion and addition of files, there's bound to be fragmentation. – Tcll Sep 16 '15 at 15:21
  • 1
    There are many explanations online - one of them explains it quite precise : howtogeek.com/115229/… – cl-netbox Sep 16 '15 at 15:31
  • 1
    I posted the documentation you requested , 0.2 % fragmentation is trivial and not enough to affect performance. – Panther Sep 16 '15 at 15:49
  • 1
    To me, the obvious next question is then: why is manual defragmentation still required on Windows after all these years? But that's clearly off-topic for this site. ;-) – Oliphaunt Sep 16 '15 at 20:06
  • 2
    Two sentences, both wrong. One defrag tool is mentioned right in the question. Another is defragfs. Some related articles: Defragmenting-Linux (linux-magazine.com), How to defrag your Linux system(howtoforge). Also see this question: unix.stackexchange.com/questions/75652/… – David Balažic Sep 16 '15 at 22:16

protected by Community Jun 9 '16 at 15:22

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.