]> www.infradead.org Git - users/dwmw2/linux.git/commit
btrfs: avoid races when tracking progress for extent map shrinking
authorFilipe Manana <fdmanana@suse.com>
Mon, 8 Jul 2024 14:42:45 +0000 (15:42 +0100)
committerDavid Sterba <dsterba@suse.com>
Thu, 11 Jul 2024 14:50:54 +0000 (16:50 +0200)
commit4484940514295b75389f94787f8e179ba6255353
tree68de671f64cdfaa2309c83e3d76e358acaa481b9
parentb3ebb9b7e92a928344a7a2c1f8514474bfa113cf
btrfs: avoid races when tracking progress for extent map shrinking

We store the progress (root and inode numbers) of the extent map shrinker
in fs_info without any synchronization but we can have multiple tasks
calling into the shrinker during memory allocations when there's enough
memory pressure for example.

This can result in a task A reading fs_info->extent_map_shrinker_last_ino
after another task B updates it, and task A reading
fs_info->extent_map_shrinker_last_root before task B updates it, making
task A see an odd state that isn't necessarily harmful but may make it
skip certain inode ranges or do more work than necessary by going over
the same inodes again. These unprotected accesses would also trigger
warnings from tools like KCSAN.

So add a lock to protect access to these progress fields.

Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/disk-io.c
fs/btrfs/extent_map.c
fs/btrfs/fs.h
include/trace/events/btrfs.h