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

  1. Enable quotas for users:

    # mount -o uquota /dev/xvdb1 /xfs

    Replace uquota with uqnoenforce to allow usage reporting without enforcing any limits.

  2. Enable quotas for groups:

    # mount -o gquota /dev/xvdb1 /xfs

    Replace gquota with gqnoenforce to allow usage reporting without enforcing any limits.

  3. Enable quotas for projects:

    # mount -o pquota /dev/xvdb1 /xfs

    Replace pquota with pqnoenforce to allow usage reporting without enforcing any limits.

  4. 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

Procedure

  1. Start the xfs_quota shell:

    # xfs_quota
  2. Show usage and limits for the given user:

    # xfs_quota> quota username
  3. Show free and used counts for blocks and inodes:

    # xfs_quota> df
  4. Run the help command to display the basic commands available with xfs_quota.

    # xfs_quota> help
  5. Specify q to exit xfs_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

Procedure

  1. Start the xfs_quota shell with the -x option to enable expert mode:

    # xfs_quota -x
  2. 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 command report -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 [------]
  3. 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.

  4. 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

  1. 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
  2. Add project names to /etc/projid to map project IDs to project names. For example, the following associates a project called logfiles with the project ID of 11 as defined in the previous step.

    # echo logfiles:11 >> /etc/projid
  3. Initialize the project directory. For example, the following initializes the project directory /var:

    # xfs_quota -x -c 'project -s logfiles' /var
  4. 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.