Commit 9cd8dcdc authored by Josef Bacik's avatar Josef Bacik Committed by David Sterba

btrfs: check for priority ticket granting before flushing

Since we're dropping locks before we enter the priority flushing loops
we could have had our ticket granted before we got the space_info->lock.
So add this check to avoid doing some extra flushing in the priority
flushing cases.

The case in priority_reclaim_metadata_space is an optimization.  Think
we came in to reserve, we didn't have the space, we added our ticket to
the list.  But at the same time somebody was waiting on the space_info
lock to add space and do btrfs_try_granting_ticket(), so we drop the
lock, get satisfied, come in to do our loop, and we have been
satisfied.

This is the priority reclaim path, so to_reclaim could be !0 still
because we may have only satisfied the priority tickets and still left
non priority tickets on the list.  We would then have to_reclaim but
->bytes == 0.
Reviewed-by: default avatarNikolay Borisov <nborisov@suse.com>
Signed-off-by: default avatarJosef Bacik <josef@toxicpanda.com>
[ add note about the optimization ]
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 9f35f76d
...@@ -1264,7 +1264,13 @@ static void priority_reclaim_metadata_space(struct btrfs_fs_info *fs_info, ...@@ -1264,7 +1264,13 @@ static void priority_reclaim_metadata_space(struct btrfs_fs_info *fs_info,
spin_lock(&space_info->lock); spin_lock(&space_info->lock);
to_reclaim = btrfs_calc_reclaim_metadata_size(fs_info, space_info); to_reclaim = btrfs_calc_reclaim_metadata_size(fs_info, space_info);
if (!to_reclaim) { /*
* This is the priority reclaim path, so to_reclaim could be >0 still
* because we may have only satisified the priority tickets and still
* left non priority tickets on the list. We would then have
* to_reclaim but ->bytes == 0.
*/
if (ticket->bytes == 0) {
spin_unlock(&space_info->lock); spin_unlock(&space_info->lock);
return; return;
} }
...@@ -1297,6 +1303,13 @@ static void priority_reclaim_data_space(struct btrfs_fs_info *fs_info, ...@@ -1297,6 +1303,13 @@ static void priority_reclaim_data_space(struct btrfs_fs_info *fs_info,
struct reserve_ticket *ticket) struct reserve_ticket *ticket)
{ {
spin_lock(&space_info->lock); spin_lock(&space_info->lock);
/* We could have been granted before we got here. */
if (ticket->bytes == 0) {
spin_unlock(&space_info->lock);
return;
}
while (!space_info->full) { while (!space_info->full) {
spin_unlock(&space_info->lock); spin_unlock(&space_info->lock);
flush_space(fs_info, space_info, U64_MAX, ALLOC_CHUNK_FORCE, false); flush_space(fs_info, space_info, U64_MAX, ALLOC_CHUNK_FORCE, false);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment