linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Wei Yang <richard.weiyang@gmail.com>
To: akpm@linux-foundation.org, Liam.Howlett@oracle.com
Cc: maple-tree@lists.infradead.org, linux-mm@kvack.org,
	Wei Yang <richard.weiyang@gmail.com>
Subject: [PATCH 3/4] maple_tree: copy to mt_pivot_count() instead of mt_slot_count()
Date: Thu, 19 Sep 2024 23:48:31 +0000	[thread overview]
Message-ID: <20240919234832.24237-4-richard.weiyang@gmail.com> (raw)
In-Reply-To: <20240919234832.24237-1-richard.weiyang@gmail.com>

mas_mab_cp() copy a maple_node's range inclusively, and the maximum
valid data index is (mt_slot_count() - 1) instead of mt_slot_count().

But if using (mt_slot_count() - 1) directly, it would have more
instructions.  The good news is we have defined mt_pivot_count() ==
(mt_slot_count - 1), except for maple_dense node. And mas_mab_cp()
doesn't handle maple_dense node. So it is safe to use it.

By doing so have almost identical generated code:

Current:

  lib/maple_tree.c:2209: 	mas_mab_cp(mast->orig_r, 0, mt_slot_count(mast->orig_r->node),
	movl	%esi, (%esp)	# _135,
	movl	-88(%ebp), %eax	# %sfp, _137
	movzbl	mt_slots(%edx), %ecx	# mt_slots[_142], mt_slots[_142]
	xorl	%edx, %edx	#
	movl	%eax, 4(%esp)	# _137,
	movl	%ebx, %eax	# _138,
	call	mas_mab_cp	#

After applying this patch:

  lib/maple_tree.c:2209: 	mas_mab_cp(mast->orig_r, 0, mt_pivot_count(mast->orig_r->node),
	movl	%esi, (%esp)	# _135,
	movl	-88(%ebp), %eax	# %sfp, _137
	movzbl	mt_pivots(%edx), %ecx	# mt_pivots[_142], mt_pivots[_142]
	xorl	%edx, %edx	#
	movl	%eax, 4(%esp)	# _137,
	movl	%ebx, %eax	# _138,
	call	mas_mab_cp	#

The difference is we access mt_pivots to get ecx instead of mt_slots,
which doesn't expect performance difference.

Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
---
 lib/maple_tree.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/maple_tree.c b/lib/maple_tree.c
index 8ff075645f21..bb4183b973d4 100644
--- a/lib/maple_tree.c
+++ b/lib/maple_tree.c
@@ -2211,7 +2211,7 @@ static inline void mast_rebalance_next(struct maple_subtree_state *mast)
 {
 	unsigned char b_end = mast->bn->b_end;
 
-	mas_mab_cp(mast->orig_r, 0, mt_slot_count(mast->orig_r->node),
+	mas_mab_cp(mast->orig_r, 0, mt_pivot_count(mast->orig_r->node),
 		   mast->bn, b_end);
 	mast->orig_r->last = mast->orig_r->max;
 }
@@ -2692,7 +2692,7 @@ static inline void mast_combine_cp_right(struct maple_subtree_state *mast)
 		return;
 
 	mas_mab_cp(mast->orig_r, mast->orig_r->offset + 1,
-		   mt_slot_count(mast->orig_r->node), mast->bn,
+		   mt_pivot_count(mast->orig_r->node), mast->bn,
 		   mast->bn->b_end);
 	mast->orig_r->last = mast->orig_r->max;
 }
@@ -2963,7 +2963,7 @@ static inline int mas_rebalance(struct ma_state *mas,
 	l_mas = r_mas = *mas;
 
 	if (mas_next_sibling(&r_mas)) {
-		mas_mab_cp(&r_mas, 0, mt_slot_count(r_mas.node), b_node, b_end);
+		mas_mab_cp(&r_mas, 0, mt_pivot_count(r_mas.node), b_node, b_end);
 		r_mas.last = r_mas.index = r_mas.max;
 	} else {
 		mas_prev_sibling(&l_mas);
-- 
2.34.1



  parent reply	other threads:[~2024-09-20  0:40 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-19 23:48 [PATCH 0/4] refine mas_end of mas_mab_cp() Wei Yang
2024-09-19 23:48 ` [PATCH 1/4] maple_tree: not necessary to copy mas->end + 1 Wei Yang
2024-09-19 23:48 ` [PATCH 2/4] maple_tree: use mt_pivot_count() to replace mt_slot_count() - 1 Wei Yang
2024-09-19 23:48 ` Wei Yang [this message]
2024-09-19 23:48 ` [PATCH 4/4] maple_tree: now we are sure mas_end wouldn't exceed mt_pivots[mt] Wei Yang
2024-09-23 19:57 ` [PATCH 0/4] refine mas_end of mas_mab_cp() Liam R. Howlett

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=20240919234832.24237-4-richard.weiyang@gmail.com \
    --to=richard.weiyang@gmail.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-mm@kvack.org \
    --cc=maple-tree@lists.infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox