From: Wei Yang <richard.weiyang@gmail.com>
To: Sidhartha Kumar <sidhartha.kumar@oracle.com>
Cc: Wei Yang <richard.weiyang@gmail.com>,
linux-kernel@vger.kernel.org, maple-tree@lists.infradead.org,
linux-mm@kvack.org, akpm@linux-foundation.org,
liam.howlett@oracle.com
Subject: Re: [PATCH 3/5] maple_tree: use vacant nodes to reduce worst case allocations
Date: Sat, 16 Nov 2024 01:41:16 +0000 [thread overview]
Message-ID: <20241116014116.a7am7z4p7k33rkl5@master> (raw)
In-Reply-To: <2aa439f1-d33d-43ee-9945-5ac570506c7e@oracle.com>
On Fri, Nov 15, 2024 at 03:34:55PM -0500, Sidhartha Kumar wrote:
>On 11/15/24 2:52 AM, Wei Yang wrote:
>> On Thu, Nov 14, 2024 at 12:05:22PM -0500, Sidhartha Kumar wrote:
>> > In order to determine the store type for a maple tree operation, a walk
>> > of the tree is done through mas_wr_walk(). This function descends the
>> > tree until a spanning write is detected or we reach a leaf node. While
>> > descending, keep track of the height at which we encounter a node with
>> > available space. This is done by checking if mas->end is less than the
>> > number of slots a given node type can fit.
>> >
>> > Now that the height of the vacant node is tracked, we can use the
>> > difference between the height of the tree and the height of the vacant
>> > node to know how many levels we will have to propagate creating new
>> > nodes. Update mas_prealloc_calc() to consider the vacant height and
>> > reduce the number of worst allocations.
>> >
>> > Rebalancing stores are not supported and fall back to using the full
>> > height of the tree for allocations.
>> >
>> > Update preallocation testing assertions to take into account vacant
>> > height.
>> >
>> > Signed-off-by: Sidhartha <sidhartha.kumar@oracle.com>
>> > ---
>> > include/linux/maple_tree.h | 2 +
>> > lib/maple_tree.c | 13 +++--
>> > tools/testing/radix-tree/maple.c | 97 +++++++++++++++++++++++++++++---
>> > 3 files changed, 100 insertions(+), 12 deletions(-)
>> >
>> > diff --git a/include/linux/maple_tree.h b/include/linux/maple_tree.h
>> > index cbbcd18d4186..7d777aa2d9ed 100644
>> > --- a/include/linux/maple_tree.h
>> > +++ b/include/linux/maple_tree.h
>> > @@ -463,6 +463,7 @@ struct ma_wr_state {
>> > void __rcu **slots; /* mas->node->slots pointer */
>> > void *entry; /* The entry to write */
>> > void *content; /* The existing entry that is being overwritten */
>> > + unsigned char vacant_height; /* Depth of lowest node with free space */
>> ^^^ ^^^
>>
>> Would this be a little misleading?
>>
>
>Could you elaborate on how its misleading?
>
As you mentioned in previous patch, depth and height has different meaning.
Root node has depth of 0 and height of 1. So I may wandering whether this is
depth or height.
>> > };
>> >
>> > #define mas_lock(mas) spin_lock(&((mas)->tree->ma_lock))
>> > @@ -498,6 +499,7 @@ struct ma_wr_state {
>> > .mas = ma_state, \
>> > .content = NULL, \
>> > .entry = wr_entry, \
>> > + .vacant_height = 0 \
>> > }
>> >
>> > #define MA_TOPIARY(name, tree) \
>> > diff --git a/lib/maple_tree.c b/lib/maple_tree.c
>> > index 21289e350382..f14d70c171c2 100644
>> > --- a/lib/maple_tree.c
>> > +++ b/lib/maple_tree.c
>> > @@ -3545,6 +3545,9 @@ static bool mas_wr_walk(struct ma_wr_state *wr_mas)
>> > if (ma_is_leaf(wr_mas->type))
>> > return true;
>> >
>> > + if (mas->end < mt_slots[wr_mas->type] - 1)
>> > + wr_mas->vacant_height = mas->depth + 1;
>>
>> For some cases in rebalance, we may split data into three parts, which means
>> we need 2 extra vacant slot.
>>
>> Maybe this check is not accurate?
>>
>
>The triple split scenario which you are describing comes from the spanning
>store case not on the wr_rebalance case. There is a check before we set
>vacant height to return if is_span_wr() so I believe this is correct still.
>
Hmm... I come up with a case in which vacant_height may not high enough.
Here is the subtree where spanning write locates. The first level is the
parent node of the second level nodes.
vacant node
+--------+-+-+-------+
| |l|r| |
+--------+-+-+-------+
l r
+------+ +----+-------+ +---------+--+ +------+
| | | | | | | | | |
+------+ +----+-------+ +---------+--+ +------+
^ ^
| |
index last
When mas_wr_walk_descend() to node l, mas_is_span_wr() return true since last
is in the right sibling, node r. Let's say the parent is vacant and l/r is
leaf. So the request number is (1 * 3) + 1.
Let's assume:
* vacant node is just sufficient
* l's left part + r's right part is sufficient but not overflow
Then the "new vacant node" would be deficient and needs another round
rebalance.
For this case, I am afraid it doesn't allocate enough nodes. Or I
misunderstand this?
--
Wei Yang
Help you, Help me
next prev parent reply other threads:[~2024-11-16 1:41 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-14 17:05 [PATCH 0/5] Track node vacancy to reduce worst case allocation counts Sidhartha Kumar
2024-11-14 17:05 ` [PATCH 1/5] maple_tree: convert mas_prealloc_calc() to take in a maple write state Sidhartha Kumar
2024-11-14 17:05 ` [PATCH 2/5] maple_tree: use height and depth consistently Sidhartha Kumar
2024-11-14 17:05 ` [PATCH 3/5] maple_tree: use vacant nodes to reduce worst case allocations Sidhartha Kumar
2024-11-15 7:52 ` Wei Yang
2024-11-15 20:34 ` Sidhartha Kumar
2024-11-16 1:41 ` Wei Yang [this message]
2024-11-18 16:36 ` Sidhartha Kumar
2024-11-19 2:30 ` Wei Yang
2024-11-19 14:15 ` Liam R. Howlett
2024-11-14 17:05 ` [PATCH 4/5] maple_tree: break on convergence in mas_spanning_rebalance() Sidhartha Kumar
2024-11-15 7:14 ` Wei Yang
2024-11-14 17:05 ` [PATCH 5/5] maple_tree: add sufficient height Sidhartha Kumar
2024-11-14 21:39 ` [PATCH 0/5] Track node vacancy to reduce worst case allocation counts Sid Kumar
2024-11-19 9:59 ` Wei Yang
2024-11-26 19:32 ` Sidhartha Kumar
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=20241116014116.a7am7z4p7k33rkl5@master \
--to=richard.weiyang@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=liam.howlett@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=maple-tree@lists.infradead.org \
--cc=sidhartha.kumar@oracle.com \
/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