Skip to content

btrfs: fix races between clone, fallocate and memory mapped writes

[email protected] linux-btrfs 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest2 patches 3 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2btrfs: fix race between cloning and memory mapped writes leading to deadlockfs/btrfs/extent_io.c fs/btrfs/file.c fs/btrfs/inode.c +3 more+67 -230 replies
2/2btrfs: fix race between fallocate and memory mapped writes leading to deadlockfs/btrfs/file.c+4 -320 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/2] btrfs: fix races between clone, fallocate and memory mapped writes

From: Filipe Manana <[email protected]>

For a very long time there's been a race between clone/dedupe and memory mapped writes as well as between fallocate and memory mapped writes. For both cases the consequence of the race is that it can makes us deadlock when we are low on available metadata space, since clone/dedupe/fallocate start a transaction while holding file ranges locked, and allocating the metadata can result in the async reclaim task to flush the inodes being used by clone/dedupe/fallocate, if a memory mapped write happened before we locked the file ranges.

For the dedupe case, Josef's recent fix [1] ("btrfs: fix race between dedupe and mmap") happens to fix this deadlock problem as well. The first patch in this patchset fixes the issue for both clone and dedupe, as it's centered on the shared extent locking function, and it is independent of Josef's fix (works both with and without that fix).

[1] https://lore.kernel.org/linux-btrfs/afdc2109f83fff1a925d7a66a6a047d4400721d4.1607724668.git.josef@toxicpanda.com/

Filipe Manana (2):
btrfs: fix race between cloning and memory mapped writes leading to
deadlock
btrfs: fix race between fallocate and memory mapped writes leading to
deadlock

 fs/btrfs/extent_io.c    |  2 +-
 fs/btrfs/file.c         | 38 +++++---------------------------
 fs/btrfs/inode.c        |  4 ++--
 fs/btrfs/ordered-data.c | 48 ++++++++++++++++++++++++++++++++---------
 fs/btrfs/ordered-data.h |  6 +++---
 fs/btrfs/reflink.c      | 28 ++++++++++++++++++------
 6 files changed, 71 insertions(+), 55 deletions(-)
Signature · 1 line
2.28.0