]> www.infradead.org Git - users/hch/xfs.git/commitdiff
xfs: use xas_for_each_marked in xfs_reclaim_inodes_count
authorChristoph Hellwig <hch@lst.de>
Thu, 29 Aug 2024 04:08:41 +0000 (07:08 +0300)
committerChandan Babu R <chandanbabu@kernel.org>
Tue, 3 Sep 2024 04:37:46 +0000 (10:07 +0530)
xfs_reclaim_inodes_count iterates over all AGs to sum up the reclaimable
inodes counts.  There is no point in grabbing a reference to the them or
unlock the RCU critical section for each iteration, so switch to the
more efficient xas_for_each_marked iterator.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>
fs/xfs/xfs_icache.c
fs/xfs/xfs_trace.h

index ba9d4c8581831b303ec8b2952b64ad71bebf1c83..20d9924f28c246e4d205310b5fd8f11b68dae85a 100644 (file)
@@ -300,32 +300,6 @@ xfs_perag_clear_inode_tag(
        trace_xfs_perag_clear_inode_tag(pag, _RET_IP_);
 }
 
-/*
- * Find the next AG after @pag, or the first AG if @pag is NULL.
- */
-static struct xfs_perag *
-xfs_perag_get_next_tag(
-       struct xfs_mount        *mp,
-       struct xfs_perag        *pag,
-       unsigned int            tag)
-{
-       unsigned long           index = 0;
-
-       if (pag) {
-               index = pag->pag_agno + 1;
-               xfs_perag_rele(pag);
-       }
-
-       rcu_read_lock();
-       pag = xa_find(&mp->m_perags, &index, ULONG_MAX, ici_tag_to_mark(tag));
-       if (pag) {
-               trace_xfs_perag_get_next_tag(pag, _RET_IP_);
-               atomic_inc(&pag->pag_ref);
-       }
-       rcu_read_unlock();
-       return pag;
-}
-
 /*
  * Find the next AG after @pag, or the first AG if @pag is NULL.
  */
@@ -1080,11 +1054,17 @@ long
 xfs_reclaim_inodes_count(
        struct xfs_mount        *mp)
 {
-       struct xfs_perag        *pag = NULL;
+       XA_STATE                (xas, &mp->m_perags, 0);
        long                    reclaimable = 0;
+       struct xfs_perag        *pag;
 
-       while ((pag = xfs_perag_get_next_tag(mp, pag, XFS_ICI_RECLAIM_TAG)))
+       rcu_read_lock();
+       xas_for_each_marked(&xas, pag, ULONG_MAX, XFS_PERAG_RECLAIM_MARK) {
+               trace_xfs_reclaim_inodes_count(pag, _THIS_IP_);
                reclaimable += pag->pag_ici_reclaimable;
+       }
+       rcu_read_unlock();
+
        return reclaimable;
 }
 
index 920743c89685c2b6510facc449b56860e84417da..ee9f0b1f548dc1ef6de47db50e7740f67b20744a 100644 (file)
@@ -210,7 +210,6 @@ DEFINE_EVENT(xfs_perag_class, name, \
        TP_PROTO(struct xfs_perag *pag, unsigned long caller_ip), \
        TP_ARGS(pag, caller_ip))
 DEFINE_PERAG_REF_EVENT(xfs_perag_get);
-DEFINE_PERAG_REF_EVENT(xfs_perag_get_next_tag);
 DEFINE_PERAG_REF_EVENT(xfs_perag_hold);
 DEFINE_PERAG_REF_EVENT(xfs_perag_put);
 DEFINE_PERAG_REF_EVENT(xfs_perag_grab);
@@ -218,6 +217,7 @@ DEFINE_PERAG_REF_EVENT(xfs_perag_grab_next_tag);
 DEFINE_PERAG_REF_EVENT(xfs_perag_rele);
 DEFINE_PERAG_REF_EVENT(xfs_perag_set_inode_tag);
 DEFINE_PERAG_REF_EVENT(xfs_perag_clear_inode_tag);
+DEFINE_PERAG_REF_EVENT(xfs_reclaim_inodes_count);
 
 TRACE_EVENT(xfs_inodegc_worker,
        TP_PROTO(struct xfs_mount *mp, unsigned int shrinker_hits),