From: Christoph Hellwig Date: Tue, 20 Aug 2024 11:52:36 +0000 (+0200) Subject: xfs: convert rtgroup lookup to an xarray X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=refs%2Fheads%2Fxfs-rtg-xarray;p=users%2Fhch%2Fxfs.git xfs: convert rtgroup lookup to an xarray 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 --- diff --git a/fs/xfs/libxfs/xfs_rtgroup.c b/fs/xfs/libxfs/xfs_rtgroup.c index ec4fc961dac8..54f0e61cb789 100644 --- a/fs/xfs/libxfs/xfs_rtgroup.c +++ b/fs/xfs/libxfs/xfs_rtgroup.c @@ -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; diff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h index 360d0064da66..7f1c8775fa31 100644 --- a/fs/xfs/xfs_mount.h +++ b/fs/xfs/xfs_mount.h @@ -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 */ diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c index 48d39a0c0079..4067456ab6c5 100644 --- a/fs/xfs/xfs_super.c +++ b/fs/xfs/xfs_super.c @@ -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);