Linux-BTRFS Archive on lore.kernel.org
 help / color / Atom feed
From: David Sterba <dsterba@suse.cz>
To: Qu Wenruo <wqu@suse.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH] btrfs-progs: Fix false ENOSPC alert by tracking used space correctly
Date: Fri, 14 Jun 2019 17:57:35 +0200
Message-ID: <20190614155735.GB19057@twin.jikos.cz> (raw)
In-Reply-To: <20190524233243.4780-1-wqu@suse.com>

On Sat, May 25, 2019 at 07:32:43AM +0800, Qu Wenruo wrote:
> [BUG]
> There is a bug report of unexpected ENOSPC from btrfs-convert.
> https://github.com/kdave/btrfs-progs/issues/123#
> 
> After some debug, even when we have enough unallocated space, we still
> hit ENOSPC at btrfs_reserve_extent().
> 
> [CAUSE]
> Btrfs-progs relies on chunk preallocator to make enough space for
> data/metadata.
> 
> However after the introduction of delayed-ref, it's no longer reliable
> to relie on btrfs_space_info::bytes_used and
> btrfs_space_info::bytes_pinned to calculate used metadata space.
> 
> For a running transaction with a lot of allocated tree blocks,
> btrfs_space_info::bytes_used stays its original value, and will only be
> updated when running delayed ref.
> 
> This makes btrfs-progs chunk preallocator completely useless. And for
> btrfs-convert/mkfs.btrfs --rootdir, if we're going to have enough
> metadata to fill a metadata block group in one transaction, we will hit
> ENOSPC no matter whether we have enough unallocated space.
> 
> [FIX]
> This patch will introduce btrfs_space_info::bytes_reserved to trace how
> many space we have reserved but not yet committed to extent tree.
> 
> To support this change, this commit also introduces the following
> modification:
> - More comment on btrfs_space_info::bytes_*
>   To make code a little easier to read
> 
> - Export update_space_info() to preallocate empty data/metadata space
>   info for mkfs.
>   For mkfs, we only have a temporary fs image with SYSTEM chunk only.
>   Export update_space_info() so that we can preallocate empty
>   data/metadata space info before we start a transaction.
> 
> - Proper btrfs_space_info::bytes_reserved update
>   The timing is the as kernel (except we don't need to update
>   bytes_reserved for data extents)
>   * Increase bytes_reserved when call alloc_reserved_tree_block()
>   * Decrease bytes_reserved when running delayed refs
>     With the help of head->must_insert_reserved to determine whether we
>     need to decrease.
> 
> Issue: #123
> Signed-off-by: Qu Wenruo <wqu@suse.com>

Added to devel, thanks.

  reply index

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-24 23:32 Qu Wenruo
2019-06-14 15:57 ` David Sterba [this message]
2019-06-19  6:32 ` Nikolay Borisov
2019-06-19  6:49   ` Qu Wenruo

Reply instructions:

You may reply publically 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=20190614155735.GB19057@twin.jikos.cz \
    --to=dsterba@suse.cz \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=wqu@suse.com \
    /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

Linux-BTRFS Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-btrfs/0 linux-btrfs/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-btrfs linux-btrfs/ https://lore.kernel.org/linux-btrfs \
		linux-btrfs@vger.kernel.org linux-btrfs@archiver.kernel.org
	public-inbox-index linux-btrfs


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-btrfs


AGPL code for this site: git clone https://public-inbox.org/ public-inbox