Skip to content

Commit c360004

Browse files
Brian Fostercmaiolino
authored andcommitted
xfs: set max_agbno to allow sparse alloc of last full inode chunk
Sparse inode cluster allocation sets min/max agbno values to avoid allocating an inode cluster that might map to an invalid inode chunk. For example, we can't have an inode record mapped to agbno 0 or that extends past the end of a runt AG of misaligned size. The initial calculation of max_agbno is unnecessarily conservative, however. This has triggered a corner case allocation failure where a small runt AG (i.e. 2063 blocks) is mostly full save for an extent to the EOFS boundary: [2050,13]. max_agbno is set to 2048 in this case, which happens to be the offset of the last possible valid inode chunk in the AG. In practice, we should be able to allocate the 4-block cluster at agbno 2052 to map to the parent inode record at agbno 2048, but the max_agbno value precludes it. Note that this can result in filesystem shutdown via dirty trans cancel on stable kernels prior to commit 9eb7759 ("xfs: walk all AGs if TRYLOCK passed to xfs_alloc_vextent_iterate_ags") because the tail AG selection by the allocator sets t_highest_agno on the transaction. If the inode allocator spins around and finds an inode chunk with free inodes in an earlier AG, the subsequent dir name creation path may still fail to allocate due to the AG restriction and cancel. To avoid this problem, update the max_agbno calculation to the agbno prior to the last chunk aligned agbno in the AG. This is not necessarily the last valid allocation target for a sparse chunk, but since inode chunks (i.e. records) are chunk aligned and sparse allocs are cluster sized/aligned, this allows the sb_spino_align alignment restriction to take over and round down the max effective agbno to within the last valid inode chunk in the AG. Note that even though the allocator improvements in the aforementioned commit seem to avoid this particular dirty trans cancel situation, the max_agbno logic improvement still applies as we should be able to allocate from an AG that has been appropriately selected. The more important target for this patch however are older/stable kernels prior to this allocator rework/improvement. Cc: stable@vger.kernel.org # v4.2 Fixes: 56d1115 ("xfs: allocate sparse inode chunks on full chunk allocation failure") Signed-off-by: Brian Foster <bfoster@redhat.com> Reviewed-by: Darrick J. Wong <djwong@kernel.org> Signed-off-by: Carlos Maiolino <cem@kernel.org>
1 parent a65fd81 commit c360004

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

fs/xfs/libxfs/xfs_ialloc.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -848,15 +848,16 @@ xfs_ialloc_ag_alloc(
848848
* invalid inode records, such as records that start at agbno 0
849849
* or extend beyond the AG.
850850
*
851-
* Set min agbno to the first aligned, non-zero agbno and max to
852-
* the last aligned agbno that is at least one full chunk from
853-
* the end of the AG.
851+
* Set min agbno to the first chunk aligned, non-zero agbno and
852+
* max to one less than the last chunk aligned agbno from the
853+
* end of the AG. We subtract 1 from max so that the cluster
854+
* allocation alignment takes over and allows allocation within
855+
* the last full inode chunk in the AG.
854856
*/
855857
args.min_agbno = args.mp->m_sb.sb_inoalignmt;
856858
args.max_agbno = round_down(xfs_ag_block_count(args.mp,
857859
pag_agno(pag)),
858-
args.mp->m_sb.sb_inoalignmt) -
859-
igeo->ialloc_blks;
860+
args.mp->m_sb.sb_inoalignmt) - 1;
860861

861862
error = xfs_alloc_vextent_near_bno(&args,
862863
xfs_agbno_to_fsb(pag,

0 commit comments

Comments
 (0)