Skip to content

reduce reflink src inode lock contention

Boris Burkov linux-btrfs 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest3 patches 3 repliesIn review
  2. v23 patches 2 repliesSuperseded

Changes in v3 from the cover letter

- use btrfs_wait_ordered_range() instead of the misguided custom walk.
- add a helper to unify range computations.

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3btrfs: pre-flush reflink source before taking inode locksfs/btrfs/reflink.c+24 -41 reply
2/3btrfs: skip unlocked reflink source flush if the inode has writersfs/btrfs/reflink.c+10 -41 reply
3/3btrfs: downgrade the reflink source inode lock for tree walkingfs/btrfs/btrfs_inode.h fs/btrfs/direct-io.c fs/btrfs/reflink.c+28 -21 reply

Reviews trailers per patch

All 3 patches have a Reviewed-by or Acked-by.

PatchFilipe Manana
1/3R-b
2/3R-b
3/3R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v3 thread

Cover letter [PATCH v3 0/3] reduce reflink src inode lock contention

We currently take the src and dst inode i_rwsem exclusive for the entirety of a reflink which includes writing back all of both files and walking all the src extents and duplicating them to dst. This results in contention on those locks which I think can be reduced.

The basic strategy is:
1. try to do obvious easy src writeback outside the lock.
2. downgrade the src lock to shared where it is safe.

Changelog:
v3:
- use btrfs_wait_ordered_range() instead of the misguided custom walk.
- add a helper to unify range computations.
v2:
- introduce unlocked wb pre-flush instead of a downgrade of src inode lock for the whole reflink.
- add the "has writers" pessimization.
- still downgrade after done with wb.

Boris Burkov (3):
btrfs: pre-flush reflink source before taking inode locks
btrfs: skip unlocked reflink source flush if the inode has writers
btrfs: downgrade the reflink source inode lock for tree walking

 fs/btrfs/btrfs_inode.h |  6 +++++
 fs/btrfs/direct-io.c   |  7 ++++++
 fs/btrfs/reflink.c     | 51 +++++++++++++++++++++++++++++++++++++-----
 3 files changed, 58 insertions(+), 6 deletions(-)
Signature · 1 line
2.55.0