btrfs: skip COW for written extent buffers
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v2 Latest2 patches 0 repliesNew
- v12 patches 1 replySuperseded
Changes in v2 from the cover letter
- Patch 1: rename qgroup_commit_fs_roots()'s ret to nr since it holds the radix lookup count and is never returned. Renamed the inner loop's ret2 to ret accordingly.
- Patch 1: lift the index advance out of the inner for loop and compute it once from gang[nr - 1] after the loop completes, since only the final value is consumed by the next radix lookup.
Patches in v2 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/2 | btrfs: don't finalize fs roots during qgroup snapshot accountingfs/ | +75 | 0 replies | |
| 2/2 | btrfs: skip COW for written extent buffers allocated in current transactionfs/ fs/ fs/ | +67 | 0 replies |
Reviews trailers per patch
1 of 2 patches has a Reviewed-by or Acked-by.
| Patch | Filipe Manana | Sun YangKai |
|---|---|---|
| 1/2 | ||
| 2/2 | R-b | R-b |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [PATCH v2 0/2] btrfs: skip COW for written extent buffers
This series adds an optimization to skip redundant COW operations on extent buffers that were allocated in the current transaction but already written back to disk due to memory pressure.
When writeback sets BTRFS_HEADER_FLAG_WRITTEN on a buffer, subsequent btrfs_search_slot() calls re-COW it unnecessarily -- the committed superblock doesn't reference blocks from the uncommitted transaction, so overwriting in place is crash-safe. This COW amplification can exhaust block reservations and degrade throughput under memory pressure.
The first patch fixes a latent issue in qgroup snapshot accounting:qgroup_account_snapshot() calls commit_fs_roots() mid-transaction to persist root items, but commit_fs_roots() also clears BTRFS_ROOT_FORCE_COW as a finalization step. This leaves snapshotted roots in an incorrect state where blocks are shared via btrfs_copy_root() but FORCE_COW no longer reflects that. This is currently harmless because WRITTEN buffers are always COW'd, but becomes a corruption vector once the skip-COW optimization relies on FORCE_COW to protect shared blocks. The fix extracts the root item persistence into qgroup_commit_fs_roots(), which does only what qgroup accounting needs without the finalization side effects.
The second patch adds the skip-COW optimization itself, and was previously sent and reviewed but reverted due to the qgroup interaction fixed in patch 1. The code is unchanged from the reviewed version. When should_cow_block() encounters a WRITTEN buffer from the current transaction, it re-dirties the buffer and overwrites in place instead of allocating a new block. FORCE_COW, EXTENT_BUFFER_WRITEBACK, log trees, zoned devices, and relocation are all excluded.
Changes since v1:
- Patch 1: rename qgroup_commit_fs_roots()'s ret to nr since it holds the radix lookup count and is never returned. Renamed the inner loop's ret2 to ret accordingly.
- Patch 1: lift the index advance out of the inner for loop and compute it once from gang[nr - 1] after the loop completes, since only the final value is consumed by the next radix lookup.
Leo Martins (2):
btrfs: don't finalize fs roots during qgroup snapshot accounting
btrfs: skip COW for written extent buffers allocated in current
transaction
fs/btrfs/ctree.c | 83 +++++++++++++++++++++++++------- fs/btrfs/disk-io.c | 2 +- fs/btrfs/extent_io.c | 4 -- fs/btrfs/transaction.c | 105 +++++++++++++++++++++++++++++------------ 4 files changed, 142 insertions(+), 52 deletions(-)
Signature · 1 line
2.53.0-Meta