From 887a7edd7d70577043dae314f5336befca995d3f Mon Sep 17 00:00:00 2001 From: Dave Chinner Date: Tue, 9 May 2023 11:29:48 +0200 Subject: [PATCH] xfs: convert xfs_ialloc_next_ag() to an atomic Source kernel commit: 20a5eab49d354a2837e0af3f07f92a104de52804 This is currently a spinlock lock protected rotor which can be implemented with a single atomic operation. Change it to be more efficient and get rid of the m_agirotor_lock. Noticed while converting the inode allocation AG selection loop to active perag references. Signed-off-by: Dave Chinner Reviewed-by: Allison Henderson Reviewed-by: Darrick J. Wong Signed-off-by: Carlos Maiolino --- libxfs/xfs_ialloc.c | 17 +---------------- libxfs/xfs_sb.c | 3 ++- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/libxfs/xfs_ialloc.c b/libxfs/xfs_ialloc.c index c04cc7cc7..d17825560 100644 --- a/libxfs/xfs_ialloc.c +++ b/libxfs/xfs_ialloc.c @@ -1571,21 +1571,6 @@ xfs_dialloc_roll( return error; } -static xfs_agnumber_t -xfs_ialloc_next_ag( - xfs_mount_t *mp) -{ - xfs_agnumber_t agno; - - spin_lock(&mp->m_agirotor_lock); - agno = mp->m_agirotor; - if (++mp->m_agirotor >= mp->m_maxagi) - mp->m_agirotor = 0; - spin_unlock(&mp->m_agirotor_lock); - - return agno; -} - static bool xfs_dialloc_good_ag( struct xfs_perag *pag, @@ -1743,7 +1728,7 @@ xfs_dialloc( * an AG has enough space for file creation. */ if (S_ISDIR(mode)) - start_agno = xfs_ialloc_next_ag(mp); + start_agno = atomic_inc_return(&mp->m_agirotor) % mp->m_maxagi; else { start_agno = XFS_INO_TO_AGNO(mp, parent); if (start_agno >= mp->m_maxagi) diff --git a/libxfs/xfs_sb.c b/libxfs/xfs_sb.c index d05f0e6e4..64b4e7bea 100644 --- a/libxfs/xfs_sb.c +++ b/libxfs/xfs_sb.c @@ -907,7 +907,8 @@ xfs_sb_mount_common( struct xfs_mount *mp, struct xfs_sb *sbp) { - mp->m_agfrotor = mp->m_agirotor = 0; + mp->m_agfrotor = 0; + atomic_set(&mp->m_agirotor, 0); mp->m_maxagi = mp->m_sb.sb_agcount; mp->m_blkbit_log = sbp->sb_blocklog + XFS_NBBYLOG; mp->m_blkbb_log = sbp->sb_blocklog - BBSHIFT; -- 2.47.2