From: Qu WenRuo <wqu@suse.com>
To: "linux-btrfs@vger.kernel.org" <linux-btrfs@vger.kernel.org>,
David Sterba <dsterba@suse.cz>
Subject: Re: [PATCH] btrfs: statfs: Don't reset f_bavail if we're over committing metadata space
Date: Wed, 15 Jan 2020 11:40:10 +0000 [thread overview]
Message-ID: <2a588e86-5894-fdc7-6e16-a106937f37e7@suse.com> (raw)
In-Reply-To: <20200115034128.32889-1-wqu@suse.com>
[-- Attachment #1.1: Type: text/plain, Size: 3571 bytes --]
BTW, this patch is for v5.5-rc release.
As some GUI programs, e.g nemo from cinnamon, would check statfs result
before doing any write operation, thus could cause false early ENOSPC error.
Thanks,
Qu
On 2020/1/15 上午11:41, Qu Wenruo wrote:
> [BUG]
> When there are a lot of metadata space reserved, e.g. after balancing a
> data block with many extents, vanilla df would report 0 available space.
>
> [CAUSE]
> btrfs_statfs() would report 0 available space if its metadata space is
> exhausted.
> And the calculation is based on currently reserved space vs on-disk
> available space, with a small headroom as buffer.
> When there is not enough headroom, btrfs_statfs() will report 0
> available space.
>
> The problem is, since commit ef1317a1b9a3 ("btrfs: do not allow
> reservations if we have pending tickets"), we allow btrfs to over commit
> metadata space, as long as we have enough space to allocate new metadata
> chunks.
>
> This makes old calculation unreliable and report false 0 available space.
>
> [FIX]
> Don't do such naive check anymore for btrfs_statfs().
> Also remove the comment about "0 available space when metadata is
> exhausted".
>
> Please note that, this is a just a quick fix. There are still a lot of
> things to be improved.
>
> Fixes: ef1317a1b9a3 ("btrfs: do not allow reservations if we have pending tickets")
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> ---
> fs/btrfs/super.c | 21 ---------------------
> 1 file changed, 21 deletions(-)
>
> diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
> index f452a94abdc3..ca1a26b3e884 100644
> --- a/fs/btrfs/super.c
> +++ b/fs/btrfs/super.c
> @@ -2018,8 +2018,6 @@ static inline int btrfs_calc_avail_data_space(struct btrfs_fs_info *fs_info,
> * algorithm that respects the device sizes and order of allocations. This is
> * a close approximation of the actual use but there are other factors that may
> * change the result (like a new metadata chunk).
> - *
> - * If metadata is exhausted, f_bavail will be 0.
> */
> static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf)
> {
> @@ -2034,7 +2032,6 @@ static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf)
> unsigned factor = 1;
> struct btrfs_block_rsv *block_rsv = &fs_info->global_block_rsv;
> int ret;
> - u64 thresh = 0;
> int mixed = 0;
>
> rcu_read_lock();
> @@ -2089,24 +2086,6 @@ static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf)
> buf->f_bavail += div_u64(total_free_data, factor);
> buf->f_bavail = buf->f_bavail >> bits;
>
> - /*
> - * We calculate the remaining metadata space minus global reserve. If
> - * this is (supposedly) smaller than zero, there's no space. But this
> - * does not hold in practice, the exhausted state happens where's still
> - * some positive delta. So we apply some guesswork and compare the
> - * delta to a 4M threshold. (Practically observed delta was ~2M.)
> - *
> - * We probably cannot calculate the exact threshold value because this
> - * depends on the internal reservations requested by various
> - * operations, so some operations that consume a few metadata will
> - * succeed even if the Avail is zero. But this is better than the other
> - * way around.
> - */
> - thresh = SZ_4M;
> -
> - if (!mixed && total_free_meta - thresh < block_rsv->size)
> - buf->f_bavail = 0;
> -
> buf->f_type = BTRFS_SUPER_MAGIC;
> buf->f_bsize = dentry->d_sb->s_blocksize;
> buf->f_namelen = BTRFS_NAME_LEN;
>
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2020-01-15 11:51 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-15 3:41 [PATCH] btrfs: statfs: Don't reset f_bavail if we're over committing metadata space Qu Wenruo
2020-01-15 11:40 ` Qu WenRuo [this message]
2020-01-16 14:29 ` David Sterba
2020-01-17 0:54 ` Qu Wenruo
2020-01-17 1:32 ` Qu Wenruo
2020-01-17 14:10 ` David Sterba
2020-01-17 14:22 ` Qu Wenruo
2020-01-29 15:38 ` David Sterba
2020-01-17 14:02 ` David Sterba
2020-01-17 14:16 ` Qu Wenruo
2020-01-29 16:01 ` David Sterba
2020-01-31 2:23 ` Zygo Blaxell
2020-01-30 21:05 ` Josef Bacik
2020-01-30 23:14 ` Anand Jain
2020-01-31 0:35 ` Qu Wenruo
2020-01-31 11:58 ` Qu Wenruo
2020-01-31 12:34 ` David Sterba
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=2a588e86-5894-fdc7-6e16-a106937f37e7@suse.com \
--to=wqu@suse.com \
--cc=dsterba@suse.cz \
--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).