linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Vlastimil Babka <vbabka@suse.cz>
To: Vitaly Wool <vitaly.wool@konsulko.se>, linux-mm@kvack.org
Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org,
	Uladzislau Rezki <urezki@gmail.com>,
	Danilo Krummrich <dakr@kernel.org>,
	Alice Ryhl <aliceryhl@google.com>,
	rust-for-linux@vger.kernel.org
Subject: Re: [PATCH v11 1/4] mm/vmalloc: allow to set node and align in vrealloc
Date: Tue, 8 Jul 2025 14:12:20 +0200	[thread overview]
Message-ID: <628e8c0d-2bc5-4cc8-893a-0b8388ba98f9@suse.cz> (raw)
In-Reply-To: <20250707164843.631434-1-vitaly.wool@konsulko.se>

On 7/7/25 18:48, Vitaly Wool wrote:
> 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>

Nit:

> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
> @@ -4089,13 +4089,22 @@ 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.
>   *
>   * 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
> @@ -4111,7 +4120,8 @@ EXPORT_SYMBOL(vzalloc_node_noprof);
>   * Return: pointer to the allocated memory; %NULL if @size is zero or in case of
>   *         failure
>   */
> -void *vrealloc_noprof(const void *p, size_t size, gfp_t flags)
> +void *vrealloc_node_align_noprof(const void *p, size_t size, unsigned long align,
> +				 gfp_t flags, int nid)
>  {
>  	struct vm_struct *vm = NULL;
>  	size_t alloced_size = 0;
> @@ -4135,6 +4145,12 @@ void *vrealloc_noprof(const void *p, size_t size, gfp_t flags)
>  		if (WARN(alloced_size < old_size,
>  			 "vrealloc() has mismatched area vs requested sizes (%p)\n", p))
>  			return NULL;
> +		if (WARN(!IS_ALIGNED((unsigned long)p, align),
> +			 "will not reallocate with a bigger alignment (0x%lx)\n", align))
> +			return NULL;

Maybe this should be mentioned in the doc comment above?

> +		if (unlikely(flags & __GFP_THISNODE) && nid != NUMA_NO_NODE &&
> +			     nid != page_to_nid(vmalloc_to_page(p)))
> +			goto need_realloc;
>  	}
>  
>  	/*
> @@ -4165,8 +4181,10 @@ void *vrealloc_noprof(const void *p, size_t size, gfp_t flags)
>  		return (void *)p;
>  	}
>  
> +need_realloc:
>  	/* TODO: Grow the vm_area, i.e. allocate and map additional pages. */
> -	n = __vmalloc_noprof(size, flags);
> +	n = __vmalloc_node_noprof(size, align, flags, nid, __builtin_return_address(0));
> +
>  	if (!n)
>  		return NULL;
>  



  reply	other threads:[~2025-07-08 12:12 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-07 16:47 [PATCH v11 0/4] support large align and nid in Rust allocators Vitaly Wool
2025-07-07 16:48 ` [PATCH v11 1/4] mm/vmalloc: allow to set node and align in vrealloc Vitaly Wool
2025-07-08 12:12   ` Vlastimil Babka [this message]
2025-07-07 16:49 ` [PATCH v11 2/4] mm/slub: allow to set node and align in k[v]realloc Vitaly Wool
2025-07-08 12:52   ` Vlastimil Babka
2025-07-08 14:03     ` Vitaly Wool
2025-07-09 13:40       ` Vitaly Wool
2025-07-09 14:13         ` Vlastimil Babka
2025-07-07 16:49 ` [PATCH v11 3/4] rust: add support for NUMA ids in allocations Vitaly Wool
2025-07-08 12:15   ` Danilo Krummrich
2025-07-07 16:49 ` [PATCH v11 4/4] rust: support large alignments " Vitaly Wool
2025-07-08 12:16   ` Danilo Krummrich
2025-07-08 10:58 ` [PATCH v11 0/4] support large align and nid in Rust allocators Lorenzo Stoakes
2025-07-08 11:12   ` Lorenzo Stoakes
2025-07-08 11:55   ` Danilo Krummrich
2025-07-08 12:36     ` Lorenzo Stoakes
2025-07-08 13:41       ` Danilo Krummrich
2025-07-08 14:06         ` Lorenzo Stoakes
2025-07-08 13:19     ` Lorenzo Stoakes
2025-07-08 14:16       ` Danilo Krummrich
2025-07-08 14:39         ` Lorenzo Stoakes
2025-07-08 15:11           ` Danilo Krummrich
2025-07-08 15:40             ` Lorenzo Stoakes
2025-07-09 11:31       ` Alice Ryhl
2025-07-09 12:24         ` Lorenzo Stoakes

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=628e8c0d-2bc5-4cc8-893a-0b8388ba98f9@suse.cz \
    --to=vbabka@suse.cz \
    --cc=akpm@linux-foundation.org \
    --cc=aliceryhl@google.com \
    --cc=dakr@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=urezki@gmail.com \
    --cc=vitaly.wool@konsulko.se \
    /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;
as well as URLs for NNTP newsgroup(s).