Commit 1e5ffdc5 authored by Dave Chinner's avatar Dave Chinner Committed by Dave Chinner

Merge tag 'pass-perag-refs-6.4_2023-04-11' of...

Merge tag 'pass-perag-refs-6.4_2023-04-11' of git://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux into guilt/xfs-for-next

xfs: pass perag references around when possible [v24.5]

Avoid the cost of perag radix tree lookups by passing around active perag
references when possible.

v24.2: rework some of the naming and whatnot so there's less opencoding
Signed-off-by: default avatarDarrick J. Wong <djwong@kernel.org>
Signed-off-by: default avatarDave Chinner <david@fromorbit.com>
parents 826053db 9b2e5a23
...@@ -81,6 +81,19 @@ xfs_perag_get_tag( ...@@ -81,6 +81,19 @@ xfs_perag_get_tag(
return pag; return pag;
} }
/* Get a passive reference to the given perag. */
struct xfs_perag *
xfs_perag_hold(
struct xfs_perag *pag)
{
ASSERT(atomic_read(&pag->pag_ref) > 0 ||
atomic_read(&pag->pag_active_ref) > 0);
trace_xfs_perag_hold(pag, _RET_IP_);
atomic_inc(&pag->pag_ref);
return pag;
}
void void
xfs_perag_put( xfs_perag_put(
struct xfs_perag *pag) struct xfs_perag *pag)
......
...@@ -134,6 +134,7 @@ void xfs_free_perag(struct xfs_mount *mp); ...@@ -134,6 +134,7 @@ void xfs_free_perag(struct xfs_mount *mp);
struct xfs_perag *xfs_perag_get(struct xfs_mount *mp, xfs_agnumber_t agno); 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, struct xfs_perag *xfs_perag_get_tag(struct xfs_mount *mp, xfs_agnumber_t agno,
unsigned int tag); unsigned int tag);
struct xfs_perag *xfs_perag_hold(struct xfs_perag *pag);
void xfs_perag_put(struct xfs_perag *pag); void xfs_perag_put(struct xfs_perag *pag);
/* Active AG references */ /* Active AG references */
......
...@@ -492,9 +492,7 @@ xfs_allocbt_init_common( ...@@ -492,9 +492,7 @@ xfs_allocbt_init_common(
cur->bc_statoff = XFS_STATS_CALC_INDEX(xs_abtb_2); cur->bc_statoff = XFS_STATS_CALC_INDEX(xs_abtb_2);
} }
/* take a reference for the cursor */ cur->bc_ag.pag = xfs_perag_hold(pag);
atomic_inc(&pag->pag_ref);
cur->bc_ag.pag = pag;
if (xfs_has_crc(mp)) if (xfs_has_crc(mp))
cur->bc_flags |= XFS_BTREE_CRC_BLOCKS; cur->bc_flags |= XFS_BTREE_CRC_BLOCKS;
......
...@@ -450,9 +450,7 @@ xfs_inobt_init_common( ...@@ -450,9 +450,7 @@ xfs_inobt_init_common(
if (xfs_has_crc(mp)) if (xfs_has_crc(mp))
cur->bc_flags |= XFS_BTREE_CRC_BLOCKS; cur->bc_flags |= XFS_BTREE_CRC_BLOCKS;
/* take a reference for the cursor */ cur->bc_ag.pag = xfs_perag_hold(pag);
atomic_inc(&pag->pag_ref);
cur->bc_ag.pag = pag;
return cur; return cur;
} }
......
...@@ -340,10 +340,7 @@ xfs_refcountbt_init_common( ...@@ -340,10 +340,7 @@ xfs_refcountbt_init_common(
cur->bc_flags |= XFS_BTREE_CRC_BLOCKS; cur->bc_flags |= XFS_BTREE_CRC_BLOCKS;
/* take a reference for the cursor */ cur->bc_ag.pag = xfs_perag_hold(pag);
atomic_inc(&pag->pag_ref);
cur->bc_ag.pag = pag;
cur->bc_ag.refc.nr_ops = 0; cur->bc_ag.refc.nr_ops = 0;
cur->bc_ag.refc.shape_changes = 0; cur->bc_ag.refc.shape_changes = 0;
cur->bc_ops = &xfs_refcountbt_ops; cur->bc_ops = &xfs_refcountbt_ops;
......
...@@ -460,10 +460,7 @@ xfs_rmapbt_init_common( ...@@ -460,10 +460,7 @@ xfs_rmapbt_init_common(
cur->bc_statoff = XFS_STATS_CALC_INDEX(xs_rmap_2); cur->bc_statoff = XFS_STATS_CALC_INDEX(xs_rmap_2);
cur->bc_ops = &xfs_rmapbt_ops; cur->bc_ops = &xfs_rmapbt_ops;
/* take a reference for the cursor */ cur->bc_ag.pag = xfs_perag_hold(pag);
atomic_inc(&pag->pag_ref);
cur->bc_ag.pag = pag;
return cur; return cur;
} }
......
...@@ -168,9 +168,7 @@ xfs_iunlink_log_inode( ...@@ -168,9 +168,7 @@ xfs_iunlink_log_inode(
iup->ip = ip; iup->ip = ip;
iup->next_agino = next_agino; iup->next_agino = next_agino;
iup->old_agino = ip->i_next_unlinked; iup->old_agino = ip->i_next_unlinked;
iup->pag = xfs_perag_hold(pag);
atomic_inc(&pag->pag_ref);
iup->pag = pag;
xfs_trans_add_item(tp, &iup->item); xfs_trans_add_item(tp, &iup->item);
tp->t_flags |= XFS_TRANS_DIRTY; tp->t_flags |= XFS_TRANS_DIRTY;
......
...@@ -667,11 +667,10 @@ xfs_iwalk_threaded( ...@@ -667,11 +667,10 @@ xfs_iwalk_threaded(
iwag->mp = mp; iwag->mp = mp;
/* /*
* perag is being handed off to async work, so take another * perag is being handed off to async work, so take a passive
* reference for the async work to release. * reference for the async work to release.
*/ */
atomic_inc(&pag->pag_ref); iwag->pag = xfs_perag_hold(pag);
iwag->pag = pag;
iwag->iwalk_fn = iwalk_fn; iwag->iwalk_fn = iwalk_fn;
iwag->data = data; iwag->data = data;
iwag->startino = startino; iwag->startino = startino;
......
...@@ -190,6 +190,7 @@ DEFINE_EVENT(xfs_perag_class, name, \ ...@@ -190,6 +190,7 @@ DEFINE_EVENT(xfs_perag_class, name, \
TP_ARGS(pag, caller_ip)) TP_ARGS(pag, caller_ip))
DEFINE_PERAG_REF_EVENT(xfs_perag_get); DEFINE_PERAG_REF_EVENT(xfs_perag_get);
DEFINE_PERAG_REF_EVENT(xfs_perag_get_tag); DEFINE_PERAG_REF_EVENT(xfs_perag_get_tag);
DEFINE_PERAG_REF_EVENT(xfs_perag_hold);
DEFINE_PERAG_REF_EVENT(xfs_perag_put); DEFINE_PERAG_REF_EVENT(xfs_perag_put);
DEFINE_PERAG_REF_EVENT(xfs_perag_grab); DEFINE_PERAG_REF_EVENT(xfs_perag_grab);
DEFINE_PERAG_REF_EVENT(xfs_perag_grab_tag); DEFINE_PERAG_REF_EVENT(xfs_perag_grab_tag);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment