From: Boris Burkov <boris@bur.io>
To: Josef Bacik <josef@toxicpanda.com>
Cc: linux-btrfs@vger.kernel.org, kernel-team@fb.com
Subject: Re: [PATCH 10/18] btrfs: track owning root in btrfs_ref
Date: Thu, 13 Jul 2023 14:21:17 -0700 [thread overview]
Message-ID: <20230713212117.GA2629298@zen> (raw)
In-Reply-To: <20230713165825.GJ207541@perftesting>
On Thu, Jul 13, 2023 at 12:58:25PM -0400, Josef Bacik wrote:
> On Wed, Jul 05, 2023 at 04:20:47PM -0700, Boris Burkov wrote:
> > While data extents require us to store additional inline refs to track
> > the original owner on free, this information is available implicitly for
> > metadata. It is found in the owner field of the header of the tree
> > block. Even if other trees refer to this block and the original ref goes
> > away, we will not rewrite that header field, so it will reliably give the
> > original owner.
> >
> > In addition, there is a relocation case where a new data extent needs to
> > have an owning root separate from the referring root wired through
> > delayed refs.
> >
> > To use it for recording simple quota deltas, we need to wire this root
> > id through from when we create the delayed ref until we fully process
> > it. Store it in the generic btrfs_ref struct of the delayed ref.
> >
> > Signed-off-by: Boris Burkov <boris@bur.io>
> > ---
> > fs/btrfs/delayed-ref.c | 7 ++++---
> > fs/btrfs/delayed-ref.h | 13 +++++++++++--
> > fs/btrfs/extent-tree.c | 19 ++++++++++++-------
> > fs/btrfs/file.c | 10 +++++-----
> > fs/btrfs/inode-item.c | 2 +-
> > fs/btrfs/relocation.c | 16 +++++++++-------
> > fs/btrfs/tree-log.c | 3 ++-
> > 7 files changed, 44 insertions(+), 26 deletions(-)
> >
> > diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c
> > index f0bae1e1c455..49c320f2334b 100644
> > --- a/fs/btrfs/delayed-ref.c
> > +++ b/fs/btrfs/delayed-ref.c
> > @@ -840,7 +840,7 @@ add_delayed_ref_head(struct btrfs_trans_handle *trans,
> > static void init_delayed_ref_common(struct btrfs_fs_info *fs_info,
> > struct btrfs_delayed_ref_node *ref,
> > u64 bytenr, u64 num_bytes, u64 ref_root,
> > - int action, u8 ref_type)
> > + int action, u8 ref_type, u64 owning_root)
> > {
> > u64 seq = 0;
> >
> > @@ -857,6 +857,7 @@ static void init_delayed_ref_common(struct btrfs_fs_info *fs_info,
> > ref->action = action;
> > ref->seq = seq;
> > ref->type = ref_type;
> > + ref->owning_root = owning_root;
> > RB_CLEAR_NODE(&ref->ref_node);
> > INIT_LIST_HEAD(&ref->add_list);
> > }
> > @@ -915,7 +916,7 @@ int btrfs_add_delayed_tree_ref(struct btrfs_trans_handle *trans,
> >
> > init_delayed_ref_common(fs_info, &ref->node, bytenr, num_bytes,
> > generic_ref->tree_ref.ref_root, action,
> > - ref_type);
> > + ref_type, generic_ref->owning_root);
> > ref->root = generic_ref->tree_ref.ref_root;
> > ref->parent = parent;
> > ref->level = level;
> > @@ -989,7 +990,7 @@ int btrfs_add_delayed_data_ref(struct btrfs_trans_handle *trans,
> > else
> > ref_type = BTRFS_EXTENT_DATA_REF_KEY;
> > init_delayed_ref_common(fs_info, &ref->node, bytenr, num_bytes,
> > - ref_root, action, ref_type);
> > + ref_root, action, ref_type, ref_root);
> > ref->root = ref_root;
> > ref->parent = parent;
> > ref->objectid = owner;
> > diff --git a/fs/btrfs/delayed-ref.h b/fs/btrfs/delayed-ref.h
> > index a71eff78469c..336c33c28191 100644
> > --- a/fs/btrfs/delayed-ref.h
> > +++ b/fs/btrfs/delayed-ref.h
> > @@ -32,6 +32,12 @@ struct btrfs_delayed_ref_node {
> > /* seq number to keep track of insertion order */
> > u64 seq;
> >
> > + /*
> > + * root which originally allocated this extent and owns it for
> > + * simple quota accounting purposes.
> > + */
> > + u64 owning_root;
> > +
> > /* ref count on this data structure */
> > refcount_t refs;
> >
> > @@ -239,6 +245,7 @@ struct btrfs_ref {
> > #endif
> > u64 bytenr;
> > u64 len;
> > + u64 owning_root;
> >
> > /* Bytenr of the parent tree block */
> > u64 parent;
> > @@ -278,16 +285,18 @@ static inline u64 btrfs_calc_delayed_ref_bytes(const struct btrfs_fs_info *fs_in
> > }
> >
> > static inline void btrfs_init_generic_ref(struct btrfs_ref *generic_ref,
> > - int action, u64 bytenr, u64 len, u64 parent)
> > + int action, u64 bytenr, u64 len, u64 parent, u64 owning_root)
> > {
> > generic_ref->action = action;
> > generic_ref->bytenr = bytenr;
> > generic_ref->len = len;
> > generic_ref->parent = parent;
> > + generic_ref->owning_root = owning_root;
> > }
> >
> > static inline void btrfs_init_tree_ref(struct btrfs_ref *generic_ref,
> > - int level, u64 root, u64 mod_root, bool skip_qgroup)
> > + int level, u64 root, u64 mod_root,
> > + bool skip_qgroup)
> > {
> > #ifdef CONFIG_BTRFS_FS_REF_VERIFY
> > /* If @real_root not set, use @root as fallback */
> > diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
> > index 041f2eb153d7..fa53f7cbd84a 100644
> > --- a/fs/btrfs/extent-tree.c
> > +++ b/fs/btrfs/extent-tree.c
> > @@ -2410,7 +2410,7 @@ static int __btrfs_mod_ref(struct btrfs_trans_handle *trans,
> > num_bytes = btrfs_file_extent_disk_num_bytes(buf, fi);
> > key.offset -= btrfs_file_extent_offset(buf, fi);
> > btrfs_init_generic_ref(&generic_ref, action, bytenr,
> > - num_bytes, parent);
> > + num_bytes, parent, ref_root);
> > btrfs_init_data_ref(&generic_ref, ref_root, key.objectid,
> > key.offset, root->root_key.objectid,
> > for_reloc);
> > @@ -2424,7 +2424,7 @@ static int __btrfs_mod_ref(struct btrfs_trans_handle *trans,
> > bytenr = btrfs_node_blockptr(buf, i);
> > num_bytes = fs_info->nodesize;
> > btrfs_init_generic_ref(&generic_ref, action, bytenr,
> > - num_bytes, parent);
> > + num_bytes, parent, ref_root);
> > btrfs_init_tree_ref(&generic_ref, level - 1, ref_root,
> > root->root_key.objectid, for_reloc);
> > if (inc)
> > @@ -3242,7 +3242,7 @@ void btrfs_free_tree_block(struct btrfs_trans_handle *trans,
> > int ret;
> >
> > btrfs_init_generic_ref(&generic_ref, BTRFS_DROP_DELAYED_REF,
> > - buf->start, buf->len, parent);
> > + buf->start, buf->len, parent, btrfs_header_owner(buf));
> > btrfs_init_tree_ref(&generic_ref, btrfs_header_level(buf),
> > root_id, 0, false);
> >
> > @@ -4699,12 +4699,16 @@ int btrfs_alloc_reserved_file_extent(struct btrfs_trans_handle *trans,
> > struct btrfs_key *ins)
> > {
> > struct btrfs_ref generic_ref = { 0 };
> > + u64 root_objectid = root->root_key.objectid;
> > + u64 owning_root = root_objectid;
> > +
> > + BUG_ON(root_objectid == BTRFS_TREE_LOG_OBJECTID);
> >
>
> This is a duplicate check of what's checked below. Also we don't want to add
> new BUG_ON()'s, we want to add ASSERT()'s. Thanks,
Oops. I just meant to use root_objectid instead of
root->root_key.objectid and somehow left in the old line, my bad.
I assume we don't want to change these existing BUG_ONs to ASSERTs
without specific justification, though.
>
> Josef
next prev parent reply other threads:[~2023-07-13 21:23 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-05 23:20 [PATCH 00/18] btrfs: simple quotas Boris Burkov
2023-07-05 23:20 ` [PATCH 01/18] btrfs: free qgroup rsv on io failure Boris Burkov
2023-07-13 14:01 ` Josef Bacik
2023-07-05 23:20 ` [PATCH 02/18] btrfs: fix start transaction qgroup rsv double free Boris Burkov
2023-07-13 14:02 ` Josef Bacik
2023-07-05 23:20 ` [PATCH 03/18] btrfs: introduce quota mode Boris Burkov
2023-07-13 14:02 ` Josef Bacik
2023-07-05 23:20 ` [PATCH 04/18] btrfs: add new quota mode for simple quotas Boris Burkov
2023-07-13 14:07 ` Josef Bacik
2023-07-05 23:20 ` [PATCH 05/18] btrfs: expose quota mode via sysfs Boris Burkov
2023-07-13 14:11 ` Josef Bacik
2023-07-05 23:20 ` [PATCH 06/18] btrfs: flush reservations during quota disable Boris Burkov
2023-07-13 14:20 ` Josef Bacik
2023-07-05 23:20 ` [PATCH 07/18] btrfs: create qgroup earlier in snapshot creation Boris Burkov
2023-07-13 14:26 ` Josef Bacik
2023-07-13 19:00 ` Boris Burkov
2023-07-13 20:37 ` Josef Bacik
2023-07-13 23:13 ` Boris Burkov
2023-07-05 23:20 ` [PATCH 08/18] btrfs: function for recording simple quota deltas Boris Burkov
2023-07-13 14:34 ` Josef Bacik
2023-07-05 23:20 ` [PATCH 09/18] btrfs: rename tree_ref and data_ref owning_root Boris Burkov
2023-07-13 16:33 ` Josef Bacik
2023-07-05 23:20 ` [PATCH 10/18] btrfs: track owning root in btrfs_ref Boris Burkov
2023-07-13 16:58 ` Josef Bacik
2023-07-13 21:21 ` Boris Burkov [this message]
2023-07-05 23:20 ` [PATCH 11/18] btrfs: track original extent owner in head_ref Boris Burkov
2023-07-13 17:09 ` Josef Bacik
2023-07-05 23:20 ` [PATCH 12/18] btrfs: new inline ref storing owning subvol of data extents Boris Burkov
2023-07-13 17:16 ` Josef Bacik
2023-07-05 23:20 ` [PATCH 13/18] btrfs: inline owner ref lookup helper Boris Burkov
2023-07-13 17:18 ` Josef Bacik
2023-07-05 23:20 ` [PATCH 14/18] btrfs: record simple quota deltas Boris Burkov
2023-07-13 17:23 ` Josef Bacik
2023-07-05 23:20 ` [PATCH 15/18] btrfs: simple quota auto hierarchy for nested subvols Boris Burkov
2023-07-13 17:28 ` Josef Bacik
2023-07-05 23:20 ` [PATCH 16/18] btrfs: check generation when recording simple quota delta Boris Burkov
2023-07-13 17:29 ` Josef Bacik
2023-07-05 23:20 ` [PATCH 17/18] btrfs: track metadata relocation cow with simple quota Boris Burkov
2023-07-13 17:31 ` Josef Bacik
2023-07-05 23:20 ` [PATCH 18/18] btrfs: track data relocation " Boris Burkov
2023-07-13 17:37 ` 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=20230713212117.GA2629298@zen \
--to=boris@bur.io \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.