Chapter 22. Limiting storage space usage on XFS with quotas
You can restrict the amount of disk space available to users or groups by implementing disk quotas. You can also define a warning level at which system administrators are informed before a user consumes too much disk space or a partition becomes full.
The XFS quota subsystem manages limits on disk space (blocks) and file (inode) usage. XFS quotas control or report on usage of these items on a user, group, or directory or project level. Group and project quotas are only mutually exclusive on older non-default XFS disk formats.
When managing on a per-directory or per-project basis, XFS manages the disk usage of directory hierarchies associated with a specific project.
22.1. Disk quotas
In most computing environments, disk space is not infinite. The quota subsystem provides a mechanism to control usage of disk space.
You can configure disk quotas for individual users as well as user groups on the local file systems. This makes it possible to manage the space allocated for user-specific files (such as email) separately from the space allocated to the projects that a user works on. The quota subsystem warns users when they exceed their allotted limit, but allows some extra space for current work (hard limit/soft limit).
If quotas are implemented, you need to check if the quotas are exceeded and make sure the quotas are accurate. If users repeatedly exceed their quotas or consistently reach their soft limits, a system administrator can either help the user determine how to use less disk space or increase the user’s disk quota.
You can set quotas to control:
- The number of consumed disk blocks.
- The number of inodes, which are data structures that contain information about files in UNIX file systems. Because inodes store file-related information, this allows control over the number of files that can be created.
22.2. The xfs_quota
tool
You can use the xfs_quota
tool to manage quotas on XFS file systems. In addition, you can use XFS file systems with limit enforcement turned off as an effective disk usage accounting system.
The XFS quota system differs from other file systems in a number of ways. Most importantly, XFS considers quota information as file system metadata and uses journaling to provide a higher level guarantee of consistency.
Additional resources
-
xfs_quota(8)
man page.
22.3. File system quota management in XFS
The XFS quota subsystem manages limits on disk space (blocks) and file (inode) usage. XFS quotas control or report on usage of these items on a user, group, or directory or project level. Group and project quotas are only mutually exclusive on older non-default XFS disk formats.
When managing on a per-directory or per-project basis, XFS manages the disk usage of directory hierarchies associated with a specific project.
22.4. Enabling disk quotas for XFS
This procedure enables disk quotas for users, groups, and projects on an XFS file system. Once quotas are enabled, the xfs_quota
tool can be used to set limits and report on disk usage.
Procedure
Enable quotas for users:
# mount -o uquota /dev/xvdb1 /xfs
Replace
uquota
withuqnoenforce
to allow usage reporting without enforcing any limits.Enable quotas for groups:
# mount -o gquota /dev/xvdb1 /xfs
Replace
gquota
withgqnoenforce
to allow usage reporting without enforcing any limits.Enable quotas for projects:
# mount -o pquota /dev/xvdb1 /xfs
Replace
pquota
withpqnoenforce
to allow usage reporting without enforcing any limits.Alternatively, include the quota mount options in the
/etc/fstab
file. The following example shows entries in the/etc/fstab
file to enable quotas for users, groups, and projects, respectively, on an XFS file system. These examples also mount the file system with read/write permissions:# vim /etc/fstab /dev/xvdb1 /xfs xfs rw,quota 0 0 /dev/xvdb1 /xfs xfs rw,gquota 0 0 /dev/xvdb1 /xfs xfs rw,prjquota 0 0
Additional resources
-
mount(8)
man page. -
xfs_quota(8)
man page.
22.5. Reporting XFS usage
You can use the xfs_quota
tool to set limits and report on disk usage. By default, xfs_quota
is run interactively, and in basic mode. Basic mode subcommands simply report usage, and are available to all users.
Prerequisites
- Quotas have been enabled for the XFS file system. See Enabling disk quotas for XFS.
Procedure
Start the
xfs_quota
shell:# xfs_quota
Show usage and limits for the given user:
# xfs_quota> quota username
Show free and used counts for blocks and inodes:
# xfs_quota> df
Run the help command to display the basic commands available with
xfs_quota
.# xfs_quota> help
Specify
q
to exitxfs_quota
.# xfs_quota> q
Additional resources
-
xfs_quota(8)
man page.
22.6. Modifying XFS quota limits
Start the xfs_quota
tool with the -x
option to enable expert mode and run the administrator commands, which allow modifications to the quota system. The subcommands of this mode allow actual configuration of limits, and are available only to users with elevated privileges.
Prerequisites
- Quotas have been enabled for the XFS file system. See Enabling disk quotas for XFS.
Procedure
Start the
xfs_quota
shell with the-x
option to enable expert mode:# xfs_quota -x
Report quota information for a specific file system:
# xfs_quota> report /path
For example, to display a sample quota report for
/home
(on/dev/blockdevice
), use the commandreport -h /home
. This displays output similar to the following:User quota on /home (/dev/blockdevice) Blocks User ID Used Soft Hard Warn/Grace ---------- --------------------------------- root 0 0 0 00 [------] testuser 103.4G 0 0 00 [------]
Modify quota limits:
# xfs_quota> limit isoft=500m ihard=700m user /path
For example, to set a soft and hard inode count limit of 500 and 700 respectively for user
john
, whose home directory is/home/john
, use the following command:# xfs_quota -x -c 'limit isoft=500 ihard=700 john' /home/
In this case, pass
mount_point
which is the mounted xfs file system.Run the help command to display the expert commands available with
xfs_quota -x
:# xfs_quota> help
Additional resources
-
xfs_quota(8)
man page.
22.7. Setting project limits for XFS
This procedure configures limits for project-controlled directories.
Procedure
Add the project-controlled directories to
/etc/projects
. For example, the following adds the/var/log
path with a unique ID of 11 to/etc/projects
. Your project ID can be any numerical value mapped to your project.# echo 11:/var/log >> /etc/projects
Add project names to
/etc/projid
to map project IDs to project names. For example, the following associates a project calledlogfiles
with the project ID of 11 as defined in the previous step.# echo logfiles:11 >> /etc/projid
Initialize the project directory. For example, the following initializes the project directory
/var
:# xfs_quota -x -c 'project -s logfiles' /var
Configure quotas for projects with initialized directories:
# xfs_quota -x -c 'limit -p bhard=1g logfiles' /var
Additional resources
-
xfs_quota(8)
man page. -
projid(5)
man page. -
projects(5)
man page.