Skip to content

Commit d40c286

Browse files
hsiangkaoChandan Babu R
authored andcommitted
xfs: avoid redundant AGFL buffer invalidation
Currently AGFL blocks can be filled from the following three sources: - allocbt free blocks, as in xfs_allocbt_free_block(); - rmapbt free blocks, as in xfs_rmapbt_free_block(); - refilled from freespace btrees, as in xfs_alloc_fix_freelist(). Originally, allocbt free blocks would be marked as stale only when they put back in the general free space pool as Dave mentioned on IRC, "we don't stale AGF metadata btree blocks when they are returned to the AGFL .. but once they get put back in the general free space pool, we have to make sure the buffers are marked stale as the next user of those blocks might be user data...." However, after commit ca250b1 ("xfs: invalidate allocbt blocks moved to the free list") and commit edfd9dd ("xfs: move buffer invalidation to xfs_btree_free_block"), even allocbt / bmapbt free blocks will be invalidated immediately since they may fail to pass V5 format validation on writeback even writeback to free space would be safe. IOWs, IMHO currently there is actually no difference of free blocks between AGFL freespace pool and the general free space pool. So let's avoid extra redundant AGFL buffer invalidation, since otherwise we're currently facing unnecessary xfs_log_force() due to xfs_trans_binval() again on buffers already marked as stale before as below: [ 333.507469] Call Trace: [ 333.507862] xfs_buf_find+0x371/0x6a0 <- xfs_buf_lock [ 333.508451] xfs_buf_get_map+0x3f/0x230 [ 333.509062] xfs_trans_get_buf_map+0x11a/0x280 [ 333.509751] xfs_free_agfl_block+0xa1/0xd0 [ 333.510403] xfs_agfl_free_finish_item+0x16e/0x1d0 [ 333.511157] xfs_defer_finish_noroll+0x1ef/0x5c0 [ 333.511871] xfs_defer_finish+0xc/0xa0 [ 333.512471] xfs_itruncate_extents_flags+0x18a/0x5e0 [ 333.513253] xfs_inactive_truncate+0xb8/0x130 [ 333.513930] xfs_inactive+0x223/0x270 xfs_log_force() will take tens of milliseconds with AGF buffer locked. It becomes an unnecessary long latency especially on our PMEM devices with FSDAX enabled and fsops like xfs_reflink_find_shared() at the same time are stuck due to the same AGF lock. Removing the double invalidation on the AGFL blocks does not make this issue go away, but this patch fixes for our workloads in reality and it should also work by the code analysis. Note that I'm not sure I need to remove another redundant one in xfs_alloc_ag_vextent_small() since it's unrelated to our workloads. Also fstests are passed with this patch. Signed-off-by: Gao Xiang <[email protected]> Reviewed-by: Dave Chinner <[email protected]> Signed-off-by: Chandan Babu R <[email protected]>
1 parent 22a40d1 commit d40c286

File tree

3 files changed

+7
-31
lines changed

3 files changed

+7
-31
lines changed

fs/xfs/libxfs/xfs_alloc.c

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1932,7 +1932,7 @@ xfs_alloc_ag_vextent_size(
19321932
/*
19331933
* Free the extent starting at agno/bno for length.
19341934
*/
1935-
STATIC int
1935+
int
19361936
xfs_free_ag_extent(
19371937
struct xfs_trans *tp,
19381938
struct xfs_buf *agbp,
@@ -2422,32 +2422,6 @@ xfs_alloc_space_available(
24222422
return true;
24232423
}
24242424

2425-
int
2426-
xfs_free_agfl_block(
2427-
struct xfs_trans *tp,
2428-
xfs_agnumber_t agno,
2429-
xfs_agblock_t agbno,
2430-
struct xfs_buf *agbp,
2431-
struct xfs_owner_info *oinfo)
2432-
{
2433-
int error;
2434-
struct xfs_buf *bp;
2435-
2436-
error = xfs_free_ag_extent(tp, agbp, agno, agbno, 1, oinfo,
2437-
XFS_AG_RESV_AGFL);
2438-
if (error)
2439-
return error;
2440-
2441-
error = xfs_trans_get_buf(tp, tp->t_mountp->m_ddev_targp,
2442-
XFS_AGB_TO_DADDR(tp->t_mountp, agno, agbno),
2443-
tp->t_mountp->m_bsize, 0, &bp);
2444-
if (error)
2445-
return error;
2446-
xfs_trans_binval(tp, bp);
2447-
2448-
return 0;
2449-
}
2450-
24512425
/*
24522426
* Check the agfl fields of the agf for inconsistency or corruption.
24532427
*

fs/xfs/libxfs/xfs_alloc.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ int xfs_alloc_get_freelist(struct xfs_perag *pag, struct xfs_trans *tp,
8080
int xfs_alloc_put_freelist(struct xfs_perag *pag, struct xfs_trans *tp,
8181
struct xfs_buf *agfbp, struct xfs_buf *agflbp,
8282
xfs_agblock_t bno, int btreeblk);
83+
int xfs_free_ag_extent(struct xfs_trans *tp, struct xfs_buf *agbp,
84+
xfs_agnumber_t agno, xfs_agblock_t bno,
85+
xfs_extlen_t len, const struct xfs_owner_info *oinfo,
86+
enum xfs_ag_resv_type type);
8387

8488
/*
8589
* Compute and fill in value of m_alloc_maxlevels.
@@ -194,8 +198,6 @@ int xfs_alloc_read_agf(struct xfs_perag *pag, struct xfs_trans *tp, int flags,
194198
struct xfs_buf **agfbpp);
195199
int xfs_alloc_read_agfl(struct xfs_perag *pag, struct xfs_trans *tp,
196200
struct xfs_buf **bpp);
197-
int xfs_free_agfl_block(struct xfs_trans *, xfs_agnumber_t, xfs_agblock_t,
198-
struct xfs_buf *, struct xfs_owner_info *);
199201
int xfs_alloc_fix_freelist(struct xfs_alloc_arg *args, uint32_t alloc_flags);
200202
int xfs_free_extent_fix_freelist(struct xfs_trans *tp, struct xfs_perag *pag,
201203
struct xfs_buf **agbp);

fs/xfs/xfs_extfree_item.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,8 +547,8 @@ xfs_agfl_free_finish_item(
547547

548548
error = xfs_alloc_read_agf(xefi->xefi_pag, tp, 0, &agbp);
549549
if (!error)
550-
error = xfs_free_agfl_block(tp, xefi->xefi_pag->pag_agno,
551-
agbno, agbp, &oinfo);
550+
error = xfs_free_ag_extent(tp, agbp, xefi->xefi_pag->pag_agno,
551+
agbno, 1, &oinfo, XFS_AG_RESV_AGFL);
552552

553553
next_extent = efdp->efd_next_extent;
554554
ASSERT(next_extent < efdp->efd_format.efd_nextents);

0 commit comments

Comments
 (0)