Commit a7ade7e1 authored by Chandan Babu R's avatar Chandan Babu R

Merge tag 'btree-readahead-cleanups-6.9_2024-02-23' of...

Merge tag 'btree-readahead-cleanups-6.9_2024-02-23' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux into xfs-6.9-mergeC

xfs: btree readahead cleanups

Minor cleanups for the btree block readahead code.
Signed-off-by: default avatarDarrick J. Wong <djwong@kernel.org>
Signed-off-by: default avatarChandan Babu R <chandanbabu@kernel.org>

* tag 'btree-readahead-cleanups-6.9_2024-02-23' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux:
  xfs: split xfs_buf_rele for cached vs uncached buffers
  xfs: move and rename xfs_btree_read_bufl
  xfs: remove xfs_btree_reada_bufs
  xfs: remove xfs_btree_reada_bufl
parents 169c030a 24f755e4
...@@ -226,6 +226,28 @@ xfs_bmap_forkoff_reset( ...@@ -226,6 +226,28 @@ xfs_bmap_forkoff_reset(
} }
} }
static int
xfs_bmap_read_buf(
struct xfs_mount *mp, /* file system mount point */
struct xfs_trans *tp, /* transaction pointer */
xfs_fsblock_t fsbno, /* file system block number */
struct xfs_buf **bpp) /* buffer for fsbno */
{
struct xfs_buf *bp; /* return value */
int error;
if (!xfs_verify_fsbno(mp, fsbno))
return -EFSCORRUPTED;
error = xfs_trans_read_buf(mp, tp, mp->m_ddev_targp,
XFS_FSB_TO_DADDR(mp, fsbno), mp->m_bsize, 0, &bp,
&xfs_bmbt_buf_ops);
if (!error) {
xfs_buf_set_ref(bp, XFS_BMAP_BTREE_REF);
*bpp = bp;
}
return error;
}
#ifdef DEBUG #ifdef DEBUG
STATIC struct xfs_buf * STATIC struct xfs_buf *
xfs_bmap_get_bp( xfs_bmap_get_bp(
...@@ -365,9 +387,7 @@ xfs_bmap_check_leaf_extents( ...@@ -365,9 +387,7 @@ xfs_bmap_check_leaf_extents(
bp = xfs_bmap_get_bp(cur, XFS_FSB_TO_DADDR(mp, bno)); bp = xfs_bmap_get_bp(cur, XFS_FSB_TO_DADDR(mp, bno));
if (!bp) { if (!bp) {
bp_release = 1; bp_release = 1;
error = xfs_btree_read_bufl(mp, NULL, bno, &bp, error = xfs_bmap_read_buf(mp, NULL, bno, &bp);
XFS_BMAP_BTREE_REF,
&xfs_bmbt_buf_ops);
if (xfs_metadata_is_sick(error)) if (xfs_metadata_is_sick(error))
xfs_btree_mark_sick(cur); xfs_btree_mark_sick(cur);
if (error) if (error)
...@@ -454,9 +474,7 @@ xfs_bmap_check_leaf_extents( ...@@ -454,9 +474,7 @@ xfs_bmap_check_leaf_extents(
bp = xfs_bmap_get_bp(cur, XFS_FSB_TO_DADDR(mp, bno)); bp = xfs_bmap_get_bp(cur, XFS_FSB_TO_DADDR(mp, bno));
if (!bp) { if (!bp) {
bp_release = 1; bp_release = 1;
error = xfs_btree_read_bufl(mp, NULL, bno, &bp, error = xfs_bmap_read_buf(mp, NULL, bno, &bp);
XFS_BMAP_BTREE_REF,
&xfs_bmbt_buf_ops);
if (xfs_metadata_is_sick(error)) if (xfs_metadata_is_sick(error))
xfs_btree_mark_sick(cur); xfs_btree_mark_sick(cur);
if (error) if (error)
...@@ -573,8 +591,7 @@ xfs_bmap_btree_to_extents( ...@@ -573,8 +591,7 @@ xfs_bmap_btree_to_extents(
return -EFSCORRUPTED; return -EFSCORRUPTED;
} }
#endif #endif
error = xfs_btree_read_bufl(mp, tp, cbno, &cbp, XFS_BMAP_BTREE_REF, error = xfs_bmap_read_buf(mp, tp, cbno, &cbp);
&xfs_bmbt_buf_ops);
if (xfs_metadata_is_sick(error)) if (xfs_metadata_is_sick(error))
xfs_btree_mark_sick(cur); xfs_btree_mark_sick(cur);
if (error) if (error)
......
...@@ -859,95 +859,26 @@ xfs_btree_offsets( ...@@ -859,95 +859,26 @@ xfs_btree_offsets(
} }
} }
/*
* Get a buffer for the block, return it read in.
* Long-form addressing.
*/
int
xfs_btree_read_bufl(
struct xfs_mount *mp, /* file system mount point */
struct xfs_trans *tp, /* transaction pointer */
xfs_fsblock_t fsbno, /* file system block number */
struct xfs_buf **bpp, /* buffer for fsbno */
int refval, /* ref count value for buffer */
const struct xfs_buf_ops *ops)
{
struct xfs_buf *bp; /* return value */
xfs_daddr_t d; /* real disk block address */
int error;
if (!xfs_verify_fsbno(mp, fsbno))
return -EFSCORRUPTED;
d = XFS_FSB_TO_DADDR(mp, fsbno);
error = xfs_trans_read_buf(mp, tp, mp->m_ddev_targp, d,
mp->m_bsize, 0, &bp, ops);
if (error)
return error;
if (bp)
xfs_buf_set_ref(bp, refval);
*bpp = bp;
return 0;
}
/*
* Read-ahead the block, don't wait for it, don't return a buffer.
* Long-form addressing.
*/
/* ARGSUSED */
void
xfs_btree_reada_bufl(
struct xfs_mount *mp, /* file system mount point */
xfs_fsblock_t fsbno, /* file system block number */
xfs_extlen_t count, /* count of filesystem blocks */
const struct xfs_buf_ops *ops)
{
xfs_daddr_t d;
ASSERT(fsbno != NULLFSBLOCK);
d = XFS_FSB_TO_DADDR(mp, fsbno);
xfs_buf_readahead(mp->m_ddev_targp, d, mp->m_bsize * count, ops);
}
/*
* Read-ahead the block, don't wait for it, don't return a buffer.
* Short-form addressing.
*/
/* ARGSUSED */
void
xfs_btree_reada_bufs(
struct xfs_mount *mp, /* file system mount point */
xfs_agnumber_t agno, /* allocation group number */
xfs_agblock_t agbno, /* allocation group block number */
xfs_extlen_t count, /* count of filesystem blocks */
const struct xfs_buf_ops *ops)
{
xfs_daddr_t d;
ASSERT(agno != NULLAGNUMBER);
ASSERT(agbno != NULLAGBLOCK);
d = XFS_AGB_TO_DADDR(mp, agno, agbno);
xfs_buf_readahead(mp->m_ddev_targp, d, mp->m_bsize * count, ops);
}
STATIC int STATIC int
xfs_btree_readahead_fsblock( xfs_btree_readahead_fsblock(
struct xfs_btree_cur *cur, struct xfs_btree_cur *cur,
int lr, int lr,
struct xfs_btree_block *block) struct xfs_btree_block *block)
{ {
int rval = 0; struct xfs_mount *mp = cur->bc_mp;
xfs_fsblock_t left = be64_to_cpu(block->bb_u.l.bb_leftsib); xfs_fsblock_t left = be64_to_cpu(block->bb_u.l.bb_leftsib);
xfs_fsblock_t right = be64_to_cpu(block->bb_u.l.bb_rightsib); xfs_fsblock_t right = be64_to_cpu(block->bb_u.l.bb_rightsib);
int rval = 0;
if ((lr & XFS_BTCUR_LEFTRA) && left != NULLFSBLOCK) { if ((lr & XFS_BTCUR_LEFTRA) && left != NULLFSBLOCK) {
xfs_btree_reada_bufl(cur->bc_mp, left, 1, xfs_buf_readahead(mp->m_ddev_targp, XFS_FSB_TO_DADDR(mp, left),
cur->bc_ops->buf_ops); mp->m_bsize, cur->bc_ops->buf_ops);
rval++; rval++;
} }
if ((lr & XFS_BTCUR_RIGHTRA) && right != NULLFSBLOCK) { if ((lr & XFS_BTCUR_RIGHTRA) && right != NULLFSBLOCK) {
xfs_btree_reada_bufl(cur->bc_mp, right, 1, xfs_buf_readahead(mp->m_ddev_targp, XFS_FSB_TO_DADDR(mp, right),
cur->bc_ops->buf_ops); mp->m_bsize, cur->bc_ops->buf_ops);
rval++; rval++;
} }
...@@ -958,22 +889,25 @@ STATIC int ...@@ -958,22 +889,25 @@ STATIC int
xfs_btree_readahead_agblock( xfs_btree_readahead_agblock(
struct xfs_btree_cur *cur, struct xfs_btree_cur *cur,
int lr, int lr,
struct xfs_btree_block *block) struct xfs_btree_block *block)
{ {
int rval = 0; struct xfs_mount *mp = cur->bc_mp;
xfs_agnumber_t agno = cur->bc_ag.pag->pag_agno;
xfs_agblock_t left = be32_to_cpu(block->bb_u.s.bb_leftsib); xfs_agblock_t left = be32_to_cpu(block->bb_u.s.bb_leftsib);
xfs_agblock_t right = be32_to_cpu(block->bb_u.s.bb_rightsib); xfs_agblock_t right = be32_to_cpu(block->bb_u.s.bb_rightsib);
int rval = 0;
if ((lr & XFS_BTCUR_LEFTRA) && left != NULLAGBLOCK) { if ((lr & XFS_BTCUR_LEFTRA) && left != NULLAGBLOCK) {
xfs_btree_reada_bufs(cur->bc_mp, cur->bc_ag.pag->pag_agno, xfs_buf_readahead(mp->m_ddev_targp,
left, 1, cur->bc_ops->buf_ops); XFS_AGB_TO_DADDR(mp, agno, left),
mp->m_bsize, cur->bc_ops->buf_ops);
rval++; rval++;
} }
if ((lr & XFS_BTCUR_RIGHTRA) && right != NULLAGBLOCK) { if ((lr & XFS_BTCUR_RIGHTRA) && right != NULLAGBLOCK) {
xfs_btree_reada_bufs(cur->bc_mp, cur->bc_ag.pag->pag_agno, xfs_buf_readahead(mp->m_ddev_targp,
right, 1, cur->bc_ops->buf_ops); XFS_AGB_TO_DADDR(mp, agno, right),
mp->m_bsize, cur->bc_ops->buf_ops);
rval++; rval++;
} }
......
...@@ -378,42 +378,6 @@ xfs_btree_offsets( ...@@ -378,42 +378,6 @@ xfs_btree_offsets(
int *first, /* output: first byte offset */ int *first, /* output: first byte offset */
int *last); /* output: last byte offset */ int *last); /* output: last byte offset */
/*
* Get a buffer for the block, return it read in.
* Long-form addressing.
*/
int /* error */
xfs_btree_read_bufl(
struct xfs_mount *mp, /* file system mount point */
struct xfs_trans *tp, /* transaction pointer */
xfs_fsblock_t fsbno, /* file system block number */
struct xfs_buf **bpp, /* buffer for fsbno */
int refval, /* ref count value for buffer */
const struct xfs_buf_ops *ops);
/*
* Read-ahead the block, don't wait for it, don't return a buffer.
* Long-form addressing.
*/
void /* error */
xfs_btree_reada_bufl(
struct xfs_mount *mp, /* file system mount point */
xfs_fsblock_t fsbno, /* file system block number */
xfs_extlen_t count, /* count of filesystem blocks */
const struct xfs_buf_ops *ops);
/*
* Read-ahead the block, don't wait for it, don't return a buffer.
* Short-form addressing.
*/
void /* error */
xfs_btree_reada_bufs(
struct xfs_mount *mp, /* file system mount point */
xfs_agnumber_t agno, /* allocation group number */
xfs_agblock_t agbno, /* allocation group block number */
xfs_extlen_t count, /* count of filesystem blocks */
const struct xfs_buf_ops *ops);
/* /*
* Initialise a new btree block header * Initialise a new btree block header
*/ */
......
...@@ -60,6 +60,11 @@ xfs_buf_submit( ...@@ -60,6 +60,11 @@ xfs_buf_submit(
return __xfs_buf_submit(bp, !(bp->b_flags & XBF_ASYNC)); return __xfs_buf_submit(bp, !(bp->b_flags & XBF_ASYNC));
} }
static inline bool xfs_buf_is_uncached(struct xfs_buf *bp)
{
return bp->b_rhash_key == XFS_BUF_DADDR_NULL;
}
static inline int static inline int
xfs_buf_is_vmapped( xfs_buf_is_vmapped(
struct xfs_buf *bp) struct xfs_buf *bp)
...@@ -996,12 +1001,19 @@ xfs_buf_hold( ...@@ -996,12 +1001,19 @@ xfs_buf_hold(
atomic_inc(&bp->b_hold); atomic_inc(&bp->b_hold);
} }
/* static void
* Release a hold on the specified buffer. If the hold count is 1, the buffer is xfs_buf_rele_uncached(
* placed on LRU or freed (depending on b_lru_ref). struct xfs_buf *bp)
*/ {
void ASSERT(list_empty(&bp->b_lru));
xfs_buf_rele( if (atomic_dec_and_test(&bp->b_hold)) {
xfs_buf_ioacct_dec(bp);
xfs_buf_free(bp);
}
}
static void
xfs_buf_rele_cached(
struct xfs_buf *bp) struct xfs_buf *bp)
{ {
struct xfs_perag *pag = bp->b_pag; struct xfs_perag *pag = bp->b_pag;
...@@ -1010,15 +1022,6 @@ xfs_buf_rele( ...@@ -1010,15 +1022,6 @@ xfs_buf_rele(
trace_xfs_buf_rele(bp, _RET_IP_); trace_xfs_buf_rele(bp, _RET_IP_);
if (!pag) {
ASSERT(list_empty(&bp->b_lru));
if (atomic_dec_and_test(&bp->b_hold)) {
xfs_buf_ioacct_dec(bp);
xfs_buf_free(bp);
}
return;
}
ASSERT(atomic_read(&bp->b_hold) > 0); ASSERT(atomic_read(&bp->b_hold) > 0);
/* /*
...@@ -1086,6 +1089,19 @@ xfs_buf_rele( ...@@ -1086,6 +1089,19 @@ xfs_buf_rele(
xfs_buf_free(bp); xfs_buf_free(bp);
} }
/*
* Release a hold on the specified buffer.
*/
void
xfs_buf_rele(
struct xfs_buf *bp)
{
trace_xfs_buf_rele(bp, _RET_IP_);
if (xfs_buf_is_uncached(bp))
xfs_buf_rele_uncached(bp);
else
xfs_buf_rele_cached(bp);
}
/* /*
* Lock a buffer object, if it is not already locked. * Lock a buffer object, if it is not already locked.
......
...@@ -100,6 +100,7 @@ xfs_iwalk_ichunk_ra( ...@@ -100,6 +100,7 @@ xfs_iwalk_ichunk_ra(
struct xfs_inobt_rec_incore *irec) struct xfs_inobt_rec_incore *irec)
{ {
struct xfs_ino_geometry *igeo = M_IGEO(mp); struct xfs_ino_geometry *igeo = M_IGEO(mp);
xfs_agnumber_t agno = pag->pag_agno;
xfs_agblock_t agbno; xfs_agblock_t agbno;
struct blk_plug plug; struct blk_plug plug;
int i; /* inode chunk index */ int i; /* inode chunk index */
...@@ -112,8 +113,9 @@ xfs_iwalk_ichunk_ra( ...@@ -112,8 +113,9 @@ xfs_iwalk_ichunk_ra(
imask = xfs_inobt_maskn(i, igeo->inodes_per_cluster); imask = xfs_inobt_maskn(i, igeo->inodes_per_cluster);
if (imask & ~irec->ir_free) { if (imask & ~irec->ir_free) {
xfs_btree_reada_bufs(mp, pag->pag_agno, agbno, xfs_buf_readahead(mp->m_ddev_targp,
igeo->blocks_per_cluster, XFS_AGB_TO_DADDR(mp, agno, agbno),
igeo->blocks_per_cluster * mp->m_bsize,
&xfs_inode_buf_ops); &xfs_inode_buf_ops);
} }
agbno += igeo->blocks_per_cluster; agbno += igeo->blocks_per_cluster;
......
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