All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Liam R. Howlett" <Liam.Howlett@oracle.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: maple-tree@lists.infradead.org, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org,
	"Liam R. Howlett" <Liam.Howlett@oracle.com>
Subject: [PATCH 12/12] maple_tree: mtree_range_walk() clean up
Date: Wed,  1 Nov 2023 13:16:29 -0400	[thread overview]
Message-ID: <20231101171629.3612299-13-Liam.Howlett@oracle.com> (raw)
In-Reply-To: <20231101171629.3612299-1-Liam.Howlett@oracle.com>

mtree_range_walk() needed to be updated to avoid checking if there was a
pivot value.  On closer examination, the code could avoid setting min or
max in certain scenarios.  The commit removes the extra check for
pivot[offset] before setting max and only sets max when necessary.  It
also only sets min if it is necessary by checking offset 0 prior to the
loop (as it has always done).

The commit also drops a dead node check since the end of the node will
return the array size when the last slot is occupied (by a potential
reuse in a dead node).  The data will be discarded later if the node is
marked dead.

Benchmarking these changes results in an increase in performance of
5.45% using the BENCH_WALK in the maple tree test code.

Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
---
 lib/maple_tree.c | 27 ++++++++++++---------------
 1 file changed, 12 insertions(+), 15 deletions(-)

diff --git a/lib/maple_tree.c b/lib/maple_tree.c
index a91adaf17306..56cc8278260f 100644
--- a/lib/maple_tree.c
+++ b/lib/maple_tree.c
@@ -2796,32 +2796,29 @@ static inline void *mtree_range_walk(struct ma_state *mas)
 	min = mas->min;
 	max = mas->max;
 	do {
-		offset = 0;
 		last = next;
 		node = mte_to_node(next);
 		type = mte_node_type(next);
 		pivots = ma_pivots(node, type);
 		end = ma_data_end(node, type, pivots, max);
-		if (unlikely(ma_dead_node(node)))
-			goto dead_node;
-
-		if (pivots[offset] >= mas->index) {
-			prev_max = max;
-			prev_min = min;
-			max = pivots[offset];
+		prev_min = min;
+		prev_max = max;
+		if (pivots[0] >= mas->index) {
+			offset = 0;
+			max = pivots[0];
 			goto next;
 		}
 
-		do {
+		offset = 1;
+		while (offset < end) {
+			if (pivots[offset] >= mas->index) {
+				max = pivots[offset];
+				break;
+			}
 			offset++;
-		} while ((offset < end) && (pivots[offset] < mas->index));
+		}
 
-		prev_min = min;
 		min = pivots[offset - 1] + 1;
-		prev_max = max;
-		if (likely(offset < end && pivots[offset]))
-			max = pivots[offset];
-
 next:
 		slots = ma_slots(node, type);
 		next = mt_slot(mas->tree, slots, offset);
-- 
2.40.1


      parent reply	other threads:[~2023-11-01 17:17 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-01 17:16 [PATCH 00/12] maple_tree: iterator state changes Liam R. Howlett
2023-11-01 17:16 ` [PATCH 01/12] maple_tree: Remove unnecessary default labels from switch statements Liam R. Howlett
2023-11-01 17:16 ` [PATCH 02/12] maple_tree: Make mas_erase() more robust Liam R. Howlett
2023-11-01 17:16 ` [PATCH 03/12] maple_tree: Move debug check to __mas_set_range() Liam R. Howlett
2023-11-01 17:16 ` [PATCH 04/12] maple_tree: Add end of node tracking to the maple state Liam R. Howlett
2023-11-01 17:16 ` [PATCH 05/12] maple_tree: Use cached node end in mas_next() Liam R. Howlett
2023-11-01 17:16 ` [PATCH 06/12] maple_tree: Use cached node end in mas_destroy() Liam R. Howlett
2023-11-01 17:16 ` [PATCH 07/12] maple_tree: Clean up inlines for some functions Liam R. Howlett
2023-11-01 17:16 ` [PATCH 08/12] maple_tree: Separate ma_state node from status Liam R. Howlett
2023-11-02  8:42   ` kernel test robot
2023-11-02 17:39     ` Liam R. Howlett
2023-11-06 15:41   ` [PATCH] maple_tree: Fix comments about MAS_* Liam R. Howlett
2023-11-06 15:45   ` [PATCH] maple_tree: Update forking to separate maple state and node Liam R. Howlett
2023-11-01 17:16 ` [PATCH 09/12] maple_tree: Remove mas_searchable() Liam R. Howlett
2023-11-01 17:16 ` [PATCH 10/12] maple_tree: Use maple state end for write operations Liam R. Howlett
2023-11-01 17:16 ` [PATCH 11/12] maple_tree: Don't find node end in mtree_lookup_walk() Liam R. Howlett
2023-11-01 17:16 ` Liam R. Howlett [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=20231101171629.3612299-13-Liam.Howlett@oracle.com \
    --to=liam.howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.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 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.