e2freefrag
Report file system free space fragmentation
TLDR
Check how many free blocks are present as contiguous and aligned free space
Specify [c]hunk size in kilobytes to print how many free chunks are available
SYNOPSIS
e2freefrag [ options ] device
PARAMETERS
-c cluster_size
Report fragmentation based on units of cluster_size instead of the filesystem's block size. The cluster_size must be a power of 2.
-h
Print numbers in human-readable units (e.g., 1K, 23M, 2G).
-t
Show overall tree information. This provides a more detailed breakdown of the free space B-tree structure, often including internal node usage.
-V
Print the version number of e2freefrag and exit.
DESCRIPTION
The e2freefrag command is a utility from the e2fsprogs suite designed to analyze the fragmentation of free space on ext2, ext3, and ext4 filesystems. It provides valuable insights into how free blocks are distributed across the disk.
While Linux filesystems, especially ext4, are generally good at minimizing file fragmentation during writes, free space itself can become fragmented over time, leading to a large number of small, discontiguous free extents. This can potentially impact performance when allocating new large files, as the system may struggle to find contiguous blocks.
e2freefrag reports metrics such as the average free extent size, the number of free extents, and a fragmentation index. It's crucial to understand that e2freefrag is an analysis tool, not a defragmentation tool. It does not modify the filesystem; it merely reports its state.
CAVEATS
e2freefrag only analyzes free space fragmentation; it does not perform defragmentation. For the most accurate results, especially on active filesystems, it's best run on an unmounted filesystem or a mounted read-only filesystem. Running on a mounted read-write filesystem might yield slightly less accurate results due to ongoing changes, but it is generally safe as it performs only read operations and does not modify the filesystem.
INTERPRETING OUTPUT
The output of e2freefrag typically includes several key metrics:
Average free extent size: This is the average size of contiguous blocks of free space on the filesystem. A smaller average might indicate higher fragmentation, meaning free space is scattered in many small chunks.
Number of free extents: This represents the total count of separate contiguous blocks of free space. A higher number for a given amount of total free space generally suggests more severe fragmentation, as the free space is broken into more pieces.
Fragmentation index: This is a calculated metric indicating the overall degree of fragmentation. While the exact formula can vary, lower values are generally better, indicating less fragmentation. A higher index suggests more severe free space fragmentation.
High free space fragmentation can suggest that new, large files might be written in a scattered manner, potentially affecting read/write performance over time. If severe fragmentation is observed, and performance is a concern, a common approach to remedy it (since there's no native free-space defragmenter for ext filesystems) is to back up all data, reformat the filesystem, and then restore the data. This process effectively 'defragments' the free space by writing data contiguously onto a freshly empty filesystem.
HISTORY
e2freefrag is part of the robust e2fsprogs package, a comprehensive collection of utilities for the ext2, ext3, and ext4 filesystems in Linux. Developed and maintained primarily by Theodore Ts'o, e2fsprogs has been a fundamental component of Linux filesystem management for decades. e2freefrag was introduced to address the specific need for a diagnostic tool to assess free space fragmentation, complementing other tools that manage or check the filesystem's integrity and performance.