public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Josef Bacik <josef@toxicpanda.com>
To: Qu Wenruo <quwenruo.btrfs@gmx.com>
Cc: linux-btrfs@vger.kernel.org, kernel-team@fb.com
Subject: Re: [PATCH 8/8] btrfs: add support for multiple global roots
Date: Mon, 8 Nov 2021 14:39:15 -0500	[thread overview]
Message-ID: <YYl84zTxBf4ZDSSG@localhost.localdomain> (raw)
In-Reply-To: <c7caa1df-f634-302f-4d24-3281aa1c94ac@gmx.com>

On Sat, Nov 06, 2021 at 09:51:20AM +0800, Qu Wenruo wrote:
> 
> 
> On 2021/11/6 09:18, Qu Wenruo wrote:
> > 
> > 
> > On 2021/11/6 04:49, Josef Bacik wrote:
> > > With extent tree v2 you will be able to create multiple csum, extent,
> > > and free space trees.  They will be used based on the block group, which
> > > will now use the block_group_item->chunk_objectid to point to the set of
> > > global roots that it will use.  When allocating new block groups we'll
> > > simply mod the gigabyte offset of the block group against the number of
> > > global roots we have and that will be the block groups global id.
> > > 
> > >  From there we can take the bytenr that we're modifying in the respective
> > > tree, look up the block group and get that block groups corresponding
> > > global root id.  From there we can get to the appropriate global root
> > > for that bytenr.
> > > 
> > > Signed-off-by: Josef Bacik <josef@toxicpanda.com>
> > > ---
> > >   fs/btrfs/block-group.c     | 11 +++++++--
> > >   fs/btrfs/block-group.h     |  1 +
> > >   fs/btrfs/ctree.h           |  2 ++
> > >   fs/btrfs/disk-io.c         | 49 +++++++++++++++++++++++++++++++-------
> > >   fs/btrfs/free-space-tree.c |  2 ++
> > >   fs/btrfs/transaction.c     | 15 ++++++++++++
> > >   fs/btrfs/tree-checker.c    | 21 ++++++++++++++--
> > >   7 files changed, 88 insertions(+), 13 deletions(-)
> > > 
> > > diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
> > > index 7eb0a8632a01..85516f2fd5da 100644
> > > --- a/fs/btrfs/block-group.c
> > > +++ b/fs/btrfs/block-group.c
> > > @@ -2002,6 +2002,7 @@ static int read_one_block_group(struct
> > > btrfs_fs_info *info,
> > >       cache->length = key->offset;
> > >       cache->used = btrfs_stack_block_group_used(bgi);
> > >       cache->flags = btrfs_stack_block_group_flags(bgi);
> > > +    cache->global_root_id = btrfs_stack_block_group_chunk_objectid(bgi);
> > > 
> > >       set_free_space_tree_thresholds(cache);
> > > 
> > > @@ -2284,7 +2285,7 @@ static int insert_block_group_item(struct
> > > btrfs_trans_handle *trans,
> > >       spin_lock(&block_group->lock);
> > >       btrfs_set_stack_block_group_used(&bgi, block_group->used);
> > >       btrfs_set_stack_block_group_chunk_objectid(&bgi,
> > > -                BTRFS_FIRST_CHUNK_TREE_OBJECTID);
> > > +                           block_group->global_root_id);
> > >       btrfs_set_stack_block_group_flags(&bgi, block_group->flags);
> > >       key.objectid = block_group->start;
> > >       key.type = BTRFS_BLOCK_GROUP_ITEM_KEY;
> > > @@ -2460,6 +2461,12 @@ struct btrfs_block_group
> > > *btrfs_make_block_group(struct btrfs_trans_handle *tran
> > >       cache->flags = type;
> > >       cache->last_byte_to_unpin = (u64)-1;
> > >       cache->cached = BTRFS_CACHE_FINISHED;
> > > +    cache->global_root_id = BTRFS_FIRST_CHUNK_TREE_OBJECTID;
> > > +
> > > +    if (btrfs_fs_incompat(fs_info, EXTENT_TREE_V2))
> > > +        cache->global_root_id = div64_u64(cache->start, SZ_1G) %
> > > +            fs_info->nr_global_roots;
> > > +
> > 
> > Any special reason for this complex global_root_id calculation?
> > 
> > My initial assumption for global trees is pretty simple, just something
> > like (CSUM_TREE, ROOT_ITEM, bg bytenr) or (EXTENT_TREE, ROOT_ITEM, bg
> > bytenr) as their root key items.
> > 
> > But this is definitely not the case here.
> > 
> > Thus I'm wondering why we're not using something more simple.
> 

Because we don't have a global tree per-block group.  We have N global roots
that have to be round robined through the block groups.  We could do something
smarter in the future, but for now just round robin'ing them is easy to wrap
your head around, and is a decent default.

> And I also forgot that, for smaller fs, we could have metadata only sized
> several megabytes.
> 
> In that case, several metadata block groups would share the same
> global_root_id, which is definitely not a good idea.
> 

Sure, we can adjust this logic for smaller file systems, I'll change it to scale
down for smaller fs'es.  Thanks,

Josef

      reply	other threads:[~2021-11-08 19:39 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-05 20:49 [PATCH 0/8] btrfs: extent tree v2, support for global roots Josef Bacik
2021-11-05 20:49 ` [PATCH 1/8] btrfs: add definition for EXTENT_TREE_V2 Josef Bacik
2021-11-05 20:49 ` [PATCH 2/8] btrfs: disable balance for extent tree v2 for now Josef Bacik
2021-11-05 20:49 ` [PATCH 3/8] btrfs: disable qgroups in extent tree v2 Josef Bacik
2021-11-05 20:49 ` [PATCH 4/8] btrfs: use metadata usage for global block rsv " Josef Bacik
2021-11-05 20:49 ` [PATCH 5/8] btrfs: tree-checker: don't fail on empty extent roots for " Josef Bacik
2021-11-06  1:05   ` Qu Wenruo
2021-11-05 20:49 ` [PATCH 6/8] btrfs: abstract out loading the tree root Josef Bacik
2021-11-05 20:49 ` [PATCH 7/8] btrfs: add code to support the block group root Josef Bacik
2021-11-06  1:11   ` Qu Wenruo
2021-11-08 19:36     ` Josef Bacik
2021-11-09  1:14       ` Qu Wenruo
2021-11-09 19:24         ` Josef Bacik
2021-11-09 23:44           ` Qu Wenruo
2021-11-10 13:57             ` Josef Bacik
2021-11-10  7:13           ` Qu Wenruo
2021-11-10 13:54             ` Josef Bacik
2021-11-05 20:49 ` [PATCH 8/8] btrfs: add support for multiple global roots Josef Bacik
2021-11-06  1:18   ` Qu Wenruo
2021-11-06  1:51     ` Qu Wenruo
2021-11-08 19:39       ` Josef Bacik [this message]

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=YYl84zTxBf4ZDSSG@localhost.localdomain \
    --to=josef@toxicpanda.com \
    --cc=kernel-team@fb.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=quwenruo.btrfs@gmx.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