From: David Sterba <dsterba@suse.cz>
To: Yangtao Li <frank.li@vivo.com>
Cc: clm@fb.com, josef@toxicpanda.com, dsterba@suse.com,
linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 01/13] btrfs: update btrfs_insert_inode_defrag to to use rb helper
Date: Tue, 22 Apr 2025 13:21:37 +0200 [thread overview]
Message-ID: <20250422112137.GA3659@suse.cz> (raw)
In-Reply-To: <20250422081504.1998809-1-frank.li@vivo.com>
Please post the series with a cover letter so comments that apply to the
whole series can be posted there.
The series looks good, tests are running OK so far, I have mostly coding
style comments.
- rephrase the subject line to
"btrfs: use rb_find_add() in btrfs_insert_inode_defrag(I)
here mentioning the rb helper also suggests what the patch does and is
obvious so it does not need a long description.
On Tue, Apr 22, 2025 at 02:14:52AM -0600, Yangtao Li wrote:
> Update btrfs_insert_inode_defrag() to use rb_find_add().
The following text can be used in most patches (adjusted accordingly)
"Use the rb-tree helper so we don't open code the search and insert
code."
>
> Suggested-by: David Sterba <dsterba@suse.com>
Please drop this tag.
> Signed-off-by: Yangtao Li <frank.li@vivo.com>
> ---
> fs/btrfs/defrag.c | 52 +++++++++++++++++++++++------------------------
> 1 file changed, 25 insertions(+), 27 deletions(-)
>
> diff --git a/fs/btrfs/defrag.c b/fs/btrfs/defrag.c
> index d4310d93f532..d908bce0b8a1 100644
> --- a/fs/btrfs/defrag.c
> +++ b/fs/btrfs/defrag.c
> @@ -60,6 +60,16 @@ static int compare_inode_defrag(const struct inode_defrag *defrag1,
> return 0;
> }
>
> +static int inode_defrag_cmp(struct rb_node *new, const struct rb_node *exist)
This is a bit confusing name because there's also compare_inode_defrag()
but I don't have a better suggestion.
> +{
> + const struct inode_defrag *new_defrag =
> + rb_entry(new, struct inode_defrag, rb_node);
> + const struct inode_defrag *exist_defrag =
> + rb_entry(exist, struct inode_defrag, rb_node);
> +
> + return compare_inode_defrag(new_defrag, exist_defrag);
> +}
> +
> /*
> * Insert a record for an inode into the defrag tree. The lock must be held
> * already.
> @@ -71,37 +81,25 @@ static int btrfs_insert_inode_defrag(struct btrfs_inode *inode,
> struct inode_defrag *defrag)
> {
> struct btrfs_fs_info *fs_info = inode->root->fs_info;
> - struct inode_defrag *entry;
> - struct rb_node **p;
> - struct rb_node *parent = NULL;
> - int ret;
> + struct rb_node *exist;
Please use 'node' for the rb_nodes.
>
> - p = &fs_info->defrag_inodes.rb_node;
> - while (*p) {
> - parent = *p;
> - entry = rb_entry(parent, struct inode_defrag, rb_node);
> + exist = rb_find_add(&defrag->rb_node, &fs_info->defrag_inodes, inode_defrag_cmp);
> + if (exist) {
> + struct inode_defrag *entry;
>
> - ret = compare_inode_defrag(defrag, entry);
> - if (ret < 0)
> - p = &parent->rb_left;
> - else if (ret > 0)
> - p = &parent->rb_right;
> - else {
> - /*
> - * If we're reinserting an entry for an old defrag run,
> - * make sure to lower the transid of our existing
> - * record.
> - */
> - if (defrag->transid < entry->transid)
> - entry->transid = defrag->transid;
> - entry->extent_thresh = min(defrag->extent_thresh,
> - entry->extent_thresh);
> - return -EEXIST;
> - }
> + entry = rb_entry(exist, struct inode_defrag, rb_node);
> + /*
> + * If we're reinserting an entry for an old defrag run,
> + * make sure to lower the transid of our existing
> + * record.
Please reformat the comment to 80 columns.
> + */
> + if (defrag->transid < entry->transid)
> + entry->transid = defrag->transid;
> + entry->extent_thresh = min(defrag->extent_thresh,
> + entry->extent_thresh);
> + return -EEXIST;
> }
> set_bit(BTRFS_INODE_IN_DEFRAG, &inode->runtime_flags);
> - rb_link_node(&defrag->rb_node, parent, p);
> - rb_insert_color(&defrag->rb_node, &fs_info->defrag_inodes);
> return 0;
> }
>
> --
> 2.39.0
>
next prev parent reply other threads:[~2025-04-22 11:21 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-22 8:14 [PATCH 01/13] btrfs: update btrfs_insert_inode_defrag to to use rb helper Yangtao Li
2025-04-22 8:14 ` [PATCH 02/13] btrfs: update __btrfs_lookup_delayed_item " Yangtao Li
2025-04-22 11:24 ` David Sterba
2025-04-22 8:14 ` [PATCH 03/13] btrfs: update ulist_rbtree_search " Yangtao Li
2025-04-22 8:14 ` [PATCH 04/13] btrfs: update ulist_rbtree_insert " Yangtao Li
2025-04-22 8:14 ` [PATCH 05/13] btrfs: update lookup_block_entry " Yangtao Li
2025-04-22 8:14 ` [PATCH 06/13] btrfs: update insert_block_entry " Yangtao Li
2025-04-22 8:14 ` [PATCH 07/13] btrfs: update lookup_root_entry " Yangtao Li
2025-04-22 8:14 ` [PATCH 08/13] btrfs: update insert_root_entry " Yangtao Li
2025-04-22 8:15 ` [PATCH 09/13] btrfs: update insert_ref_entry " Yangtao Li
2025-04-22 8:15 ` [PATCH 10/13] btrfs: update find_qgroup_rb " Yangtao Li
2025-04-22 8:15 ` [PATCH 11/13] btrfs: update add_qgroup_rb " Yangtao Li
2025-04-22 8:15 ` [PATCH 12/13] btrfs: update btrfs_qgroup_trace_subtree_after_cow " Yangtao Li
2025-04-22 8:15 ` [PATCH 13/13] btrfs: update btrfs_qgroup_add_swapped_blocks " Yangtao Li
2025-04-22 11:21 ` David Sterba [this message]
2025-05-20 5:14 ` [PATCH 01/13] btrfs: update btrfs_insert_inode_defrag " Yangtao Li
2025-05-21 7:06 ` 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=20250422112137.GA3659@suse.cz \
--to=dsterba@suse.cz \
--cc=clm@fb.com \
--cc=dsterba@suse.com \
--cc=frank.li@vivo.com \
--cc=josef@toxicpanda.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-kernel@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.