xfsprogs port of perag xarray conversion
Hi all,
this series contains the xfsprogs port of the perag xarray conversion.
PATCH 1/4 libfrog: add xarray emulation
Implement the simple parts of the kernel xarray API on-top of the libfrog radix-tree.
--- libfrog/radix-tree.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
libfrog/radix-tree.h +30 -0
@@ -63,4 +63,34 @@ int radix_tree_tagged(struct radix_tree_root *root, unsigned int tag);static inline int radix_tree_preload (int gfp_mask) {return 0 ; }static inline void radix_tree_preload_end (void ) { } +/* +* Emulation of the kernel xarray API. Note that unlike the kernel +* xarray, there is no internal locking so code using this should not +* allow concurrent operations in userspace. +*/ +struct xarray { +struct radix_tree_root r; +}; + +static inline void xa_init (struct xarray *xa) +{ +INIT_RADIX_TREE (&xa->r,GFP_KERNEL ); +} + +static inline void *xa_load (struct xarray *xa,unsigned long index) +{ +return radix_tree_lookup (&xa->r, index); +} + +static inline void *xa_erase (struct xarray *xa,unsigned long index) +{ +return radix_tree_delete (&xa->r, index); +} + +static inline int xa_set (struct xarray *xa,unsigned long index,void *entry, +unsigned int gfp) +{ +return radix_tree_insert (&xa->r, index, entry); +} +#endif /* __LIBFROG_RADIX_TREE_H__ */
Signature · 1 line
2.43.0
PATCH 2/4 libxfs: add a kfree_rcu_mightsleep stub
In reply to Christoph HellwigAdd a kfree_rcu_mightsleep stub so that code that needs to RCU free AGs in kernelspace can simply use this helper in xfsprogs.
--- include/kmem.h | 10 ++++++++++ 1 file changed, 10 insertions(+)
include/kmem.h +10 -0
@@ -65,6 +65,16 @@ static inline void kfree(const void *ptr)free ((void *)ptr); } +/* +* Stub for the kernel kfree_rcu_mightsleep. Does not actually wait +* for a RCU grace period, so can only be used in code that does not +* require RCU protection in userspace. +*/ +static inline void kfree_rcu_mightsleep (const void *ptr) +{ +kfree (ptr); +} + __attribute__((format (printf,2 ,3 )))char *kasprintf (gfp_t gfp,const char *fmt, ...);
Signature · 1 line
2.43.0
PATCH 3/4 xfs: convert perag lookup to xarray
In reply to Christoph HellwigSource kernel commit: ab6159870e68c198e4990faa8f82f348657d73f9
Convert the perag lookup from the legacy radix tree to the xarray, which allows for much nicer iteration and bulk lookup semantics.
Note that this removes the helpers for tagged get and grab and the for_each* wrappers built around them and instead uses the xa_for_each* iteration helpers directly in xfs_icache.c, which simplifies the code nicely.
--- include/xfs_mount.h | 2 +- libxfs/init.c | 2 +- libxfs/xfs_ag.c | 81 +++++---------------------------------------- libxfs/xfs_ag.h | 11 ------ 4 files changed, 10 insertions(+), 86 deletions(-)
include/xfs_mount.h +1 -1
@@ -91,7 +91,7 @@ typedef struct xfs_mount {xfs_extlen_t m_ag_prealloc_blocks;/* reserved ag blocks */ uint m_alloc_set_aside;/* space we can't use */ uint m_ag_max_usable;/* max space per AG */ -struct radix_tree_root m_perag_tree; +struct xarray m_perags;uint64_t m_features;/* active filesystem features */ uint64_t m_low_space[XFS_LOWSP_MAX ];uint64_t m_rtxblkmask;/* rt extent block mask */
libxfs/init.c +1 -1
@@ -664,7 +664,7 @@ libxfs_mount( mp->m_finobt_nores = true;xfs_set_inode32 (mp); mp->m_sb = *sb; -INIT_RADIX_TREE (&mp->m_perag_tree,GFP_KERNEL ); +xa_init (&mp->m_perags); sbp = &mp->m_sb;spin_lock_init (&mp->m_sb_lock);spin_lock_init (&mp->m_agirotor_lock);
libxfs/xfs_ag.c +8 -73
131 lines not on this page · raw message
libxfs/xfs_ag.h +0 -11
@@ -156,15 +156,11 @@ void xfs_free_perag(struct xfs_mount *mp);/* Passive AG references */ struct xfs_perag *xfs_perag_get (struct xfs_mount *mp,xfs_agnumber_t agno); -struct xfs_perag *xfs_perag_get_tag (struct xfs_mount *mp,xfs_agnumber_t agno, -unsigned int tag);struct xfs_perag *xfs_perag_hold (struct xfs_perag *pag);void xfs_perag_put (struct xfs_perag *pag);/* Active AG references */ struct xfs_perag *xfs_perag_grab (struct xfs_mount *,xfs_agnumber_t ); -struct xfs_perag *xfs_perag_grab_tag (struct xfs_mount *,xfs_agnumber_t , -int tag);void xfs_perag_rele (struct xfs_perag *pag);/*
@@ -266,13 +262,6 @@ xfs_perag_next( (agno) =0 ; \ for_each_perag_from((mp), (agno), (pag)) -#define for_each_perag_tag (mp, agno, pag, tag) \ - for ((agno) = 0, (pag) = xfs_perag_grab_tag((mp), 0, (tag)); \ - (pag) != NULL; \ - (agno) = (pag)->pag_agno + 1, \ - xfs_perag_rele(pag), \ - (pag) = xfs_perag_grab_tag((mp), (agno), (tag))) -static inline struct xfs_perag * xfs_perag_next_wrap( struct xfs_perag *pag,
Signature · 1 line
2.43.0
PATCH 4/4 xfs: use kfree_rcu_mightsleep to free the perag structures
In reply to Christoph HellwigSource kernel commit: 7344fea851552b1586ee161147a749995504b368
Using the kfree_rcu_mightsleep is simpler and removes the need for a rcu_head in the perag structure.
--- libxfs/xfs_ag.c | 12 +----------- libxfs/xfs_ag.h | 3 --- 2 files changed, 1 insertion(+), 14 deletions(-)
libxfs/xfs_ag.c +1 -11
@@ -183,16 +183,6 @@ out:return error; } -STATIC void -__xfs_free_perag ( -struct rcu_head *head) -{ - struct xfs_perag *pag = container_of(head, struct xfs_perag, rcu_head); - -ASSERT (!delayed_work_pending (&pag->pag_blockgc_work)); -kfree (pag); -} -/* * Free up the per-ag resources associated with the mount structure. */
@@ -216,7 +206,7 @@ xfs_free_perag(xfs_perag_rele (pag);XFS_IS_CORRUPT (pag->pag_mount,atomic_read (&pag->pag_active_ref) !=0 ); -call_rcu (&pag->rcu_head, __xfs_free_perag); +kfree_rcu_mightsleep (pag); } }
libxfs/xfs_ag.h +0 -3
@@ -63,9 +63,6 @@ struct xfs_perag {/* Blocks reserved for the reverse mapping btree. */ struct xfs_ag_resv pag_rmapbt_resv; -/* for rcu-safe freeing */ -struct rcu_head rcu_head; -/* Precalculated geometry info */ xfs_agblock_t block_count;xfs_agblock_t min_block;
Signature · 1 line
2.43.0