defragfs Command

Purpose

Increases a file system's contiguous free space.

Syntax

defragfs [ -q | -r | -s] [-f [-v] [-y] ] { Device | FileSystem }

Description

The defragfs command increases a file system's contiguous free space by reorganizing allocations to be contiguous rather than scattered across the disk. The file system to be defragmented can be specified with the Device variable, which is the path name of the logical volume (for example, /dev/hd4). It can also be specified with the FileSystem variable, which is the mount point in the /etc/filesystems file.

The defragfs command is intended for fragmented and compressed file systems. However, you can use the defragfs command to increase contiguous free space in nonfragmented file systems.

You must mount the file system read-write for this command to run successfully. Using the -q flag, the -r flag or the -s flag generates a fragmentation report. These flags do not alter the file system.

The defragfs command is slow against a Enhanced Journaled File System (JFS2) file system with a snapshot due to the amount of data that must be copied into snapshot storage object. The defragfs command issues a warning message if there are snapshots. The snapshot command can be used to delete the snapshots and then used again to create a new snapshot after the defragfs command completes.

On a JFS2 file system, you can specify the -f flag with the defragfs command to defragment the file system by relocating data extents to be adjacent, and then combining them. Additionally, if you specify the -v flag, the defragfs command also displays the fragmentation of the file system before and after running the defragfs command. The -f , -v, and -y flags can only be used on a JFS2 file system. The -v flag is compatible only with the -f flag.

The defragfs command takes more time to run if you use with the -f flag. It is recommended the defragfs command be run during a maintenance window.

Any file system activity might decrease the performance of the defragmentation process.

The defragfs command might not significantly improve performance of a file system in which the logical volume is located in part or completely on Solid-State Drives (SSDs).

The defragfs command cannot run if internal snapshots exist in the system. The defragfs command issues a warning message if external snapshots exist in the system unless the defragfs command is run with the -f flag. If the defragfs command is run with the -f flag, the defragfs command cannot be run with external snapshots. The defragfs command takes time to run on a JFS2 file system with a snapshot because of the amount of data that must be copied into the snapshot storage object. The snapshot command can be used to delete the snapshots and then the snapshot command can be used again to create a new snapshot after the defragfs command completes.

The defragfs command shows better performance if run on a file system that does not share a log volume with other file systems. If the defragfs command is run on a file system that shares a log volume with other file systems, the defragfs command displays a warning and asks for confirmation. If you run the defragfs command with the -y flag, it suppresses the warning. The -y flag is only compatible with the -f flag.

Flags

Item Description
-f Relocates and combines data extents for each file in the file system. This process prioritizes file organization over file system free space contiguity.
-q Reports the current state of the file system.
-r Reports the current state of the file system and the state that would result if the defragfs command is run without either the -q, -r or -s flag.
-s Reports the fragmentation in the file system. This option causes defragfs to pass through meta data in the file system which may result in degraded performance.
-v Displays the fragmentation percentage of file system at the start and at the end of the defragmentation operation.
-y Suppresses warning message that is displayed by the defragfs command when multiple file systems are currently mounted by using the same log volume. When the warning messages are suppressed, the defragfs command operation continues without any interruption.
Note: The -v and the -y flag can only be used with the -f flag.

Output

On a JFS file system, the definitions for the messages reported by the defragfs command are as follows:
Number of free fragments
The number of free fragments in the file system.
Number of allocated fragments
The number of allocated fragments in the file system.
Number of free spaces shorter than a block
The number of free spaces within the file system that are shorter than a block. A free space is a set of contiguous fragments that are not allocated.
Number of free fragments in short free spaces
The total number of fragments in all the short free spaces. A short free space is one that is shorter than a block.
Number of fragments moved
The total number of fragments moved.
Number of logical blocks moved
The total number of logical blocks moved.
Number of allocation attempts
The number of times free fragments were reallocated.
Number of exact matches
The number of times the fragments that are moved would fit exactly in some free space.
Total number of fragments
The total number of fragments in the file system.
Number of fragments that may be migrated
The number of fragments that may be moved during defragmentation.
File system is in percent fragmented
Shows to what extent the file system is fragmented in percentage.
On a JFS2 file system the definitions for the messages reported by the defragfs command are as follows:
Total allocation groups
The number of allocation groups in the file system. Allocation groups divide the space on a file system into chunks. Allocation groups allow JFS2 resource allocation policies to use well known methods for achieving good I/O performance.
Allocation groups defragmented
The number of allocation groups that were defragmented.
Allocation groups skipped - entirely free
The number of allocation groups that were skipped because they were entirely free.
Allocation groups skipped - too few free blocks
The number of allocation groups that were skipped because there were too few free blocks in them for reallocation.
Allocation groups skipped - contains a large contiguous free space
The number of allocation groups that were skipped because they contained a large contiguous free space which is not worth defragmenting.
Allocation groups are candidates for defragmenting
The number of allocation groups that are fit for defragmenting.
Average number of free runs in candidate allocation groups
The average number of free runs per allocation group, for allocation groups that are found fit for defragmentation. A free run is a contiguous set of blocks which are not allocated.
Total number of blocks
The total number of blocks in the file system.
Number of blocks that may be migrated
The number of blocks that may be moved during defragmentation.
File system is in percent fragmented
Shows to what extent the file system is fragmented in percentage.
Percentage of fragmentation in the file system: percentage
The percentage of fragmentation in the file system before and after running the defragfs command. The following example shows the percentage of fragmentation in the file system:
# defragfs -fv /exampleFS
File fragmentation before defrag: 100.00%
File fragmentation after defrag: 0.00%

Security

Attention RBAC users and Trusted AIX users: This command can perform privileged operations. Only privileged users can run privileged operations. For more information about authorizations and privileges, see Privileged Command Database in Security. For a list of privileges and the authorizations associated with this command, see the lssecattr command or the getcmdattr subcommand.

Examples

  1. To defragment the /data1 file system located on the /dev/lv00 logical volume, enter:
    defragfs /dev/lv00
  2. To defragment the /data1 file system by specifying its mount point, enter:
    defragfs /data1
  3. To generate a report on the /data1 file system that indicates its current status as well as its status after being defragmented, enter:
    defragfs  -r /data1
  4. To generate a report on the fragmentation in the /data1 file system, enter:
    defragfs -s /data1

Files

Item Description
/etc/filesystems Lists the known file systems and defines their characteristics.