defragfs Command

Purpose

Increases a file system's contiguous free space.

Syntax

defragfs [ -q | -r | -s] { 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 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.

Flags

Item Description
-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.

Output

On a JFS filesystem, 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.
FileSystem filesystem is n percent fragmented
Shows to what extent the file system is fragmented in percentage.
On a JFS2 filesystem 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.
FileSystem filesystem is n percent fragmented
Shows to what extent the file system is fragmented in percentage.

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 AIX® Version 7.1 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 /data1
  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.