[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <628e8c0d-2bc5-4cc8-893a-0b8388ba98f9@suse.cz>
Date: Tue, 8 Jul 2025 14:12:20 +0200
From: Vlastimil Babka <vbabka@...e.cz>
To: Vitaly Wool <vitaly.wool@...sulko.se>, linux-mm@...ck.org
Cc: akpm@...ux-foundation.org, linux-kernel@...r.kernel.org,
Uladzislau Rezki <urezki@...il.com>, Danilo Krummrich <dakr@...nel.org>,
Alice Ryhl <aliceryhl@...gle.com>, rust-for-linux@...r.kernel.org
Subject: Re: [PATCH v11 1/4] mm/vmalloc: allow to set node and align in
vrealloc
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@...sulko.se>
> Reviewed-by: Uladzislau Rezki (Sony) <urezki@...il.com>
Reviewed-by: Vlastimil Babka <vbabka@...e.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;
>
Powered by blists - more mailing lists