diff mbox series

[6/6] btrfs: update tree_insert() to use rb helpers

Message ID c80d0f92b73983e7454291154b3fb6ae555f6053.1734033142.git.beckerlee3@gmail.com (mailing list archive)
State New
Headers show
Series None | expand

Commit Message

Lee Beckermeyer Dec. 12, 2024, 8:29 p.m. UTC
update tree_insert() to use rb_find_add_cached().
add cmp_refs_node in rb_find_add_cached() to compare.

note: I think some of comparison functions could be further refined.

V2: incorporated changes from Filipe Manana

Signed-off-by: Roger L. Beckermeyer III <beckerlee3@gmail.com>
---
 fs/btrfs/delayed-ref.c | 39 ++++++++++++++++-----------------------
 1 file changed, 16 insertions(+), 23 deletions(-)

Comments

Qu Wenruo Dec. 13, 2024, 6:19 a.m. UTC | #1
在 2024/12/13 06:59, Roger L. Beckermeyer III 写道:
> update tree_insert() to use rb_find_add_cached().
> add cmp_refs_node in rb_find_add_cached() to compare.
> 
> note: I think some of comparison functions could be further refined.
> 
> V2: incorporated changes from Filipe Manana

Firstly changelog should not be part of the commit message. It should be 
after the "---" line so that git-am will drop it when applying.

Secondly if you're updating a series of patches, please resend the whole 
series and put the change log into the cover letter to explain all the 
changes.
Updating one patch of a series is only going to make it much harder to 
follow/apply.

And put a version number for the whole series. It can be done by 
git-formatpatch with `--subject="PATCH v2"` option.

Lastly, please do not split your patches and send differently, the last 
send attempt split the first and the remaining patches, just do not do that.
Always send the whole series with "git send-email *.patch", that will 
easily mess up the Message-Id (which is already messed up as you put two 
message ids for your new series, meanwhile you should use a new 
message-id for each updated series)

If you want separate Cc, you can put it into the commit message and 
git-sendemail will pick it up.

Thanks,
Qu

> 
> Signed-off-by: Roger L. Beckermeyer III <beckerlee3@gmail.com>
> ---
>   fs/btrfs/delayed-ref.c | 39 ++++++++++++++++-----------------------
>   1 file changed, 16 insertions(+), 23 deletions(-)
> 
> diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c
> index 30f7079fa28e..3cd122c899cc 100644
> --- a/fs/btrfs/delayed-ref.c
> +++ b/fs/btrfs/delayed-ref.c
> @@ -317,34 +317,27 @@ static int comp_refs(struct btrfs_delayed_ref_node *ref1,
>   	return 0;
>   }
>   
> +static int cmp_refs_node(struct rb_node *node, const struct rb_node *node2)
> +{
> +	struct btrfs_delayed_ref_node *ref1;
> +	const struct btrfs_delayed_ref_node *ref2;
> +	bool check_seq = true;
> +
> +	ref1 = rb_entry(node, struct btrfs_delayed_ref_node, ref_node);
> +	ref2 = rb_entry(node2, struct btrfs_delayed_ref_node, ref_node);
> +
> +	return comp_refs(ref1, ref2, check_seq);
> +}
> +
>   static struct btrfs_delayed_ref_node* tree_insert(struct rb_root_cached *root,
>   		struct btrfs_delayed_ref_node *ins)
>   {
> -	struct rb_node **p = &root->rb_root.rb_node;
>   	struct rb_node *node = &ins->ref_node;
> -	struct rb_node *parent_node = NULL;
> -	struct btrfs_delayed_ref_node *entry;
> -	bool leftmost = true;
> -
> -	while (*p) {
> -		int comp;
> -
> -		parent_node = *p;
> -		entry = rb_entry(parent_node, struct btrfs_delayed_ref_node,
> -				 ref_node);
> -		comp = comp_refs(ins, entry, true);
> -		if (comp < 0) {
> -			p = &(*p)->rb_left;
> -		} else if (comp > 0) {
> -			p = &(*p)->rb_right;
> -			leftmost = false;
> -		} else {
> -			return entry;
> -		}
> -	}
> +	struct rb_node *exist;
>   
> -	rb_link_node(node, parent_node, p);
> -	rb_insert_color_cached(node, root, leftmost);
> +	exist = rb_find_add_cached(node, root, cmp_refs_node);
> +	if (exist != NULL)
> +		return rb_entry(exist, struct btrfs_delayed_ref_node, ref_node);
>   	return NULL;
>   }
>
Johannes Thumshirn Dec. 13, 2024, 7:30 a.m. UTC | #2
On 13.12.24 07:19, Qu Wenruo wrote:
> 
> 
> 在 2024/12/13 06:59, Roger L. Beckermeyer III 写道:
>> update tree_insert() to use rb_find_add_cached().
>> add cmp_refs_node in rb_find_add_cached() to compare.
>>
>> note: I think some of comparison functions could be further refined.
>>
>> V2: incorporated changes from Filipe Manana
> 
> Firstly changelog should not be part of the commit message. It should be
> after the "---" line so that git-am will drop it when applying.
> 
> Secondly if you're updating a series of patches, please resend the whole
> series and put the change log into the cover letter to explain all the
> changes.
> Updating one patch of a series is only going to make it much harder to
> follow/apply.
> 
> And put a version number for the whole series. It can be done by
> git-formatpatch with `--subject="PATCH v2"` option.

