]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: convert xfs_ialloc_next_ag() to an atomic
authorDave Chinner <dchinner@redhat.com>
Tue, 9 May 2023 09:29:48 +0000 (11:29 +0200)
committerCarlos Maiolino <cem@kernel.org>
Wed, 10 May 2023 08:13:12 +0000 (10:13 +0200)
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 <dchinner@redhat.com>
Reviewed-by: Allison Henderson <allison.henderson@oracle.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
libxfs/xfs_ialloc.c
libxfs/xfs_sb.c

index c04cc7cc76cce25d5e3eb05193284467eaf32313..d17825560ccf0b4ad15858aa87550a534b41e4b9 100644 (file)
@@ -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)
index d05f0e6e4b7bf94abcbd8b994cf871dbc6a13df2..64b4e7beafd30b4bfff600a07ebed37c5d6a1527 100644 (file)
@@ -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;