linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Vitaly Wool <vitaly.wool@konsulko.se>
To: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: "Liam R. Howlett" <Liam.Howlett@oracle.com>,
	linux-mm@kvack.org, akpm@linux-foundation.org,
	linux-kernel@vger.kernel.org, Uladzislau Rezki <urezki@gmail.com>,
	Danilo Krummrich <dakr@kernel.org>,
	Alice Ryhl <aliceryhl@google.com>,
	Vlastimil Babka <vbabka@suse.cz>,
	rust-for-linux@vger.kernel.org,
	Kent Overstreet <kent.overstreet@linux.dev>,
	linux-bcachefs@vger.kernel.org, bpf@vger.kernel.org,
	Herbert Xu <herbert@gondor.apana.org.au>,
	Jann Horn <jannh@google.com>, Pedro Falcato <pfalcato@suse.de>
Subject: Re: [PATCH v12 1/4] mm/vmalloc: allow to set node and align in vrealloc
Date: Thu, 10 Jul 2025 20:57:48 +0200	[thread overview]
Message-ID: <2D8A1A29-C847-479F-B732-A7CB13A46FA7@konsulko.se> (raw)
In-Reply-To: <aedc2b36-b3b0-4367-aa68-ba9f8a110b52@lucifer.local>



> On Jul 10, 2025, at 5:19 PM, Lorenzo Stoakes <lorenzo.stoakes@oracle.com> wrote:
> 
> On Thu, Jul 10, 2025 at 08:21:19AM +0200, Vitaly Wool wrote:
>> 
>> 
>>> On Jul 9, 2025, at 9:01 PM, Liam R. Howlett <Liam.Howlett@oracle.com> wrote:
>>> 
>>> * Vitaly Wool <vitaly.wool@konsulko.se <mailto:vitaly.wool@konsulko.se>> [250709 13:24]:
>>>> Reimplement vrealloc() to be able to set node and alignment should
>>>> a user need to do so. Rename the function to vrealloc_node_align()
>>>> to better match what it actually does now and introduce macros for
>>>> vrealloc() and friends for backward compatibility.
>>>> 
>>>> With that change we also provide the ability for the Rust part of
>>>> the kernel to set node and alignment in its allocations.
>>>> 
>>>> Signed-off-by: Vitaly Wool <vitaly.wool@konsulko.se>
>>>> Reviewed-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
>>>> Reviewed-by: Vlastimil Babka <vbabka@suse.cz>
>>>> ---
>>>> include/linux/vmalloc.h | 12 +++++++++---
>>>> mm/nommu.c              |  3 ++-
>>>> mm/vmalloc.c            | 31 ++++++++++++++++++++++++++-----
>>>> 3 files changed, 37 insertions(+), 9 deletions(-)
>>>> 
>>> ...
>>> 
>>>> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
>>>> index 6dbcdceecae1..03dd06097b25 100644
>>>> --- a/mm/vmalloc.c
>>>> +++ b/mm/vmalloc.c
>>>> @@ -4089,19 +4089,31 @@ void *vzalloc_node_noprof(unsigned long size, int node)
>>>> EXPORT_SYMBOL(vzalloc_node_noprof);
>>>> 
>>>> /**
>>>> - * vrealloc - reallocate virtually contiguous memory; contents remain unchanged
>>>> + * vrealloc_node_align_noprof - reallocate virtually contiguous memory; contents
>>>> + * remain unchanged
>>>> * @p: object to reallocate memory for
>>>> * @size: the size to reallocate
>>>> + * @align: requested alignment
>>>> * @flags: the flags for the page level allocator
>>>> + * @nid: node number of the target node
>>>> + *
>>>> + * If @p is %NULL, vrealloc_XXX() behaves exactly like vmalloc(). If @size is
>>>> + * 0 and @p is not a %NULL pointer, the object pointed to is freed.
>>>> *
>>>> - * If @p is %NULL, vrealloc() behaves exactly like vmalloc(). If @size is 0 and
>>>> - * @p is not a %NULL pointer, the object pointed to is freed.
>>>> + * if @nid is not NUMA_NO_NODE, this function will try to allocate memory on
>>>> + * the given node. If reallocation is not necessary (e. g. the new size is less
>>>> + * than the current allocated size), the current allocation will be preserved
>>>> + * unless __GFP_THISNODE is set. In the latter case a new allocation on the
>>>> + * requested node will be attempted.
> 
> Agreed with Liam, this is completely unreadable.
> 
> I think the numa node stuff is unnecesasry, that's pretty much inferred.
> 
> I'd just go with something like 'if the function can void having to reallocate
> then it does'.
> 
> Nice and simple :)

I think it is important to stress that the function is not always following the specified nid.
How about “If the caller wants the new memory to be on specific node *only*, __GFP_THISNODE flag should be set, otherwise the function will try to avoid reallocation and possibly disregard the specified @nid” ?

> 
>>> 
>>> I am having a very hard time understanding what you mean here.  What is
>>> the latter case?
>>> 
>>> If @nis is !NUMA_NO_NODE, the allocation will be attempted on the given
>>> node.  Then things sort of get confusing.  What is the latter case?
>> 
>> The latter case is __GFP_THISNODE present in flags. That’s the latest if-clause in this paragraph.
>>> 
>>>> *
>>>> * If __GFP_ZERO logic is requested, callers must ensure that, starting with the
>>>> * initial memory allocation, every subsequent call to this API for the same
>>>> * memory allocation is flagged with __GFP_ZERO. Otherwise, it is possible that
>>>> * __GFP_ZERO is not fully honored by this API.
>>>> *
>>>> + * If the requested alignment is bigger than the one the *existing* allocation
>>>> + * has, this function will fail.
>>>> + *
>>> 
>>> It might be better to say something like:
>>> Requesting an alignment that is bigger than the alignment of the
>>> *existing* allocation will fail.
>>> 
>> 
>> The whole function description in fact consists of several if-clauses (some of which are nested) so I am just following the pattern here.
> 
> Right, but in no sane world is essentially describing a series of if-clauses in
> a kerneldoc a thing.
> 
> Just it keep it simple, this is meant to be an overview, people can go read the
> code if they need details :)
> 
Alright, no strong feelings about it anyway. Will reword as you guys suggest.

Thanks,
Vitaly



  reply	other threads:[~2025-07-10 18:58 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-09 17:23 [PATCH v12 0/4] support large align and nid in Rust allocators Vitaly Wool
2025-07-09 17:24 ` [PATCH v12 1/4] mm/vmalloc: allow to set node and align in vrealloc Vitaly Wool
2025-07-09 19:01   ` Liam R. Howlett
2025-07-10  6:21     ` Vitaly Wool
2025-07-10 15:09       ` Liam R. Howlett
2025-07-10 15:19       ` Lorenzo Stoakes
2025-07-10 18:57         ` Vitaly Wool [this message]
2025-07-10 14:07     ` Vitaly Wool
2025-07-09 22:53   ` Alexei Starovoitov
2025-07-09 22:57     ` Danilo Krummrich
2025-07-09 23:14       ` Alexei Starovoitov
2025-07-09 23:26         ` Danilo Krummrich
2025-07-10  0:39           ` Alexei Starovoitov
2025-07-10  6:16             ` Vitaly Wool
2025-07-10  9:57             ` Danilo Krummrich
2025-07-09 17:24 ` [PATCH v12 2/4] mm/slub: allow to set node and align in k[v]realloc Vitaly Wool
2025-07-10  7:45   ` Vlastimil Babka
2025-07-11  8:58   ` Harry Yoo
2025-07-11 11:11     ` Kent Overstreet
2025-07-11 15:43     ` Vlastimil Babka
2025-07-12 12:43       ` Vitaly Wool
2025-07-14  8:14         ` Vlastimil Babka
2025-07-14 15:27           ` Vitaly Wool
2025-07-15  7:03           ` Alice Ryhl
2025-07-09 17:24 ` [PATCH v12 3/4] rust: add support for NUMA ids in allocations Vitaly Wool
2025-07-09 20:58   ` Danilo Krummrich
2025-07-09 17:25 ` [PATCH v12 4/4] rust: support large alignments " Vitaly Wool
2025-07-09 21:00   ` Danilo Krummrich

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=2D8A1A29-C847-479F-B732-A7CB13A46FA7@konsulko.se \
    --to=vitaly.wool@konsulko.se \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=aliceryhl@google.com \
    --cc=bpf@vger.kernel.org \
    --cc=dakr@kernel.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=jannh@google.com \
    --cc=kent.overstreet@linux.dev \
    --cc=linux-bcachefs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=pfalcato@suse.de \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=urezki@gmail.com \
    --cc=vbabka@suse.cz \
    /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