Nit: git format-patch -v 2 also gives you a nice v2-XXX.patch prefix for 
the files as well as "PATCH v2" for the subject.
Qu Wenruo Dec. 13, 2024, 7:32 a.m. UTC | #3
在 2024/12/13 18:00, Johannes Thumshirn 写道:
> On 13.12.24 07:19, Qu Wenruo wrote:
>>
>>
>> 在 2024/12/13 06:59, Roger L. Beckermeyer III 写道:
>>> update tree_insert() to use rb_find_add_cached().
>>> add cmp_refs_node in rb_find_add_cached() to compare.
>>>
>>> note: I think some of comparison functions could be further refined.
>>>
>>> V2: incorporated changes from Filipe Manana
>>
>> Firstly changelog should not be part of the commit message. It should be
>> after the "---" line so that git-am will drop it when applying.
>>
>> Secondly if you're updating a series of patches, please resend the whole
>> series and put the change log into the cover letter to explain all the
>> changes.
>> Updating one patch of a series is only going to make it much harder to
>> follow/apply.
>>
>> And put a version number for the whole series. It can be done by
>> git-formatpatch with `--subject="PATCH v2"` option.
> 
> Nit: git format-patch -v 2 also gives you a nice v2-XXX.patch prefix for
> the files as well as "PATCH v2" for the subject.

Thanks a lot! It saves quite a lot of key strikes, and even added the 
"v2-" prefix.

Never too old to learn.

Thanks,
Qu
Lee Beckermeyer Dec. 13, 2024, 5:14 p.m. UTC | #4
On Fri, Dec 13, 2024 at 1:32 AM Qu Wenruo <wqu@suse.com> wrote:
>
>
>
> 在 2024/12/13 18:00, Johannes Thumshirn 写道:
> > On 13.12.24 07:19, Qu Wenruo wrote:
> >>
> >>
> >> 在 2024/12/13 06:59, Roger L. Beckermeyer III 写道:
> >>> update tree_insert() to use rb_find_add_cached().
> >>> add cmp_refs_node in rb_find_add_cached() to compare.
> >>>
> >>> note: I think some of comparison functions could be further refined.
> >>>
> >>> V2: incorporated changes from Filipe Manana
> >>
> >> Firstly changelog should not be part of the commit message. It should be
> >> after the "---" line so that git-am will drop it when applying.
added it to the cover letter this time, also was more thorough in
documenting the changes.
> >>
> >> Secondly if you're updating a series of patches, please resend the whole
> >> series and put the change log into the cover letter to explain all the
> >> changes.
> >> Updating one patch of a series is only going to make it much harder to
> >> follow/apply.
Roger (pun intended) I'll resend the whole patch series once I get a
reply on this, I've been utilizing the help message on the first
message I sent so it all stays the same more or less. Should I not be
doing that when I send a new patch series?
> >>
> >> And put a version number for the whole series. It can be done by
> >> git-formatpatch with `--subject="PATCH v2"` option.
> >
> > Nit: git format-patch -v 2 also gives you a nice v2-XXX.patch prefix for
> > the files as well as "PATCH v2" for the subject.
>
> Thanks a lot! It saves quite a lot of key strikes, and even added the
> "v2-" prefix.
>
> Never too old to learn.
>
> Thanks,
> Qu
Qu Wenruo Dec. 13, 2024, 8:28 p.m. UTC | #5
在 2024/12/14 03:44, Lee Beckermeyer 写道:
> On Fri, Dec 13, 2024 at 1:32 AM Qu Wenruo <wqu@suse.com> wrote:
>>
>>
>>
>> 在 2024/12/13 18:00, Johannes Thumshirn 写道:
>>> On 13.12.24 07:19, Qu Wenruo wrote:
>>>>
>>>>
>>>> 在 2024/12/13 06:59, Roger L. Beckermeyer III 写道:
>>>>> update tree_insert() to use rb_find_add_cached().
>>>>> add cmp_refs_node in rb_find_add_cached() to compare.
>>>>>
>>>>> note: I think some of comparison functions could be further refined.
>>>>>
>>>>> V2: incorporated changes from Filipe Manana
>>>>
>>>> Firstly changelog should not be part of the commit message. It should be
>>>> after the "---" line so that git-am will drop it when applying.
> added it to the cover letter this time, also was more thorough in
> documenting the changes.
>>>>
>>>> Secondly if you're updating a series of patches, please resend the whole
>>>> series and put the change log into the cover letter to explain all the
>>>> changes.
>>>> Updating one patch of a series is only going to make it much harder to
>>>> follow/apply.
> Roger (pun intended) I'll resend the whole patch series once I get a
> reply on this, I've been utilizing the help message on the first
> message I sent so it all stays the same more or less.

