Product SiteDocumentation Site

3.2. AG Free Space Management

The XFS filesystem tracks free space in an allocation group using two B+trees. One B+tree tracks space by block number, the second by the size of the free space block. This scheme allows XFS to quickly find free space near a given block or of a given size.
All block numbers, indexes and counts are AG relative.

3.2.1. AG Free Space Block

The second sector in an AG contains the information about the two free space B+trees and associated free space information for the AG. The "AG Free Space Block", also knows as the AGF, uses the following structure:
typedef struct xfs_agf {
     __be32              agf_magicnum;
     __be32              agf_versionnum;
     __be32              agf_seqno;
     __be32              agf_length;
     __be32              agf_roots[XFS_BTNUM_AGF];
     __be32              agf_spare0;
     __be32              agf_levels[XFS_BTNUM_AGF];
     __be32              agf_spare1;
     __be32              agf_flfirst;
     __be32              agf_fllast;
     __be32              agf_flcount;
     __be32              agf_freeblks;
     __be32              agf_longest;
     __be32              agf_btreeblks;
} xfs_agf_t;
The rest of the bytes in the sector are zeroed. XFS_BTNUM_AGF is set to 2, index 0 for the count B+tree and index 1 for the size B+tree.
Specifies the magic number for the AGF sector: "XAGF" (0x58414746).
Set to XFS_AGF_VERSION which is currently 1.
Specifies the AG number for the sector.
Specifies the size of the AG in filesystem blocks. For all AGs except the last, this must be equal to the superblock's sb_agblocks value. For the last AG, this could be less than the sb_agblocks value. It is this value that should be used to determine the size of the AG.
Specifies the block number for the root of the two free space B+trees.
Specifies the level or depth of the two free space B+trees. For a fresh AG, this will be one, and the "roots" will point to a single leaf of level 0.
Specifies the index of the first "free list" block. Free lists are covered in more detail later on.
Specifies the index of the last "free list" block.
Specifies the number of blocks in the "free list".
Specifies the current number of free blocks in the AG.
Specifies the number of blocks of longest contiguous free space in the AG.
Specifies the number of blocks used for the free space B+trees. This is only used if the XFS_SB_VERSION2_LAZYSBCOUNTBIT bit is set in sb_features2.