linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Wei Yang <richard.weiyang@gmail.com>
To: "Liam R. Howlett" <Liam.Howlett@oracle.com>
Cc: richard.weiyang@gmail.com, akpm@linux-foundation.org,
	maple-tree@lists.infradead.org, linux-mm@kvack.org
Subject: Re: [PATCH 1/3] maple_tree: use ma_data_end() in mas_data_end()
Date: Wed, 4 Sep 2024 14:53:05 +0000	[thread overview]
Message-ID: <20240904145305.dq7jolrwd6fp6dmf@master> (raw)
In-Reply-To: <20240904075819.5vgnelkxxj7myyn4@master>

On Wed, Sep 04, 2024 at 07:58:19AM +0000, Wei Yang wrote:
[...]
>>It is only changing code for the sake of changing code.  And it looks
>>like it will be slower, or the same speed if we are lucky.  I have to
>>take time to verify things aren't slower or add subtle issues (maybe an
>>RCU race) because the code looked similar.  It's just not worth it.
>>
>
>I am trying to make the code more easy to read, but seems not helping.
>
>BTW, I found in mas_update_gap(), if (p_gap != max_gap), we would access
>the first parent, parent's type and its gap twice. Once in mas_update_gap()
>and once in mas_parent_gap().
>
>Do you think it worth a change to reduce one?
>

Liam,

I am trying to understand what kind code change you don't like. 

Is the following change worth?

diff --git a/lib/maple_tree.c b/lib/maple_tree.c
index 2b310dd3addf..e331d086eb7c 100644
--- a/lib/maple_tree.c
+++ b/lib/maple_tree.c
@@ -1595,32 +1595,33 @@ static inline unsigned long mas_max_gap(struct ma_state *mas)
 /*
  * mas_parent_gap() - Set the parent gap and any gaps above, as needed
  * @mas: The maple state
- * @offset: The gap offset in the parent to set
  * @new: The new gap value.
  *
  * Set the parent gap then continue to set the gap upwards, using the metadata
  * of the parent to see if it is necessary to check the node above.
  */
-static inline void mas_parent_gap(struct ma_state *mas, unsigned char offset,
-		unsigned long new)
+static inline void mas_parent_gap(struct ma_state *mas, unsigned long new)
 {
 	unsigned long meta_gap = 0;
 	struct maple_node *pnode;
-	struct maple_enode *penode;
+	struct maple_enode *enode = mas->node;
 	unsigned long *pgaps;
-	unsigned char meta_offset;
+	unsigned char offset, meta_offset;
 	enum maple_type pmt;
 
-	pnode = mte_parent(mas->node);
-	pmt = mas_parent_type(mas, mas->node);
-	penode = mt_mk_node(pnode, pmt);
+ascend:
+	pnode = mte_parent(enode);
+	pmt = mas_parent_type(mas, enode);
+	offset = mte_parent_slot(enode);
 	pgaps = ma_gaps(pnode, pmt);
 
-ascend:
 	MAS_BUG_ON(mas, pmt != maple_arange_64);
 	meta_offset = ma_meta_gap(pnode);
 	meta_gap = pgaps[meta_offset];
 
+	if (pgaps[offset] == new)
+		return;
+
 	pgaps[offset] = new;
 
 	if (meta_gap == new)
@@ -1640,11 +1641,7 @@ static inline void mas_parent_gap(struct ma_state *mas, unsigned char offset,
 		return;
 
 	/* Go to the parent node. */
-	pnode = mte_parent(penode);
-	pmt = mas_parent_type(mas, penode);
-	pgaps = ma_gaps(pnode, pmt);
-	offset = mte_parent_slot(penode);
-	penode = mt_mk_node(pnode, pmt);
+	enode = mt_mk_node(pnode, pmt);
 	goto ascend;
 }
 
@@ -1654,24 +1651,13 @@ static inline void mas_parent_gap(struct ma_state *mas, unsigned char offset,
  */
 static inline void mas_update_gap(struct ma_state *mas)
 {
-	unsigned char pslot;
-	unsigned long p_gap;
-	unsigned long max_gap;
-
 	if (!mt_is_alloc(mas->tree))
 		return;
 
 	if (mte_is_root(mas->node))
 		return;
 
-	max_gap = mas_max_gap(mas);
-
-	pslot = mte_parent_slot(mas->node);
-	p_gap = ma_gaps(mte_parent(mas->node),
-			mas_parent_type(mas, mas->node))[pslot];
-
-	if (p_gap != max_gap)
-		mas_parent_gap(mas, pslot, max_gap);
+	mas_parent_gap(mas, mas_max_gap(mas));
 }
 
 /*
-- 
2.34.1

-- 
Wei Yang
Help you, Help me


  reply	other threads:[~2024-09-04 14:53 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-31  0:10 Wei Yang
2024-08-31  0:10 ` [PATCH 2/3] maple_tree: use mas_safe_pivot() to get the pivot range Wei Yang
2024-09-04  0:41   ` Liam R. Howlett
2024-09-04  8:01     ` Wei Yang
2024-08-31  0:10 ` [PATCH 3/3] maple_tree: local variable 'count' is not necessary Wei Yang
2024-09-04  0:42   ` Liam R. Howlett
2024-09-03 16:12 ` [PATCH 1/3] maple_tree: use ma_data_end() in mas_data_end() Liam R. Howlett
2024-09-04  0:15   ` Wei Yang
2024-09-04  2:25     ` Liam R. Howlett
2024-09-04  7:58       ` Wei Yang
2024-09-04 14:53         ` Wei Yang [this message]
2024-09-05 20:13           ` Liam R. Howlett
2024-09-06  3:44             ` Wei Yang
2024-09-11 23:15               ` Wei Yang
2024-09-13 14:13                 ` Liam R. Howlett
2024-09-14  0:50                   ` Wei Yang

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=20240904145305.dq7jolrwd6fp6dmf@master \
    --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