Message ID | 162259517467.662681.7329146794207007368.stgit@locust (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | xfs: clean up incore inode walk functions | expand |
On Tue, Jun 01, 2021 at 05:52:54PM -0700, Darrick J. Wong wrote: > From: Darrick J. Wong <djwong@kernel.org> > > As part of removing the indirect calls and radix tag implementation > details from the incore inode walk loop, create an enum to represent the > goal of the inode iteration. More immediately, this separate removes > the need for the "ICI_NOTAG" define which makes little sense. > > Signed-off-by: Darrick J. Wong <djwong@kernel.org> > --- > fs/xfs/xfs_icache.c | 51 +++++++++++++++++++++++++++++++++++++-------------- > fs/xfs/xfs_icache.h | 9 --------- > 2 files changed, 37 insertions(+), 23 deletions(-) > > > diff --git a/fs/xfs/xfs_icache.c b/fs/xfs/xfs_icache.c > index e70ce7868444..018b3f8bdd21 100644 > --- a/fs/xfs/xfs_icache.c > +++ b/fs/xfs/xfs_icache.c > @@ -26,12 +26,35 @@ > > #include <linux/iversion.h> > > +/* Radix tree tags for incore inode tree. */ > + > +/* inode is to be reclaimed */ > +#define XFS_ICI_RECLAIM_TAG 0 > +/* Inode has speculative preallocations (posteof or cow) to clean. */ > +#define XFS_ICI_BLOCKGC_TAG 1 > + > +/* > + * The goal for walking incore inodes. These can correspond with incore inode > + * radix tree tags when convenient. Avoid existing XFS_IWALK namespace. > + */ > +enum xfs_icwalk_goal { > + XFS_ICWALK_DQRELE = -1, > + XFS_ICWALK_BLOCKGC = XFS_ICI_BLOCKGC_TAG, > +}; > + > +/* Is there a radix tree tag for this goal? */ > +static inline bool > +xfs_icwalk_tagged(enum xfs_icwalk_goal goal) > +{ > + return goal != XFS_ICWALK_DQRELE; > +} I think I'd rather the "non tag" types be explicitly defined to be less than zero, and the tagged types be greater than zero and (maybe) match the tag to be used for lookup. That way we end up with: static inline int xfs_icwalk_tag(enum xfs_icwalk_goal goal) { if (goal < 0) return -1; return goal; } And we have a mechanism that allows for us to have multiple goals point at the same tag by replacing the 'return goal' with a switch statement. THen... > @@ -1650,7 +1673,7 @@ xfs_inode_walk_ag( > > rcu_read_lock(); > > - if (tag == XFS_ICI_NO_TAG) > + if (!xfs_icwalk_tagged(goal)) > nr_found = radix_tree_gang_lookup(&pag->pag_ici_root, > (void **)batch, first_index, > XFS_LOOKUP_BATCH); > @@ -1658,7 +1681,7 @@ xfs_inode_walk_ag( > nr_found = radix_tree_gang_lookup_tag( > &pag->pag_ici_root, > (void **) batch, first_index, > - XFS_LOOKUP_BATCH, tag); > + XFS_LOOKUP_BATCH, goal); This becomes: tag = xfs_icwalk_tag(goal); if (tag < 0) /* do untagged lookup */ else /* do tagged lookup w/ tag */ > > if (!nr_found) { > rcu_read_unlock(); > @@ -1733,11 +1756,11 @@ static inline struct xfs_perag * > xfs_inode_walk_get_perag( > struct xfs_mount *mp, > xfs_agnumber_t agno, > - int tag) > + enum xfs_icwalk_goal goal) > { > - if (tag == XFS_ICI_NO_TAG) > + if (!xfs_icwalk_tagged(goal)) > return xfs_perag_get(mp, agno); > - return xfs_perag_get_tag(mp, agno, tag); > + return xfs_perag_get_tag(mp, agno, goal); > } > > /* > @@ -1750,7 +1773,7 @@ xfs_inode_walk( > int iter_flags, > int (*execute)(struct xfs_inode *ip, void *args), > void *args, > - int tag) > + enum xfs_icwalk_goal goal) > { > struct xfs_perag *pag; > int error = 0; > @@ -1758,9 +1781,9 @@ xfs_inode_walk( > xfs_agnumber_t ag; > > ag = 0; > - while ((pag = xfs_inode_walk_get_perag(mp, ag, tag))) { > + while ((pag = xfs_inode_walk_get_perag(mp, ag, goal))) { > ag = pag->pag_agno + 1; > - error = xfs_inode_walk_ag(pag, iter_flags, execute, args, tag); > + error = xfs_inode_walk_ag(pag, iter_flags, execute, args, goal); > xfs_perag_put(pag); > if (error) { > last_error = error; FYI, I'm soon going to be modifying this walk to separate it out into for_each_perag() and for_each_perag_tagged() for shrink protection. This becomes cleaner if we have a single xfs_icwalk_tag() call here rather than hiding it inside xfs_inode_walk_get_perag(). Not something you need to address here, but I thought I'd mention it so you can think about that while contemplating my suggestion above... Cheers, Dave.
diff --git a/fs/xfs/xfs_icache.c b/fs/xfs/xfs_icache.c index e70ce7868444..018b3f8bdd21 100644 --- a/fs/xfs/xfs_icache.c +++ b/fs/xfs/xfs_icache.c @@ -26,12 +26,35 @@ #include <linux/iversion.h> +/* Radix tree tags for incore inode tree. */ + +/* inode is to be reclaimed */ +#define XFS_ICI_RECLAIM_TAG 0 +/* Inode has speculative preallocations (posteof or cow) to clean. */ +#define XFS_ICI_BLOCKGC_TAG 1 + +/* + * The goal for walking incore inodes. These can correspond with incore inode + * radix tree tags when convenient. Avoid existing XFS_IWALK namespace. + */ +enum xfs_icwalk_goal { + XFS_ICWALK_DQRELE = -1, + XFS_ICWALK_BLOCKGC = XFS_ICI_BLOCKGC_TAG, +}; + +/* Is there a radix tree tag for this goal? */ +static inline bool +xfs_icwalk_tagged(enum xfs_icwalk_goal goal) +{ + return goal != XFS_ICWALK_DQRELE; +} + static int xfs_inode_walk(struct xfs_mount *mp, int iter_flags, int (*execute)(struct xfs_inode *ip, void *args), - void *args, int tag); + void *args, enum xfs_icwalk_goal goal); static int xfs_inode_walk_ag(struct xfs_perag *pag, int iter_flags, int (*execute)(struct xfs_inode *ip, void *args), - void *args, int tag); + void *args, enum xfs_icwalk_goal goal); /* * Allocate and initialise an xfs_inode. @@ -781,7 +804,7 @@ xfs_dqrele_all_inodes( eofb.eof_flags |= XFS_EOFB_DROP_PDQUOT; return xfs_inode_walk(mp, XFS_INODE_WALK_INEW_WAIT, xfs_dqrele_inode, - &eofb, XFS_ICI_NO_TAG); + &eofb, XFS_ICWALK_DQRELE); } #endif /* CONFIG_XFS_QUOTA */ @@ -1529,7 +1552,7 @@ xfs_blockgc_worker( if (!sb_start_write_trylock(mp->m_super)) return; error = xfs_inode_walk_ag(pag, 0, xfs_blockgc_scan_inode, NULL, - XFS_ICI_BLOCKGC_TAG); + XFS_ICWALK_BLOCKGC); if (error) xfs_info(mp, "AG %u preallocation gc worker failed, err=%d", pag->pag_agno, error); @@ -1548,7 +1571,7 @@ xfs_blockgc_free_space( trace_xfs_blockgc_free_space(mp, eofb, _RET_IP_); return xfs_inode_walk(mp, 0, xfs_blockgc_scan_inode, eofb, - XFS_ICI_BLOCKGC_TAG); + XFS_ICWALK_BLOCKGC); } /* @@ -1629,7 +1652,7 @@ xfs_inode_walk_ag( int iter_flags, int (*execute)(struct xfs_inode *ip, void *args), void *args, - int tag) + enum xfs_icwalk_goal goal) { struct xfs_mount *mp = pag->pag_mount; uint32_t first_index; @@ -1650,7 +1673,7 @@ xfs_inode_walk_ag( rcu_read_lock(); - if (tag == XFS_ICI_NO_TAG) + if (!xfs_icwalk_tagged(goal)) nr_found = radix_tree_gang_lookup(&pag->pag_ici_root, (void **)batch, first_index, XFS_LOOKUP_BATCH); @@ -1658,7 +1681,7 @@ xfs_inode_walk_ag( nr_found = radix_tree_gang_lookup_tag( &pag->pag_ici_root, (void **) batch, first_index, - XFS_LOOKUP_BATCH, tag); + XFS_LOOKUP_BATCH, goal); if (!nr_found) { rcu_read_unlock(); @@ -1733,11 +1756,11 @@ static inline struct xfs_perag * xfs_inode_walk_get_perag( struct xfs_mount *mp, xfs_agnumber_t agno, - int tag) + enum xfs_icwalk_goal goal) { - if (tag == XFS_ICI_NO_TAG) + if (!xfs_icwalk_tagged(goal)) return xfs_perag_get(mp, agno); - return xfs_perag_get_tag(mp, agno, tag); + return xfs_perag_get_tag(mp, agno, goal); } /* @@ -1750,7 +1773,7 @@ xfs_inode_walk( int iter_flags, int (*execute)(struct xfs_inode *ip, void *args), void *args, - int tag) + enum xfs_icwalk_goal goal) { struct xfs_perag *pag; int error = 0; @@ -1758,9 +1781,9 @@ xfs_inode_walk( xfs_agnumber_t ag; ag = 0; - while ((pag = xfs_inode_walk_get_perag(mp, ag, tag))) { + while ((pag = xfs_inode_walk_get_perag(mp, ag, goal))) { ag = pag->pag_agno + 1; - error = xfs_inode_walk_ag(pag, iter_flags, execute, args, tag); + error = xfs_inode_walk_ag(pag, iter_flags, execute, args, goal); xfs_perag_put(pag); if (error) { last_error = error; diff --git a/fs/xfs/xfs_icache.h b/fs/xfs/xfs_icache.h index a4f737cea460..bc0998a2f7d6 100644 --- a/fs/xfs/xfs_icache.h +++ b/fs/xfs/xfs_icache.h @@ -26,15 +26,6 @@ struct xfs_eofblocks { XFS_EOFB_DROP_GDQUOT | \ XFS_EOFB_DROP_PDQUOT) -/* - * tags for inode radix tree - */ -#define XFS_ICI_NO_TAG (-1) /* special flag for an untagged lookup - in xfs_inode_walk */ -#define XFS_ICI_RECLAIM_TAG 0 /* inode is to be reclaimed */ -/* Inode has speculative preallocations (posteof or cow) to clean. */ -#define XFS_ICI_BLOCKGC_TAG 1 - /* * Flags for xfs_iget() */