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.
EDIT (2021): it would seem a similar, less popular, question has been asked 3 years before this question with suggested tools: https://unix.stackexchange.com/questions/30743/is-there-a-tool-to-visualize-a-filesystem-allocation-map-on-linux
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.
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.
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!
There is no need for defragmentation on Linux systems.
So that is why there are not many defrag tools available.
People seem to forget that a good modern defragger is not just defrager, but optimiser as well. Different areas of the hard disk platter read at different speeds. The closer to the centre of the disk, the slower the file read is. A modern defragger will analyse file usage and place frequently read files towards the outer edge of the platter and less frequently used files are moved towards the centre. Some even allow files that are flagged as archives to be pull as close to the centre as possible. I have seen large files on my Linux system broken into 1000's of segments.
I run defrags on my server every month. My temp storage drive where I download my torrents is really bad.
$ xfs_db -r /dev/md6 -c frag
People that claim linux file systems don't need defragging are just regurgitating what someone else said and have never actually checked.
Fragview does what I needed and more.
As you can see if I click on an area of the map it shows which files are in that area, and how fragmented they are.
I can now use
btrfs filesystem defrag
should I wish to do so.Running on Ubuntu 18.04 amd64 with a BTRFS filesystem.
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 ;)