linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.cz>
To: Nikolay Borisov <nborisov@suse.com>
Cc: Josef Bacik <josef@toxicpanda.com>,
	linux-btrfs@vger.kernel.org, kernel-team@fb.com
Subject: Re: [PATCH 1/2] btrfs: include the free space tree in the global rsv minimum calculation
Date: Tue, 7 Dec 2021 20:19:03 +0100	[thread overview]
Message-ID: <20211207191902.GE28560@twin.jikos.cz> (raw)
In-Reply-To: <e57e0536-779b-f617-477f-08e3c99c5c81@suse.com>

On Thu, Dec 02, 2021 at 11:07:51AM +0200, Nikolay Borisov wrote:
> > diff --git a/fs/btrfs/block-rsv.c b/fs/btrfs/block-rsv.c
> > index 21ac60ec19f6..b3086f252ad0 100644
> > --- a/fs/btrfs/block-rsv.c
> > +++ b/fs/btrfs/block-rsv.c
> > @@ -352,25 +352,29 @@ 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;
> > -	struct btrfs_root *extent_root = btrfs_extent_root(fs_info, 0);
> > -	struct btrfs_root *csum_root = btrfs_csum_root(fs_info, 0);
> > -	u64 num_bytes;
> > -	unsigned min_items;
> > +	struct btrfs_root *root, *tmp;
> > +	u64 num_bytes = btrfs_root_used(&fs_info->tree_root->root_item);
> > +	unsigned int min_items = 1;
> >  
> >  	/*
> >  	 * The global block rsv is based on the size of the extent tree, the
> >  	 * checksum tree and the root tree.  If the fs is empty we want to set
> >  	 * it to a minimal amount for safety.
> > +	 *
> > +	 * We also are going to need to modify the minimum of the tree root and
> > +	 * any global roots we could touch.
> >  	 */
> > -	num_bytes = btrfs_root_used(&extent_root->root_item) +
> > -		btrfs_root_used(&csum_root->root_item) +
> > -		btrfs_root_used(&fs_info->tree_root->root_item);
> > -
> > -	/*
> > -	 * We at a minimum are going to modify the csum root, the tree root, and
> > -	 * the extent root.
> > -	 */
> > -	min_items = 3;
> > +	read_lock(&fs_info->global_root_lock);
> > +	rbtree_postorder_for_each_entry_safe(root, tmp, &fs_info->global_root_tree,
> > +					     rb_node) {
> > +		if (root->root_key.objectid == BTRFS_EXTENT_TREE_OBJECTID ||
> > +		    root->root_key.objectid == BTRFS_CSUM_TREE_OBJECTID ||
> > +		    root->root_key.objectid == BTRFS_FREE_SPACE_TREE_OBJECTID) {
> > +			num_bytes += btrfs_root_used(&root->root_item);
> > +			min_items++;
> > +		}
> > +	}
> 
> nit: I think those changes constitute 2 patches - the first does the
> global_root_tree iteration as preparation for global roots. And the
> subsequent patch should also include the freespace tree, no ? Otherwise
> LGTM.

As this is probably a fix we'd like to backport, the oder of the
suggested patches would have to be reversed too, so we first have the
fix and then port to the global roots. But the diff is short and a
backport to non-global roots could be done in one go as well,
referencing this patch.

  reply	other threads:[~2021-12-07 19:19 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1638377089.git.josef@toxicpanda.com>
2021-12-01 16:45 ` [PATCH 1/2] btrfs: include the free space tree in the global rsv minimum calculation Josef Bacik
2021-12-02  9:07   ` Nikolay Borisov
2021-12-07 19:19     ` David Sterba [this message]
2021-12-01 16:45 ` [PATCH 2/2] btrfs: reserve extra space for the free space tree Josef Bacik
2021-12-02 14:14   ` Nikolay Borisov
2021-12-02 15:46     ` Josef Bacik

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=20211207191902.GE28560@twin.jikos.cz \
    --to=dsterba@suse.cz \
    --cc=josef@toxicpanda.com \
    --cc=kernel-team@fb.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=nborisov@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
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).