From: "Liam R. Howlett" <Liam.Howlett@Oracle.com>
To: Peng Zhang <zhangpeng.00@bytedance.com>
Cc: akpm@linux-foundation.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, maple-tree@lists.infradead.org
Subject: Re: [PATCH v3 4/4] maple_tree: add a fast path case in mas_wr_slot_store()
Date: Tue, 27 Jun 2023 10:45:13 -0400 [thread overview]
Message-ID: <20230627144513.fp5osnsqhn3rgvs3@revolver> (raw)
In-Reply-To: <20230615084301.97701-5-zhangpeng.00@bytedance.com>
* Peng Zhang <zhangpeng.00@bytedance.com> [230615 04:43]:
> When expanding a range in two directions, only partially overwriting the
> previous and next ranges, the number of entries will not be increased, so
> we can just update the pivots as a fast path. However, it may introduce
> potential risks in RCU mode (although it may pass the test), because it
> updates two pivots. We only enable it in non-RCU mode for now.
You've fixed the above test passing without the RCU bit set, so this
comment should be removed.
>
> Signed-off-by: Peng Zhang <zhangpeng.00@bytedance.com>
> ---
> lib/maple_tree.c | 36 ++++++++++++++++++++++++------------
> 1 file changed, 24 insertions(+), 12 deletions(-)
>
> diff --git a/lib/maple_tree.c b/lib/maple_tree.c
> index da4af6743b30..bff6531fd0bc 100644
> --- a/lib/maple_tree.c
> +++ b/lib/maple_tree.c
> @@ -4100,23 +4100,35 @@ static inline bool mas_wr_slot_store(struct ma_wr_state *wr_mas)
> {
> struct ma_state *mas = wr_mas->mas;
> unsigned char offset = mas->offset;
> + void __rcu **slots = wr_mas->slots;
> bool gap = false;
>
> - if (wr_mas->offset_end - offset != 1)
> - return false;
> -
> - gap |= !mt_slot_locked(mas->tree, wr_mas->slots, offset);
> - gap |= !mt_slot_locked(mas->tree, wr_mas->slots, offset + 1);
> + gap |= !mt_slot_locked(mas->tree, slots, offset);
> + gap |= !mt_slot_locked(mas->tree, slots, offset + 1);
>
> - if (mas->index == wr_mas->r_min) {
> - /* Overwriting the range and over a part of the next range. */
> - rcu_assign_pointer(wr_mas->slots[offset], wr_mas->entry);
> - wr_mas->pivots[offset] = mas->last;
> - } else {
> - /* Overwriting a part of the range and over the next range */
> - rcu_assign_pointer(wr_mas->slots[offset + 1], wr_mas->entry);
> + if (wr_mas->offset_end - offset == 1) {
> + if (mas->index == wr_mas->r_min) {
> + /* Overwriting the range and a part of the next one */
> + rcu_assign_pointer(slots[offset], wr_mas->entry);
> + wr_mas->pivots[offset] = mas->last;
> + } else {
> + /* Overwriting a part of the range and the next one */
> + rcu_assign_pointer(slots[offset + 1], wr_mas->entry);
> + wr_mas->pivots[offset] = mas->index - 1;
> + mas->offset++; /* Keep mas accurate. */
> + }
> + } else if (!mt_in_rcu(mas->tree)) {
> + /*
> + * Expand the range, only partially overwriting the previous and
> + * next ranges
> + */
> + gap |= !mt_slot_locked(mas->tree, slots, offset + 2);
> + rcu_assign_pointer(slots[offset + 1], wr_mas->entry);
> wr_mas->pivots[offset] = mas->index - 1;
> + wr_mas->pivots[offset + 1] = mas->last;
> mas->offset++; /* Keep mas accurate. */
> + } else {
> + return false;
> }
>
> trace_ma_write(__func__, mas, 0, wr_mas->entry);
> --
> 2.20.1
>
next prev parent reply other threads:[~2023-06-27 14:45 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-15 8:42 [PATCH v3 0/4] Optimize the fast path of mas_store() Peng Zhang
2023-06-15 8:42 ` [PATCH v3 1/4] maple_tree: add test for mas_wr_modify() fast path Peng Zhang
2023-06-15 8:42 ` [PATCH v3 2/4] maple_tree: add test for expanding range in RCU mode Peng Zhang
2023-06-15 8:43 ` [PATCH v3 3/4] maple_tree: optimize mas_wr_append(), also improve duplicating VMAs Peng Zhang
2023-06-15 8:43 ` [PATCH v3 4/4] maple_tree: add a fast path case in mas_wr_slot_store() Peng Zhang
2023-06-27 14:45 ` Liam R. Howlett [this message]
2023-06-25 4:04 ` [PATCH v3 0/4] Optimize the fast path of mas_store() Peng Zhang
2023-06-27 15:22 ` 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=20230627144513.fp5osnsqhn3rgvs3@revolver \
--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 \
--cc=zhangpeng.00@bytedance.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