16

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.

  • 1
    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
  • 2
    @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
  • 2
    @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
24

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%.

See:

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.

| improve this answer | |
  • 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
  • 1
    @Tcll I totally agree you should use Ext or similarly behaving FSs for Linux itself and it doesn't make much sense why it wouldn't be so - that however does not in any way affect the real other disks & partitions you have to deal with which originate from e.g. Windows and other OSs or have heavy I/O at nearly full capacities. I won't go futher here, but I think we are on the same page :) – jave.web Apr 20 at 11:25
4

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!

| improve this answer | |
  • 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
  • @DanglingPointer what about those NTFSs though.... hmmm ? :) or a heavy I/O? hmmm ? :) people who simply don!t or can't afford "another disk" hmmm ? :) – jave.web Apr 17 at 11:47
2

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

| improve this answer | |
0

Currently there are no GUI utilities that offer ease of use

If you use NTFS, ExFAT, or other filesystems without any auto-defrag solution on Linux, you are stuck with cumbersome non-intuitive CLI tools.


The current solution is to use EXT4 or ZFS, which automatically does the brunt work for you to keep your HDDs fast.
Just avoid using more than 90% of your drive

if you use an SSD, fragmentation doesn't matter too much unless a file somehow gets so fragmented, the redirections start degrading performance.

EXT4 can discern an HDD from an SSD and won't kill your write cycles with auto-defragmentation.
just make sure you don't use swap on an SSD ;)

| improve this answer | |

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