[PATCH 10/10] xfbtree: let the buffer cache flush dirty buffers to the xfile

Darrick J. Wong
2023-12-31T22:17:10Z

As a performance optimization, when we're committing xfbtree updates,
let the buffer cache flush the dirty buffers to disk when it's ready
instead of writing everything at every transaction commit. This is a
bit sketchy but it's an ephemeral tree so we can play fast and loose.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
libxfs/xfbtree.c | 17 +++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/libxfs/xfbtree.c b/libxfs/xfbtree.c
index 3cca7b5494c..c4dd706f4f7 100644
--- a/libxfs/xfbtree.c
+++ b/libxfs/xfbtree.c
@@ -699,7 +699,6 @@ xfbtree_trans_commit(
struct xfbtree *xfbt,
struct xfs_trans *tp)
{
- LIST_HEAD(buffer_list);
struct xfs_log_item *lip, *n;
bool corrupt = false;
bool tp_dirty = false;
@@ -733,12 +732,16 @@ xfbtree_trans_commit(
* If the buffer fails verification, log the failure
* but continue walking the transaction items so that
* we remove all ephemeral btree buffers.
+ *
+ * Since the userspace buffer cache supports marking
+ * buffers dirty and flushing them later, use this to
+ * reduce the number of writes to the xfile.
*/
if (fa) {
corrupt = true;
xfs_verifier_error(bp, -EFSCORRUPTED, fa);
} else {
- xfs_buf_delwri_queue_here(bp, &buffer_list);
+ libxfs_buf_mark_dirty(bp);
}
}

@@ -752,15 +755,9 @@ xfbtree_trans_commit(
tp->t_flags = (tp->t_flags & ~XFS_TRANS_DIRTY) |
(tp_dirty ? XFS_TRANS_DIRTY : 0);

- if (corrupt) {
- xfs_buf_delwri_cancel(&buffer_list);
+ if (corrupt)
return -EFSCORRUPTED;
- }
-
- if (list_empty(&buffer_list))
- return 0;
-
- return xfs_buf_delwri_submit(&buffer_list);
+ return 0;
}

/*