All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peng Zhang <zhangpeng.00@bytedance.com>
To: Sidhartha Kumar <sidhartha.kumar@oracle.com>
Cc: akpm@linux-foundation.org, willy@infradead.org,
	liam.howlett@oracle.com, linux-kernel@vger.kernel.org,
	maple-tree@lists.infradead.org, linux-mm@kvack.org,
	Peng Zhang <zhangpeng.00@bytedance.com>
Subject: Re: [PATCH 2/3] maple_tree: use preallocations in mas_store_gfp()
Date: Wed, 11 Oct 2023 15:40:17 +0800	[thread overview]
Message-ID: <3342fd24-84f5-430f-8900-fd2d8ddae639@bytedance.com> (raw)
In-Reply-To: <205f093a-8b43-5b3b-7e87-2dcbe434f519@oracle.com>



在 2023/10/11 08:17, Sidhartha Kumar 写道:
> On 10/9/23 8:03 PM, Peng Zhang wrote:
>> Hi,
>>
>> 在 2023/10/10 04:16, Sidhartha Kumar 写道:
>>> Preallocate maple nodes before call to mas_wr_store_entry(). If a new
>>> node is not needed, go directly to mas_wr_store_entry(), otherwise
>>> allocate the needed nodes and set the MA_STATE_PREALLOC flag.
>>>
>>> Signed-off-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
>>> ---
>>>   lib/maple_tree.c | 22 +++++++++++++++++++---
>>>   1 file changed, 19 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/lib/maple_tree.c b/lib/maple_tree.c
>>> index e239197a57fc..25ae66e585f4 100644
>>> --- a/lib/maple_tree.c
>>> +++ b/lib/maple_tree.c
>>> @@ -5478,17 +5478,33 @@ int mas_prealloc_calc(struct ma_wr_state *wr_mas)
>>>   int mas_store_gfp(struct ma_state *mas, void *entry, gfp_t gfp)
>>>   {
>>>       MA_WR_STATE(wr_mas, mas, entry);
>>> +    int request;
>>>       mas_wr_store_setup(&wr_mas);
>>> -    trace_ma_write(__func__, mas, 0, entry);
>>> -retry:
>>> +    wr_mas.content = mas_start(mas);
>>> +
>>> +    request = mas_prealloc_calc(&wr_mas);
>> mas_wr_store_entry() does something similar to mas_prealloc_calc().
>> Now, making it do it twice would incur additional overhead.
>> We encountered this issue while optimizing preallocation, but it
>> hasn't been resolved yet. Previously, this problem only occurred
>> when using mas_preallocate(). Now, this change would bring this
>> impact to all write operations on maple tree. What do you think
>> about it?
>>
> 
> After talking to Liam, I will have to implement the store type enum feature on the Maple Tree Work list so that mas_prealloc_calc() can start a partial walk and write that information to the enum. mas_wr_store_entry() can then read that enum to continue the walk that was already started rather than having to redo the whole walk. This could also be used in mas_preallocate(). Do you have any suggestions for the implementation of this enum?
There is another scenario where this enum can be useful,
as seen in the implementation of mas_replace_entry() in [1].
It is a faster alternative to mas_store(), but it is not safe.
If we can determine through the enum while writing the maple
tree that a faster write operation can be performed, it would
be beneficial. Some performance improvements can also be
observed in [1].

[1] https://lore.kernel.org/lkml/49f0181a-55a4-41aa-8596-877560c8b802@bytedance.com/
> 
> Thanks,
> Sid
> 
>> Thanks,
>> Peng
>>> +    if (!request)
>>> +        goto store_entry;
>>> +
>>> +    mas_node_count_gfp(mas, request, gfp);
>>> +    if (unlikely(mas_is_err(mas))) {
>>> +        mas_set_alloc_req(mas, 0);
>>> +        mas_destroy(mas);
>>> +        mas_reset(mas);
>>> +        return xa_err(mas->node);
>>> +    }
>>> +    mas->mas_flags |= MA_STATE_PREALLOC;
>>> +
>>> +store_entry:
>>>       mas_wr_store_entry(&wr_mas);
>>>       if (unlikely(mas_nomem(mas, gfp)))
>>> -        goto retry;
>>> +        goto store_entry;
>>>       if (unlikely(mas_is_err(mas)))
>>>           return xa_err(mas->node);
>>> +    trace_ma_write(__func__, mas, 0, entry);
>>>       return 0;
>>>   }
>>>   EXPORT_SYMBOL_GPL(mas_store_gfp);
>>
> 
> 

  reply	other threads:[~2023-10-11  7:40 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-09 20:16 [PATCH 0/3] align maple tree write paths Sidhartha Kumar
2023-10-09 20:16 ` [PATCH 1/3] maple_tree: introduce mas_prealloc_calc() Sidhartha Kumar
2023-10-09 22:25   ` kernel test robot
2023-10-10 22:13     ` Sidhartha Kumar
2023-10-10 11:06   ` kernel test robot
2023-10-18  2:53   ` kernel test robot
2023-10-09 20:16 ` [PATCH 2/3] maple_tree: use preallocations in mas_store_gfp() Sidhartha Kumar
2023-10-10  3:03   ` Peng Zhang
2023-10-11  0:17     ` Sidhartha Kumar
2023-10-11  7:40       ` Peng Zhang [this message]
2023-10-10 18:15   ` Liam R. Howlett
2023-10-25  9:52   ` kernel test robot
2023-10-26 17:16     ` Liam R. Howlett
2023-10-27  5:59       ` Oliver Sang
2023-11-01 16:59         ` Liam R. Howlett
2023-11-03  2:37           ` Oliver Sang
2023-10-09 20:16 ` [PATCH 3/3] maple_tree: use preallocations in mas_erase() 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=3342fd24-84f5-430f-8900-fd2d8ddae639@bytedance.com \
    --to=zhangpeng.00@bytedance.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 \
    --cc=willy@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.