What do you mean by the "help message"?

> Should I not be
> doing that when I send a new patch series?
>>>>
>>>> And put a version number for the whole series. It can be done by
>>>> git-formatpatch with `--subject="PATCH v2"` option.
>>>
>>> Nit: git format-patch -v 2 also gives you a nice v2-XXX.patch prefix for
>>> the files as well as "PATCH v2" for the subject.
>>
>> Thanks a lot! It saves quite a lot of key strikes, and even added the
>> "v2-" prefix.
>>
>> Never too old to learn.
>>
>> Thanks,
>> Qu
>
diff mbox series

Patch

diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c
index 30f7079fa28e..3cd122c899cc 100644
--- a/fs/btrfs/delayed-ref.c
+++ b/fs/btrfs/delayed-ref.c
@@ -317,34 +317,27 @@  static int comp_refs(struct btrfs_delayed_ref_node *ref1,
 	return 0;
 }
 
+static int cmp_refs_node(struct rb_node *node, const struct rb_node *node2)
+{
+	struct btrfs_delayed_ref_node *ref1;
+	const struct btrfs_delayed_ref_node *ref2;
+	bool check_seq = true;
+
+	ref1 = rb_entry(node, struct btrfs_delayed_ref_node, ref_node);
+	ref2 = rb_entry(node2, struct btrfs_delayed_ref_node, ref_node);
+
+	return comp_refs(ref1, ref2, check_seq);
+}
+
 static struct btrfs_delayed_ref_node* tree_insert(struct rb_root_cached *root,
 		struct btrfs_delayed_ref_node *ins)
 {
-	struct rb_node **p = &root->rb_root.rb_node;
 	struct rb_node *node = &ins->ref_node;
-	struct rb_node *parent_node = NULL;
-	struct btrfs_delayed_ref_node *entry;
-	bool leftmost = true;
-
-	while (*p) {
-		int comp;
-
-		parent_node = *p;
-		entry = rb_entry(parent_node, struct btrfs_delayed_ref_node,
-				 ref_node);
-		comp = comp_refs(ins, entry, true);
-		if (comp < 0) {
-			p = &(*p)->rb_left;
-		} else if (comp > 0) {
-			p = &(*p)->rb_right;
-			leftmost = false;
-		} else {
-			return entry;
-		}
-	}
+	struct rb_node *exist;
 
-	rb_link_node(node, parent_node, p);
-	rb_insert_color_cached(node, root, leftmost);
+	exist = rb_find_add_cached(node, root, cmp_refs_node);
+	if (exist != NULL)
+		return rb_entry(exist, struct btrfs_delayed_ref_node, ref_node);
 	return NULL;
 }