]> www.infradead.org Git - users/hch/xfs.git/commitdiff
xfs: convert rtgroup lookup to an xarray xfs-rtg-xarray
authorChristoph Hellwig <hch@lst.de>
Tue, 20 Aug 2024 11:52:36 +0000 (13:52 +0200)
committerChristoph Hellwig <hch@lst.de>
Tue, 20 Aug 2024 14:22:58 +0000 (16:22 +0200)
The xarray is the modern replacement for the radix-tree.  It is simpler
to use, especially when using marks to find specific entries, something
we will heavily use for the zone allocator implementation.

Signed-off-by: Christoph Hellwig <hch@lst.de>
fs/xfs/libxfs/xfs_rtgroup.c
fs/xfs/xfs_mount.h
fs/xfs/xfs_super.c

index ec4fc961dac8e57e46a1103bb32fc9bdbdfc7c08..54f0e61cb78962c997c8aa8581362bfe13f08938 100644 (file)
@@ -49,7 +49,7 @@ xfs_rtgroup_get(
        struct xfs_rtgroup      *rtg;
 
        rcu_read_lock();
-       rtg = radix_tree_lookup(&mp->m_rtgroup_tree, rgno);
+       rtg = xa_load(&mp->m_rtgroups, rgno);
        if (rtg) {
                trace_xfs_rtgroup_get(rtg, _RET_IP_);
                ASSERT(atomic_read(&rtg->rtg_ref) >= 0);
@@ -95,7 +95,7 @@ xfs_rtgroup_grab(
        struct xfs_rtgroup      *rtg;
 
        rcu_read_lock();
-       rtg = radix_tree_lookup(&mp->m_rtgroup_tree, agno);
+       rtg = xa_load(&mp->m_rtgroups, agno);
        if (rtg) {
                trace_xfs_rtgroup_grab(rtg, _RET_IP_);
                if (!atomic_inc_not_zero(&rtg->rtg_active_ref))
@@ -128,19 +128,11 @@ xfs_rtgroup_alloc(
        rtg->rtg_rgno = rgno;
        rtg->rtg_mount = mp;
 
-       error = radix_tree_preload(GFP_NOFS);
-       if (error)
-               goto out_free_rtg;
-
-       spin_lock(&mp->m_rtgroup_lock);
-       if (radix_tree_insert(&mp->m_rtgroup_tree, rgno, rtg)) {
-               spin_unlock(&mp->m_rtgroup_lock);
-               radix_tree_preload_end();
-               error = -EEXIST;
+       error = xa_insert(&mp->m_rtgroups, rgno, rtg, GFP_KERNEL);
+       if (error) {
+               WARN_ON_ONCE(error == -EBUSY);
                goto out_free_rtg;
        }
-       spin_unlock(&mp->m_rtgroup_lock);
-       radix_tree_preload_end();
 
 #ifdef __KERNEL__
        /* Place kernel structure only init below this point. */
@@ -166,10 +158,7 @@ xfs_rtgroup_free(
 {
        struct xfs_rtgroup      *rtg;
 
-       spin_lock(&mp->m_rtgroup_lock);
-       rtg = radix_tree_delete(&mp->m_rtgroup_tree, rgno);
-       spin_unlock(&mp->m_rtgroup_lock);
-
+       rtg = xa_erase(&mp->m_rtgroups, rgno);
        if (!rtg) /* can happen when growfs fails */
                return;
 
index 360d0064da66adb84b79ab24bffa27a58f26e96b..7f1c8775fa319a9634c3654eaf7d488f3fa75aff 100644 (file)
@@ -213,8 +213,7 @@ typedef struct xfs_mount {
         */
        atomic64_t              m_allocbt_blks;
 
-       struct radix_tree_root  m_rtgroup_tree; /* per-rt group info */
-       spinlock_t              m_rtgroup_lock; /* lock for m_rtgroup_tree */
+       struct xarray           m_rtgroups;     /* per-rt group info */
        struct radix_tree_root  m_perag_tree;   /* per-ag accounting info */
        spinlock_t              m_perag_lock;   /* lock for m_perag_tree */
        uint64_t                m_resblks;      /* total reserved blocks */
index 48d39a0c00797f63d2f0802dd3ffaba847d4648c..4067456ab6c58092afce8f2fac8a62a605e47201 100644 (file)
@@ -2031,8 +2031,7 @@ static int xfs_init_fs_context(
        spin_lock_init(&mp->m_sb_lock);
        INIT_RADIX_TREE(&mp->m_perag_tree, GFP_ATOMIC);
        spin_lock_init(&mp->m_perag_lock);
-       INIT_RADIX_TREE(&mp->m_rtgroup_tree, GFP_ATOMIC);
-       spin_lock_init(&mp->m_rtgroup_lock);
+       xa_init(&mp->m_rtgroups);
        mutex_init(&mp->m_growlock);
        INIT_WORK(&mp->m_flush_inodes_work, xfs_flush_inodes_worker);
        INIT_DELAYED_WORK(&mp->m_reclaim_work, xfs_reclaim_worker);