linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nikolay Borisov <nborisov@suse.com>
To: Josef Bacik <josef@toxicpanda.com>,
	kernel-team@fb.com, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 3/5] btrfs: use add_old_bytes when updating global reserve
Date: Tue, 20 Aug 2019 18:33:26 +0300	[thread overview]
Message-ID: <0745c827-7b48-40a6-567f-10ba1b07817f@suse.com> (raw)
In-Reply-To: <20190816152019.1962-4-josef@toxicpanda.com>



On 16.08.19 г. 18:20 ч., Josef Bacik wrote:
> We have some annoying xfstests tests that will create a very small fs,
> fill it up, delete it, and repeat to make sure everything works right.
> This trips btrfs up sometimes because we may commit a transaction to
> free space, but most of the free metadata space was being reserved by
> the global reserve.  So we commit and update the global reserve, but the
> space is simply added to bytes_may_use directly, instead of trying to
> add it to existing tickets.  This results in ENOSPC when we really did
> have space.  Fix this by returning the space via
> btrfs_space_info_add_old_bytes.  The global reserve _can_ be using
> overcommitted space, but the add_old_bytes checks this and won't add the
> reservation if we're still overcommitted, so we are safe in this regard.
> 
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>

Reviewed-by: Nikolay Borisov <nborisov@suse.com> but see below for one
suggestion.

> ---
>  fs/btrfs/block-rsv.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/btrfs/block-rsv.c b/fs/btrfs/block-rsv.c
> index 18a0af20ee5a..394b8fff3a4b 100644
> --- a/fs/btrfs/block-rsv.c
> +++ b/fs/btrfs/block-rsv.c
> @@ -258,6 +258,7 @@ void btrfs_update_global_block_rsv(struct btrfs_fs_info *fs_info)
>  	struct btrfs_block_rsv *block_rsv = &fs_info->global_block_rsv;
>  	struct btrfs_space_info *sinfo = block_rsv->space_info;
>  	u64 num_bytes;
> +	u64 to_free = 0;
>  	unsigned min_items;
>  
>  	/*
> @@ -300,9 +301,7 @@ void btrfs_update_global_block_rsv(struct btrfs_fs_info *fs_info)
>  		btrfs_space_info_update_bytes_may_use(fs_info, sinfo,
>  						      num_bytes);
>  	} else if (block_rsv->reserved > block_rsv->size) {
> -		num_bytes = block_rsv->reserved - block_rsv->size;
> -		btrfs_space_info_update_bytes_may_use(fs_info, sinfo,
> -						      -num_bytes);
> +		to_free = block_rsv->reserved - block_rsv->size;

nit: Since you hold  sinfo->lock here you could just call the try to
wakeup function, you already have the bytes_may_use update call, that
will also make the to_free variable private to this 'else if' branch.
The only reason to suggest is because further down the sinfo->lock is
released only to be acquired milliseconds later if to_free != 0

>  		block_rsv->reserved = block_rsv->size;
>  	}
>  
> @@ -313,6 +312,9 @@ void btrfs_update_global_block_rsv(struct btrfs_fs_info *fs_info)
>  
>  	spin_unlock(&block_rsv->lock);
>  	spin_unlock(&sinfo->lock);
> +
> +	if (to_free)
> +		btrfs_space_info_add_old_bytes(fs_info, sinfo, to_free);
>  }
>  
>  void btrfs_init_global_block_rsv(struct btrfs_fs_info *fs_info)
> 

  reply	other threads:[~2019-08-20 15:33 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-16 15:20 [PATCH 0/5] Fix global reserve size and can overcommit Josef Bacik
2019-08-16 15:20 ` [PATCH 1/5] btrfs: change the minimum global reserve size Josef Bacik
2019-08-20 13:45   ` Nikolay Borisov
2019-08-20 19:12     ` Josef Bacik
2019-08-16 15:20 ` [PATCH 2/5] btrfs: always reserve our entire size for the global reserve Josef Bacik
2019-08-20 14:23   ` Nikolay Borisov
2019-08-20 19:13     ` Josef Bacik
2019-08-16 15:20 ` [PATCH 3/5] btrfs: use add_old_bytes when updating " Josef Bacik
2019-08-20 15:33   ` Nikolay Borisov [this message]
2019-08-16 15:20 ` [PATCH 4/5] btrfs: do not account global reserve in can_overcommit Josef Bacik
2019-08-21  6:51   ` Nikolay Borisov
2019-08-21 15:30   ` Vladimir Panteleev
2019-08-16 15:20 ` [PATCH 5/5] btrfs: add enospc debug messages for ticket failure Josef Bacik
2019-08-21  6:39   ` Nikolay Borisov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0745c827-7b48-40a6-567f-10ba1b07817f@suse.com \
    --to=nborisov@suse.com \
    --cc=josef@toxicpanda.com \
    --cc=kernel-team@fb.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).