summaryrefslogtreecommitdiffstats
path: root/fs/btrfs/space-info.c
diff options
context:
space:
mode:
authorJosef Bacik <josef@toxicpanda.com>2020-07-21 10:22:27 -0400
committerDavid Sterba <dsterba@suse.com>2020-10-07 12:06:53 +0200
commit0532a6f8b6ce64ced0ffcca0a2ab5d66a8eb9a6d (patch)
tree7de169a4cca23d5d319da782657b2db51583a1f4 /fs/btrfs/space-info.c
parent1004f6860f8c64f8d959051d6299981c09046cbe (diff)
btrfs: serialize data reservations if we are flushing
Nikolay reported a problem where generic/371 would fail sometimes with a slow drive. The gist of the test is that we fallocate a file in parallel with a pwrite of a different file. These two files combined are smaller than the file system, but sometimes the pwrite would ENOSPC. A fair bit of investigation uncovered the fact that the fallocate workload was racing in and grabbing the free space that the pwrite workload was trying to free up so it could make its own reservation. After a few loops of this eventually the pwrite workload would error out with an ENOSPC. We've had the same problem with metadata as well, and we serialized all metadata allocations to satisfy this problem. This wasn't usually a problem with data because data reservations are more straightforward, but obviously could still happen. Fix this by not allowing reservations to occur if there are any pending tickets waiting to be satisfied on the space info. Reviewed-by: Nikolay Borisov <nborisov@suse.com> Tested-by: Nikolay Borisov <nborisov@suse.com> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Signed-off-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'fs/btrfs/space-info.c')
-rw-r--r--fs/btrfs/space-info.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c
index 9c118af363de..fd9eff51e5b4 100644
--- a/fs/btrfs/space-info.c
+++ b/fs/btrfs/space-info.c
@@ -1399,13 +1399,16 @@ int btrfs_reserve_data_bytes(struct btrfs_fs_info *fs_info, u64 bytes,
struct btrfs_space_info *data_sinfo = fs_info->data_sinfo;
u64 used;
int ret = -ENOSPC;
+ bool pending_tickets;
ASSERT(!current->journal_info || flush != BTRFS_RESERVE_FLUSH_DATA);
spin_lock(&data_sinfo->lock);
used = btrfs_space_info_used(data_sinfo, true);
+ pending_tickets = !list_empty(&data_sinfo->tickets) ||
+ !list_empty(&data_sinfo->priority_tickets);
- if (used + bytes > data_sinfo->total_bytes) {
+ if (pending_tickets || used + bytes > data_sinfo->total_bytes) {
struct reserve_ticket ticket;
init_waitqueue_head(&ticket.wait);