Skip to content

Commit a7ade7e

Browse files
author
Chandan Babu R
committed
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: Darrick J. Wong <djwong@kernel.org> Signed-off-by: Chandan 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
2 parents 169c030 + 24f755e commit a7ade7e

5 files changed

Lines changed: 76 additions & 143 deletions

File tree

fs/xfs/libxfs/xfs_bmap.c

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,28 @@ xfs_bmap_forkoff_reset(
226226
}
227227
}
228228

229+
static int
230+
xfs_bmap_read_buf(
231+
struct xfs_mount *mp, /* file system mount point */
232+
struct xfs_trans *tp, /* transaction pointer */
233+
xfs_fsblock_t fsbno, /* file system block number */
234+
struct xfs_buf **bpp) /* buffer for fsbno */
235+
{
236+
struct xfs_buf *bp; /* return value */
237+
int error;
238+
239+
if (!xfs_verify_fsbno(mp, fsbno))
240+
return -EFSCORRUPTED;
241+
error = xfs_trans_read_buf(mp, tp, mp->m_ddev_targp,
242+
XFS_FSB_TO_DADDR(mp, fsbno), mp->m_bsize, 0, &bp,
243+
&xfs_bmbt_buf_ops);
244+
if (!error) {
245+
xfs_buf_set_ref(bp, XFS_BMAP_BTREE_REF);
246+
*bpp = bp;
247+
}
248+
return error;
249+
}
250+
229251
#ifdef DEBUG
230252
STATIC struct xfs_buf *
231253
xfs_bmap_get_bp(
@@ -365,9 +387,7 @@ xfs_bmap_check_leaf_extents(
365387
bp = xfs_bmap_get_bp(cur, XFS_FSB_TO_DADDR(mp, bno));
366388
if (!bp) {
367389
bp_release = 1;
368-
error = xfs_btree_read_bufl(mp, NULL, bno, &bp,
369-
XFS_BMAP_BTREE_REF,
370-
&xfs_bmbt_buf_ops);
390+
error = xfs_bmap_read_buf(mp, NULL, bno, &bp);
371391
if (xfs_metadata_is_sick(error))
372392
xfs_btree_mark_sick(cur);
373393
if (error)
@@ -454,9 +474,7 @@ xfs_bmap_check_leaf_extents(
454474
bp = xfs_bmap_get_bp(cur, XFS_FSB_TO_DADDR(mp, bno));
455475
if (!bp) {
456476
bp_release = 1;
457-
error = xfs_btree_read_bufl(mp, NULL, bno, &bp,
458-
XFS_BMAP_BTREE_REF,
459-
&xfs_bmbt_buf_ops);
477+
error = xfs_bmap_read_buf(mp, NULL, bno, &bp);
460478
if (xfs_metadata_is_sick(error))
461479
xfs_btree_mark_sick(cur);
462480
if (error)
@@ -573,8 +591,7 @@ xfs_bmap_btree_to_extents(
573591
return -EFSCORRUPTED;
574592
}
575593
#endif
576-
error = xfs_btree_read_bufl(mp, tp, cbno, &cbp, XFS_BMAP_BTREE_REF,
577-
&xfs_bmbt_buf_ops);
594+
error = xfs_bmap_read_buf(mp, tp, cbno, &cbp);
578595
if (xfs_metadata_is_sick(error))
579596
xfs_btree_mark_sick(cur);
580597
if (error)

fs/xfs/libxfs/xfs_btree.c

Lines changed: 16 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -859,95 +859,26 @@ xfs_btree_offsets(
859859
}
860860
}
861861

862-
/*
863-
* Get a buffer for the block, return it read in.
864-
* Long-form addressing.
865-
*/
866-
int
867-
xfs_btree_read_bufl(
868-
struct xfs_mount *mp, /* file system mount point */
869-
struct xfs_trans *tp, /* transaction pointer */
870-
xfs_fsblock_t fsbno, /* file system block number */
871-
struct xfs_buf **bpp, /* buffer for fsbno */
872-
int refval, /* ref count value for buffer */
873-
const struct xfs_buf_ops *ops)
874-
{
875-
struct xfs_buf *bp; /* return value */
876-
xfs_daddr_t d; /* real disk block address */
877-
int error;
878-
879-
if (!xfs_verify_fsbno(mp, fsbno))
880-
return -EFSCORRUPTED;
881-
d = XFS_FSB_TO_DADDR(mp, fsbno);
882-
error = xfs_trans_read_buf(mp, tp, mp->m_ddev_targp, d,
883-
mp->m_bsize, 0, &bp, ops);
884-
if (error)
885-
return error;
886-
if (bp)
887-
xfs_buf_set_ref(bp, refval);
888-
*bpp = bp;
889-
return 0;
890-
}
891-
892-
/*
893-
* Read-ahead the block, don't wait for it, don't return a buffer.
894-
* Long-form addressing.
895-
*/
896-
/* ARGSUSED */
897-
void
898-
xfs_btree_reada_bufl(
899-
struct xfs_mount *mp, /* file system mount point */
900-
xfs_fsblock_t fsbno, /* file system block number */
901-
xfs_extlen_t count, /* count of filesystem blocks */
902-
const struct xfs_buf_ops *ops)
903-
{
904-
xfs_daddr_t d;
905-
906-
ASSERT(fsbno != NULLFSBLOCK);
907-
d = XFS_FSB_TO_DADDR(mp, fsbno);
908-
xfs_buf_readahead(mp->m_ddev_targp, d, mp->m_bsize * count, ops);
909-
}
910-
911-
/*
912-
* Read-ahead the block, don't wait for it, don't return a buffer.
913-
* Short-form addressing.
914-
*/
915-
/* ARGSUSED */
916-
void
917-
xfs_btree_reada_bufs(
918-
struct xfs_mount *mp, /* file system mount point */
919-
xfs_agnumber_t agno, /* allocation group number */
920-
xfs_agblock_t agbno, /* allocation group block number */
921-
xfs_extlen_t count, /* count of filesystem blocks */
922-
const struct xfs_buf_ops *ops)
923-
{
924-
xfs_daddr_t d;
925-
926-
ASSERT(agno != NULLAGNUMBER);
927-
ASSERT(agbno != NULLAGBLOCK);
928-
d = XFS_AGB_TO_DADDR(mp, agno, agbno);
929-
xfs_buf_readahead(mp->m_ddev_targp, d, mp->m_bsize * count, ops);
930-
}
931-
932862
STATIC int
933863
xfs_btree_readahead_fsblock(
934864
struct xfs_btree_cur *cur,
935865
int lr,
936866
struct xfs_btree_block *block)
937867
{
938-
int rval = 0;
868+
struct xfs_mount *mp = cur->bc_mp;
939869
xfs_fsblock_t left = be64_to_cpu(block->bb_u.l.bb_leftsib);
940870
xfs_fsblock_t right = be64_to_cpu(block->bb_u.l.bb_rightsib);
871+
int rval = 0;
941872

942873
if ((lr & XFS_BTCUR_LEFTRA) && left != NULLFSBLOCK) {
943-
xfs_btree_reada_bufl(cur->bc_mp, left, 1,
944-
cur->bc_ops->buf_ops);
874+
xfs_buf_readahead(mp->m_ddev_targp, XFS_FSB_TO_DADDR(mp, left),
875+
mp->m_bsize, cur->bc_ops->buf_ops);
945876
rval++;
946877
}
947878

948879
if ((lr & XFS_BTCUR_RIGHTRA) && right != NULLFSBLOCK) {
949-
xfs_btree_reada_bufl(cur->bc_mp, right, 1,
950-
cur->bc_ops->buf_ops);
880+
xfs_buf_readahead(mp->m_ddev_targp, XFS_FSB_TO_DADDR(mp, right),
881+
mp->m_bsize, cur->bc_ops->buf_ops);
951882
rval++;
952883
}
953884

@@ -958,22 +889,25 @@ STATIC int
958889
xfs_btree_readahead_agblock(
959890
struct xfs_btree_cur *cur,
960891
int lr,
961-
struct xfs_btree_block *block)
892+
struct xfs_btree_block *block)
962893
{
963-
int rval = 0;
894+
struct xfs_mount *mp = cur->bc_mp;
895+
xfs_agnumber_t agno = cur->bc_ag.pag->pag_agno;
964896
xfs_agblock_t left = be32_to_cpu(block->bb_u.s.bb_leftsib);
965897
xfs_agblock_t right = be32_to_cpu(block->bb_u.s.bb_rightsib);
966-
898+
int rval = 0;
967899

968900
if ((lr & XFS_BTCUR_LEFTRA) && left != NULLAGBLOCK) {
969-
xfs_btree_reada_bufs(cur->bc_mp, cur->bc_ag.pag->pag_agno,
970-
left, 1, cur->bc_ops->buf_ops);
901+
xfs_buf_readahead(mp->m_ddev_targp,
902+
XFS_AGB_TO_DADDR(mp, agno, left),
903+
mp->m_bsize, cur->bc_ops->buf_ops);
971904
rval++;
972905
}
973906

974907
if ((lr & XFS_BTCUR_RIGHTRA) && right != NULLAGBLOCK) {
975-
xfs_btree_reada_bufs(cur->bc_mp, cur->bc_ag.pag->pag_agno,
976-
right, 1, cur->bc_ops->buf_ops);
908+
xfs_buf_readahead(mp->m_ddev_targp,
909+
XFS_AGB_TO_DADDR(mp, agno, right),
910+
mp->m_bsize, cur->bc_ops->buf_ops);
977911
rval++;
978912
}
979913

fs/xfs/libxfs/xfs_btree.h

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -378,42 +378,6 @@ xfs_btree_offsets(
378378
int *first, /* output: first byte offset */
379379
int *last); /* output: last byte offset */
380380

381-
/*
382-
* Get a buffer for the block, return it read in.
383-
* Long-form addressing.
384-
*/
385-
int /* error */
386-
xfs_btree_read_bufl(
387-
struct xfs_mount *mp, /* file system mount point */
388-
struct xfs_trans *tp, /* transaction pointer */
389-
xfs_fsblock_t fsbno, /* file system block number */
390-
struct xfs_buf **bpp, /* buffer for fsbno */
391-
int refval, /* ref count value for buffer */
392-
const struct xfs_buf_ops *ops);
393-
394-
/*
395-
* Read-ahead the block, don't wait for it, don't return a buffer.
396-
* Long-form addressing.
397-
*/
398-
void /* error */
399-
xfs_btree_reada_bufl(
400-
struct xfs_mount *mp, /* file system mount point */
401-
xfs_fsblock_t fsbno, /* file system block number */
402-
xfs_extlen_t count, /* count of filesystem blocks */
403-
const struct xfs_buf_ops *ops);
404-
405-
/*
406-
* Read-ahead the block, don't wait for it, don't return a buffer.
407-
* Short-form addressing.
408-
*/
409-
void /* error */
410-
xfs_btree_reada_bufs(
411-
struct xfs_mount *mp, /* file system mount point */
412-
xfs_agnumber_t agno, /* allocation group number */
413-
xfs_agblock_t agbno, /* allocation group block number */
414-
xfs_extlen_t count, /* count of filesystem blocks */
415-
const struct xfs_buf_ops *ops);
416-
417381
/*
418382
* Initialise a new btree block header
419383
*/

fs/xfs/xfs_buf.c

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ xfs_buf_submit(
6060
return __xfs_buf_submit(bp, !(bp->b_flags & XBF_ASYNC));
6161
}
6262

63+
static inline bool xfs_buf_is_uncached(struct xfs_buf *bp)
64+
{
65+
return bp->b_rhash_key == XFS_BUF_DADDR_NULL;
66+
}
67+
6368
static inline int
6469
xfs_buf_is_vmapped(
6570
struct xfs_buf *bp)
@@ -996,12 +1001,19 @@ xfs_buf_hold(
9961001
atomic_inc(&bp->b_hold);
9971002
}
9981003

999-
/*
1000-
* Release a hold on the specified buffer. If the hold count is 1, the buffer is
1001-
* placed on LRU or freed (depending on b_lru_ref).
1002-
*/
1003-
void
1004-
xfs_buf_rele(
1004+
static void
1005+
xfs_buf_rele_uncached(
1006+
struct xfs_buf *bp)
1007+
{
1008+
ASSERT(list_empty(&bp->b_lru));
1009+
if (atomic_dec_and_test(&bp->b_hold)) {
1010+
xfs_buf_ioacct_dec(bp);
1011+
xfs_buf_free(bp);
1012+
}
1013+
}
1014+
1015+
static void
1016+
xfs_buf_rele_cached(
10051017
struct xfs_buf *bp)
10061018
{
10071019
struct xfs_perag *pag = bp->b_pag;
@@ -1010,15 +1022,6 @@ xfs_buf_rele(
10101022

10111023
trace_xfs_buf_rele(bp, _RET_IP_);
10121024

1013-
if (!pag) {
1014-
ASSERT(list_empty(&bp->b_lru));
1015-
if (atomic_dec_and_test(&bp->b_hold)) {
1016-
xfs_buf_ioacct_dec(bp);
1017-
xfs_buf_free(bp);
1018-
}
1019-
return;
1020-
}
1021-
10221025
ASSERT(atomic_read(&bp->b_hold) > 0);
10231026

10241027
/*
@@ -1086,6 +1089,19 @@ xfs_buf_rele(
10861089
xfs_buf_free(bp);
10871090
}
10881091

1092+
/*
1093+
* Release a hold on the specified buffer.
1094+
*/
1095+
void
1096+
xfs_buf_rele(
1097+
struct xfs_buf *bp)
1098+
{
1099+
trace_xfs_buf_rele(bp, _RET_IP_);
1100+
if (xfs_buf_is_uncached(bp))
1101+
xfs_buf_rele_uncached(bp);
1102+
else
1103+
xfs_buf_rele_cached(bp);
1104+
}
10891105

10901106
/*
10911107
* Lock a buffer object, if it is not already locked.

fs/xfs/xfs_iwalk.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ xfs_iwalk_ichunk_ra(
100100
struct xfs_inobt_rec_incore *irec)
101101
{
102102
struct xfs_ino_geometry *igeo = M_IGEO(mp);
103+
xfs_agnumber_t agno = pag->pag_agno;
103104
xfs_agblock_t agbno;
104105
struct blk_plug plug;
105106
int i; /* inode chunk index */
@@ -112,8 +113,9 @@ xfs_iwalk_ichunk_ra(
112113

113114
imask = xfs_inobt_maskn(i, igeo->inodes_per_cluster);
114115
if (imask & ~irec->ir_free) {
115-
xfs_btree_reada_bufs(mp, pag->pag_agno, agbno,
116-
igeo->blocks_per_cluster,
116+
xfs_buf_readahead(mp->m_ddev_targp,
117+
XFS_AGB_TO_DADDR(mp, agno, agbno),
118+
igeo->blocks_per_cluster * mp->m_bsize,
117119
&xfs_inode_buf_ops);
118120
}
119121
agbno += igeo->blocks_per_cluster;

0 commit comments

Comments
 (0)