diff options
| author | Boris Burkov <boris@bur.io> | 2026-09-15 10:58:33 -0700 |
|---|---|---|
| committer | David Sterba <dsterba@suse.com> | 2026-10-12 19:16:21 +0200 |
| commit | cf02c310d018c7e5363b80dfd68ffdf159f3c914 (patch) | |
| tree | 20748ab466a68a582d02b37e4d33874488047d54 /tools/perf/scripts/python | |
| parent | e0c9d01770ef56792fbb2947128e5f43f7d49c61 (diff) | |
| download | linux-cf02c310d018c7e5363b80dfd68ffdf159f3c914.tar.gz linux-cf02c310d018c7e5363b80dfd68ffdf159f3c914.zip | |
btrfs: downgrade the reflink source inode lock for tree walking
When doing a reflink, we are not writing to the src inode or modifying
it in any way, so it is counter-intuitive to have to lock it
exclusively. This has the cost of blocking other shared lock users of
the src file for the duration of any new writeback since the optimistic
pre-flush and all the actual reflinking. So we would like to downgrade
the lock to shared as much as possible.
There are two important gotchas to do with direct io that must be
addressed to make this idea work.
The first gotcha is that dio writes that come in under EOF try to take
inode->i_rwsem shared, which would result in messed up views of the
extents in the reflinked file. Therefore, add "being used as a reflink
src" as another inode flag exception for the dio write shared tests that
already exist to check for other dangerous conditions. In order to
ensure that this flag is visible to the dio writer, reflink must first
take i_rwsem exclusive, then set the flag, then downgrade to shared.
The second is that dio reads increment inode->i_dio_count which blocks
inode_dio_wait() in __generic_remap_file_range_prep(). Therefore, we
must remain exclusive to dio reads through finishing the prep or risk
starving the clone on a stream of dio readers. There is still O(extents)
work in btrfs_clone() which can be done without holding the lock
exclusive, so we should downgrade to shared and admit dio readers (and
other shared lock users like lseek) after we are finished with
inode_dio_wait().
By running concurrent clones and lseeks or dio reads on a src file with
32k extents on a vm, I can demonstrate 100ms+ stalls on the readers
without this patch and they go away entirely with the patch.
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Boris Burkov <boris@bur.io>
Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'tools/perf/scripts/python')
0 files changed, 0 insertions, 0 deletions
