XFS supports metadata journaling, which facilitates quicker crash recovery. The XFS file system can also be defragmented and enlarged while mounted and active. In addition, Red Hat Enterprise Linux 7 supports backup and restore utilities specific to XFS.
- Allocation Features
XFS features the following allocation schemes:
Delayed allocation and other performance optimizations affect XFS the same way that they do ext4. Namely, a program’s writes to an XFS file system are not guaranteed to be on-disk unless the program issues an
Stripe-aware allocation policies
- XFS is designed for large file systems and large file handling.
- XFS has on-line defragmentation tools
- XFS dramatically reduces start-up time by avoiding
- XFS has fast file system creation.
- XFS formatted disk capacity is greater than Ext3/4 even after removing the reserved blocks from the Ext3/4 file system
- Other XFS Features
The XFS file system support:
- Extended attributes (
This allows the system to associate several additional name/value pairs per file. It is enabled by default.
- Quota journaling
This avoids the need for lengthy quota consistency checks after a crash.
- Project/directory quotas
This allows quota restrictions over a directory tree.
- Subsecond timestamps
This allows timestamps to go to the subsecond
- Extended attributes (
Common Commands for ext3/4 and XFS
Task ext3/4 XFS Create a file system
File system check
Resizing a file system
Save an image of a file system
Label or tune a file system
Backup a file system
Creating an XFS File System with Tuning options
mkfs.xfs /dev/devicecommand. In general, the default options are optimal for common use.
mkfs.xfson a block device containing an existing file system, use the
-foption to force an overwrite of that file system.
Specifies a stripe unit or RAID chunk size. The
valuemust be specified in bytes, with an optional
Specifies the number of data disks in a RAID device, or the number of stripe units in the stripe.
# mkfs.xfs -d su=64k,sw=4 /dev/device
For < 1TB XFS file system
mkfs.xfs -l lazy-count=1,version=2,size=128m -i attr=2 -d agcount=4 -L VolumeName <dev>
For > 1TB XFS filesystem
mkfs.xfs -l lazy-count=1,version=2,size=128m -i attr=2 -d agcount=16 -L VolumeName <dev>
mkfs.xfschooses an optimal geometry. This may also be true on some hardware RAIDs that export geometry information to the operating system.
Mounting XFS with Tuning options
Further performance optimizations can be gained but specifying some additional mount options for your XFS file systems. By default, XFS uses write barriers to ensure file system integrity even when power is lost to a device with write caches enabled. For devices without write caches, or with battery-backed write caches, disable the barriers by using the
To manually mount a XFS file system with, optimal mount options, use the following:
mount -t xfs -o noatime,osyncisosync,logbsize=256k,logbufs=8 <dev> <mtpt>
The ‘/etc/fstab’ entry
UUID=xxxxxxxxxxx...x <mtpt> xfs noatime,osyncisosync,logbsize=256k,logbufs=8 0 2
logsbsize and logbufs
options address the often sited limitation of XFS when handling lots of small files and large number of file deletions.
Every time a file is accessed (read or write) the default for most file systems is to append the metadata associated with that file with an updated access time. Thus, even read operations incur an overhead associated with a write to the file system. This can lead to a significant degradation in performance in some usage scenarios. Appending
noatime to the fstab line for any file system stops this action from happening.
The above assumes you don't require atime
. Not using atime provides a significant performance benefit.
Access time is not the same as the last-modified time. Disabling access time will still enable you to see when files were last modified by a write operation.
atime behavior is
Relatimeis on by default for XFS. It has almost no overhead compared to
noatimewhile still maintaining sane
Increasing the size of an XFS file system
xfs_growfs /mount/point -D size
-D sizeoption grows the file system to the specified
size(expressed in file system blocks). Without the
xfs_growfswill grow the file system to the maximum size supported by the device.
-D size, ensure that the underlying block device is of an appropriate size to hold the file system later
Repairing an XFS File System
xfs_repairutility is designed to repair even large file systems with many inodes efficiently. Unlike other Linux file systems,
xfs_repairdoes not run at boot time, even when an XFS file system was not cleanly unmounted. In the event of an unclean unmount,
xfs_repairsimply replays the log at mount time, ensuring a consistent file system.
xfs_repairutility cannot repair an XFS file system with a dirty log. To clear the log, mount and unmount the XFS file system. If the log is corrupt and cannot be replayed, use the
-Loption (“force log zeroing”) to clear the log, that is,
xfs_repair -L /dev/device. Be aware that this may result in further corruption or data loss
Suspending an XFS File System
xfs_freeze. Suspending write activity allows hardware-based device snapshots to be used to capture the file system in a consistent state.
xfs_freezeutility is provided by the
xfsprogspackage, which is only available on x86_64.
xfs_freeze -f /mount/point
xfs_freeze -u /mount/point
xfs_freezeto suspend the file system first. Rather, the LVM management tools will automatically suspend the XFS file system before taking the snapshot
Backup and Restore of XFS File System
xfsdumputility. Red Hat Enterprise Linux 7 supports backups to tape drives or regular file images, and also allows multiple dumps to be written to the same tape. The
xfsdumputility also allows a dump to span multiple tapes, although only one dump can be written to a regular file. In addition,
xfsdumpsupports incremental backups, and can exclude files from a backup using size, subtree, or inode flags to filter them.
xfsdumpuses dump levels to determine a base dump to which a specific dump is relative. The
-loption specifies a dump level (0-9). To perform a full backup, perform a level 0 dump on the file system (that is,
/path/to/filesystem), as in:
xfsdump -l 0 -f /dev/device /path/to/filesystem
-foption specifies a destination for a backup. For example, the
/dev/st0destination is normally used for tape drives. An
xfsdumpdestination can be a tape drive, regular file, or remote tape device.
xfsdump -l 1 -f /dev/st0 /path/to/filesystem
xfsrestoreutility restores file systems from dumps produced by
xfsrestoreutility has two modes: a default simple mode, and a cumulative mode. Specific dumps are identified by session ID or session label. As such, restoring a dump requires its corresponding session ID or label.
session-ID), restore it fully to
xfsrestore -f /dev/st0 -S session-ID /path/to/destination
-foption specifies the location of the dump, while the
-Loption specifies which specific dump to restore. The
-Soption is used to specify a session ID, while the
-Loption is used for session labels. The
-Ioption displays both session labels and IDs for each dump.
xfsrestoreallows file system restoration from a specific incremental backup, for example, level 1 to level 9. To restore a file system from an incremental backup, simply add the
xfsrestore -f /dev/st0 -S session-ID -r /path/to/destination
xfsrestoreutility also allows specific files from a dump to be extracted, added, or deleted. To use
xfsrestoreinteractively, use the
-ioption, as in:
xfsrestore -f /dev/st0 -i /destination/directory
xfsrestorefinishes reading the specified device. Available commands in this dialogue include
XFS userspace tools
Once the OS is installed, XFS userspace tools are installed by using yum.
yum install xfsdump xfsprogs
Other XFS File System Utilities
Used to defragment mounted XFS file systems. When invoked with no arguments,
xfs_fsrdefragments all regular files in all mounted XFS file systems. This utility also allows users to suspend a defragmentation at a specified time and resume from where it left off later.In addition,
xfs_fsralso allows the defragmentation of only one file, as in
xfs_fsr /path/to/file. Red Hat advises not to periodically defrag an entire file system because XFS avoids fragmentation by default. System wide defragmentation could cause the side effect of fragmentation in free space.
Prints the map of disk blocks used by files in an XFS filesystem. This map lists each extent used by a specified file, as well as regions in the file with no corresponding blocks (that is, holes).
Prints XFS file system information.
Changes the parameters of an XFS file system. The
xfs_adminutility can only modify parameters of unmounted devices or file systems.
Copies the contents of an entire XFS file system to one or more targets in parallel.
Copies XFS file system metadata to a file. Red Hat only supports using the
xfs_metadumputility to copy unmounted file systems or read-only mounted file systems; otherwise, generated dumps could be corrupted or inconsistent.
Restores an XFS metadump image (generated using
xfs_metadump) to a file system image.
Debugs an XFS file system.
sudo xfs_db –c frag –r /dev/sda3
The file system reorganizer for XFS is
xfs_fsr. Typically, I instruct
/dev/sda3with a timeout (-t) of 6hrs (60 * 60 * 6 = 21600) which is specified in seconds. But for the purposes of this example I used a timeout of 15 mins.
sudo xfs_fsr -t 300 /dev/sda3 -v
When the defrag is finished check how well the file system reorganized
sudo xfs_db -c frag -r /dev/sda3 actual 2155648, ideal 254512, fragmentation factor 88.19%
Defragmenting for 15 mins doesn’t help much,
xfs_fsr needs several hours or more.
A better solution is to schedule a cron job to run periodically.
It is also possible to de-fragment a single file. To determine if a file is in need of defragmenting run the following…
xfs_bmap -v /srv/A320/PGQAR.DAT | wc -l
This will output a number which showing the number of extents the file is using.
This number should be close to 1
sudo xfs_fsr -v /srv/A320/PGQAR.DAT
Performance Tuning XFS References