Skip to content

Commit ef1317a

Browse files
josefbacikkdave
authored andcommitted
btrfs: do not allow reservations if we have pending tickets
If we already have tickets on the list we don't want to steal their reservations. This is a preparation patch for upcoming changes, technically this shouldn't happen today because of the way we add bytes to tickets before adding them to the space_info in most cases. This does not change the FIFO nature of reserve tickets, it simply allows us to enforce it in a different way. Previously it was enforced because any new space would be added to the first ticket on the list, which would result in new reservations getting a reserve ticket. This replaces that mechanism by simply checking to see if we have outstanding reserve tickets and skipping straight to adding a ticket for our reservation. Reviewed-by: Nikolay Borisov <[email protected]> Signed-off-by: Josef Bacik <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent e182163 commit ef1317a

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

fs/btrfs/space-info.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -993,21 +993,25 @@ static int __reserve_metadata_bytes(struct btrfs_fs_info *fs_info,
993993
struct reserve_ticket ticket;
994994
u64 used;
995995
int ret = 0;
996+
bool pending_tickets;
996997

997998
ASSERT(orig_bytes);
998999
ASSERT(!current->journal_info || flush != BTRFS_RESERVE_FLUSH_ALL);
9991000

10001001
spin_lock(&space_info->lock);
10011002
ret = -ENOSPC;
10021003
used = btrfs_space_info_used(space_info, true);
1004+
pending_tickets = !list_empty(&space_info->tickets) ||
1005+
!list_empty(&space_info->priority_tickets);
10031006

10041007
/*
10051008
* Carry on if we have enough space (short-circuit) OR call
10061009
* can_overcommit() to ensure we can overcommit to continue.
10071010
*/
1008-
if ((used + orig_bytes <= space_info->total_bytes) ||
1009-
can_overcommit(fs_info, space_info, orig_bytes, flush,
1010-
system_chunk)) {
1011+
if (!pending_tickets &&
1012+
((used + orig_bytes <= space_info->total_bytes) ||
1013+
can_overcommit(fs_info, space_info, orig_bytes, flush,
1014+
system_chunk))) {
10111015
btrfs_space_info_update_bytes_may_use(fs_info, space_info,
10121016
orig_bytes);
10131017
trace_btrfs_space_reservation(fs_info, "space_info",

0 commit comments

Comments
 (0)