Message ID | 20190816141952.19369-8-josef@toxicpanda.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Rework reserve ticket handling | expand |
On 16.08.19 г. 17:19 ч., Josef Bacik wrote: > Now that we aren't partially filling tickets we may have some slack > space left in the space_info. We need to account for this in > may_commit_transaction, otherwise we may choose to not commit the > transaction despite it actually having enough space to satisfy our > ticket. > > Calculate the free space we have in the space_info, if any. Then check > to see if its >= the amount of bytes_needed after we've accounted for > the space being used by the delayed refs rsv. If it's not subtract it > from the bytes_needed before doing the final pinned check. If we still > don't have enough space then we are truly out of space. > > Signed-off-by: Josef Bacik <josef@toxicpanda.com> > --- > fs/btrfs/space-info.c | 19 +++++++++++++++++++ > 1 file changed, 19 insertions(+) > > diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c > index bd485be783b8..f79afdc04925 100644 > --- a/fs/btrfs/space-info.c > +++ b/fs/btrfs/space-info.c > @@ -471,12 +471,19 @@ static int may_commit_transaction(struct btrfs_fs_info *fs_info, > struct btrfs_trans_handle *trans; > u64 bytes_needed; > u64 reclaim_bytes = 0; > + u64 cur_free_bytes = 0; > > trans = (struct btrfs_trans_handle *)current->journal_info; > if (trans) > return -EAGAIN; > > spin_lock(&space_info->lock); > + cur_free_bytes = btrfs_space_info_used(space_info, true); > + if (cur_free_bytes < space_info->total_bytes) > + cur_free_bytes = space_info->total_bytes - cur_free_bytes; > + else > + cur_free_bytes = 0; > + Why don't you subtract cur_free_bytes from bytes_needed right here, giving you more chance to hit the: if (reclaim_bytes >= bytes_needed) goto commit; > if (!list_empty(&space_info->priority_tickets)) > ticket = list_first_entry(&space_info->priority_tickets, > struct reserve_ticket, list); > @@ -522,6 +529,18 @@ static int may_commit_transaction(struct btrfs_fs_info *fs_info, > goto commit; > bytes_needed -= reclaim_bytes; > > + /* > + * We don't partially fill tickets anymore, so we could have some free > + * bytes in the space_info already, just not enough to satisfy the > + * ticket. If bytes_needed is already below cur_free_bytes after taking > + * away the delayed refs and delayed rsv's then we can commit. > + * Otherwise subtract our cur_free_bytes from bytes_needed before we > + * check pinned. > + */ > + if (bytes_needed <= cur_free_bytes) > + goto commit; If you do that you won't need that check because you have already accounted for the current free space. > + bytes_needed -= cur_free_bytes; And this line will be gone as well. > + > if (__percpu_counter_compare(&space_info->total_bytes_pinned, > bytes_needed, > BTRFS_TOTAL_BYTES_PINNED_BATCH) < 0) >
diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c index bd485be783b8..f79afdc04925 100644 --- a/fs/btrfs/space-info.c +++ b/fs/btrfs/space-info.c @@ -471,12 +471,19 @@ static int may_commit_transaction(struct btrfs_fs_info *fs_info, struct btrfs_trans_handle *trans; u64 bytes_needed; u64 reclaim_bytes = 0; + u64 cur_free_bytes = 0; trans = (struct btrfs_trans_handle *)current->journal_info; if (trans) return -EAGAIN; spin_lock(&space_info->lock); + cur_free_bytes = btrfs_space_info_used(space_info, true); + if (cur_free_bytes < space_info->total_bytes) + cur_free_bytes = space_info->total_bytes - cur_free_bytes; + else + cur_free_bytes = 0; + if (!list_empty(&space_info->priority_tickets)) ticket = list_first_entry(&space_info->priority_tickets, struct reserve_ticket, list); @@ -522,6 +529,18 @@ static int may_commit_transaction(struct btrfs_fs_info *fs_info, goto commit; bytes_needed -= reclaim_bytes; + /* + * We don't partially fill tickets anymore, so we could have some free + * bytes in the space_info already, just not enough to satisfy the + * ticket. If bytes_needed is already below cur_free_bytes after taking + * away the delayed refs and delayed rsv's then we can commit. + * Otherwise subtract our cur_free_bytes from bytes_needed before we + * check pinned. + */ + if (bytes_needed <= cur_free_bytes) + goto commit; + bytes_needed -= cur_free_bytes; + if (__percpu_counter_compare(&space_info->total_bytes_pinned, bytes_needed, BTRFS_TOTAL_BYTES_PINNED_BATCH) < 0)
Now that we aren't partially filling tickets we may have some slack space left in the space_info. We need to account for this in may_commit_transaction, otherwise we may choose to not commit the transaction despite it actually having enough space to satisfy our ticket. Calculate the free space we have in the space_info, if any. Then check to see if its >= the amount of bytes_needed after we've accounted for the space being used by the delayed refs rsv. If it's not subtract it from the bytes_needed before doing the final pinned check. If we still don't have enough space then we are truly out of space. Signed-off-by: Josef Bacik <josef@toxicpanda.com> --- fs/btrfs/space-info.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)