From nobody Wed Oct 8 16:08:18 2025 Received: from mailrelay4-3.pub.mailoutpod3-cph3.one.com (mailrelay4-3.pub.mailoutpod3-cph3.one.com [46.30.212.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9D17225F964 for ; Thu, 26 Jun 2025 08:36:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.30.212.3 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750926990; cv=none; b=SlB1bzxAwuty6yk+KCvOBrM/Y3GyyiCkhoaoTkNygnLKhvl8ym8xMfPxyQ5aogpjA4nll6PKv9HaQ7pvq9l+xLelCQJvGttSa751dOSEc3xwmgaYvZ8wPPDsqgbOZ67vMkQSkEFup+6Wd5O5mMvC49XfjIO9jJLGNvZLnKo+OYI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750926990; c=relaxed/simple; bh=gQn4VmqsD0HYtYPDRubHPhoNsnIoIExefHu5TFwwrKk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=I2xXY64SWyEP7ZnRSpj4+bi6JMmeU+ycNr6MnRwRQvSshxDKwjP1nRcPUOHgmcYFrRvuiCBun7CZrI8zsSIhJEPJlqPIsoUjaNHQ3WalREkvpEUAl/RtUGmCRvHF/uiuSMRHJkbtwCGcDiA3rkNK1dVIff7RUWH5AbHl20/ltY0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=konsulko.se; spf=none smtp.mailfrom=konsulko.se; dkim=pass (2048-bit key) header.d=konsulko.se header.i=@konsulko.se header.b=cn5kbwdr; dkim=permerror (0-bit key) header.d=konsulko.se header.i=@konsulko.se header.b=ioaMVepK; arc=none smtp.client-ip=46.30.212.3 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=konsulko.se Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=konsulko.se Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=konsulko.se header.i=@konsulko.se header.b="cn5kbwdr"; dkim=permerror (0-bit key) header.d=konsulko.se header.i=@konsulko.se header.b="ioaMVepK" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1750926980; x=1751531780; d=konsulko.se; s=rsa1; h=content-transfer-encoding:mime-version:references:in-reply-to:message-id:date: subject:cc:to:from:from; bh=mkYpvclAYF6uZDEKl93atoHVzEINRICyZlGgMsyMSN8=; b=cn5kbwdrF0U0ijbydoKjcGWYj45rESCFlARBFb3a3xk5AeytbkLXtpXygHIvf+GHnFgyry4H/E8Y/ xa4ralAXWUP6A/CaZV2FHo372ysJfkKEB3JEjlOue5PyXGb9aPlmH5MbOLtrmvSeYZ56CzM/IK6eUv siz7vAWhL/TZRX1bxFAWJCuDwUu6l4v8UshLbqzXQumX51vXO2qt4foDLN0oBPkfc5Mb9f2355CIHl pBvlEekquW7MbiOgGNqfZufFOMp+dRrEhAKob6snl06Pahd9At3Gt1Dv8SYa2CbHn12U+Iip7rjlGz XYHEOZwE51SJ++/fOk0KxyHedYLA6vA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1750926980; x=1751531780; d=konsulko.se; s=ed1; h=content-transfer-encoding:mime-version:references:in-reply-to:message-id:date: subject:cc:to:from:from; bh=mkYpvclAYF6uZDEKl93atoHVzEINRICyZlGgMsyMSN8=; b=ioaMVepK/VgZgirl2GI14/87I/2Zw/jDC/YpwE31muFRDbDmhjKabDOkOwivvYa28cZkBVI+JPEim CtS1W+ZAg== X-HalOne-ID: a129904f-5268-11f0-9ab1-29b2d794c87d Received: from localhost.localdomain (host-90-238-19-233.mobileonline.telia.com [90.238.19.233]) by mailrelay4.pub.mailoutpod3-cph3.one.com (Halon) with ESMTPSA id a129904f-5268-11f0-9ab1-29b2d794c87d; Thu, 26 Jun 2025 08:36:20 +0000 (UTC) From: Vitaly Wool To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org, Uladzislau Rezki , Danilo Krummrich , Alice Ryhl , rust-for-linux@vger.kernel.org, Vitaly Wool Subject: [PATCHi v4 1/4] mm/vmalloc: allow to set node and align in vrealloc Date: Thu, 26 Jun 2025 10:36:17 +0200 Message-Id: <20250626083617.3596326-1-vitaly.wool@konsulko.se> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20250626083516.3596197-1-vitaly.wool@konsulko.se> References: <20250626083516.3596197-1-vitaly.wool@konsulko.se> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Reimplement vrealloc() to be able to set node and alignment should a user need to do so. Rename the function to vrealloc_node() to better match what it actually does now and introduce a macro for vrealloc() for backward compatibility. With that change we also provide the ability for the Rust part of the kernel to set node and aligmnent in its allocations. Signed-off-by: Vitaly Wool Reviewed-by: "Uladzislau Rezki (Sony)" --- include/linux/vmalloc.h | 8 +++++--- mm/nommu.c | 3 ++- mm/vmalloc.c | 16 +++++++++++++--- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h index fdc9aeb74a44..7d5251287687 100644 --- a/include/linux/vmalloc.h +++ b/include/linux/vmalloc.h @@ -197,9 +197,11 @@ extern void *__vcalloc_noprof(size_t n, size_t size, g= fp_t flags) __alloc_size(1 extern void *vcalloc_noprof(size_t n, size_t size) __alloc_size(1, 2); #define vcalloc(...) alloc_hooks(vcalloc_noprof(__VA_ARGS__)) =20 -void * __must_check vrealloc_noprof(const void *p, size_t size, gfp_t flag= s) - __realloc_size(2); -#define vrealloc(...) alloc_hooks(vrealloc_noprof(__VA_ARGS__)) +void *__must_check vrealloc_node_noprof(const void *p, size_t size, + unsigned long align, gfp_t flags, int nid) __realloc_size(2); +#define vrealloc_noprof(p, s, f) vrealloc_node_noprof(p, s, 1, f, NUMA_NO_= NODE) +#define vrealloc_node(...) alloc_hooks(vrealloc_node_noprof(__VA_ARGS__)) +#define vrealloc(...) alloc_hooks(vrealloc_noprof(__VA_ARGS__)) =20 extern void vfree(const void *addr); extern void vfree_atomic(const void *addr); diff --git a/mm/nommu.c b/mm/nommu.c index 87e1acab0d64..6cec05c3312c 100644 --- a/mm/nommu.c +++ b/mm/nommu.c @@ -119,7 +119,8 @@ void *__vmalloc_noprof(unsigned long size, gfp_t gfp_ma= sk) } EXPORT_SYMBOL(__vmalloc_noprof); =20 -void *vrealloc_noprof(const void *p, size_t size, gfp_t flags) +void *vrealloc_node_noprof(const void *p, size_t size, unsigned long align, + gfp_t flags, int nid) { return krealloc_noprof(p, size, (flags | __GFP_COMP) & ~__GFP_HIGHMEM); } diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 6dbcdceecae1..412bf5b8d3ff 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -4089,10 +4089,12 @@ void *vzalloc_node_noprof(unsigned long size, int n= ode) EXPORT_SYMBOL(vzalloc_node_noprof); =20 /** - * vrealloc - reallocate virtually contiguous memory; contents remain unch= anged + * vrealloc_node - 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 id * * 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. @@ -4111,7 +4113,7 @@ EXPORT_SYMBOL(vzalloc_node_noprof); * Return: pointer to the allocated memory; %NULL if @size is zero or in c= ase of * failure */ -void *vrealloc_noprof(const void *p, size_t size, gfp_t flags) +void *vrealloc_node_noprof(const void *p, size_t size, unsigned long align= , gfp_t flags, int nid) { struct vm_struct *vm =3D NULL; size_t alloced_size =3D 0; @@ -4135,6 +4137,13 @@ void *vrealloc_noprof(const void *p, size_t size, gf= p_t flags) if (WARN(alloced_size < old_size, "vrealloc() has mismatched area vs requested sizes (%p)\n", p)) return NULL; + if (WARN(nid !=3D NUMA_NO_NODE && nid !=3D page_to_nid(vmalloc_to_page(p= )), + "vrealloc() has mismatched nids\n")) + return NULL; + if (WARN((uintptr_t)p & (align - 1), + "will not reallocate with a bigger alignment (0x%lx)\n", + align)) + return NULL; } =20 /* @@ -4166,7 +4175,8 @@ void *vrealloc_noprof(const void *p, size_t size, gfp= _t flags) } =20 /* TODO: Grow the vm_area, i.e. allocate and map additional pages. */ - n =3D __vmalloc_noprof(size, flags); + n =3D __vmalloc_node_noprof(size, align, flags, nid, __builtin_return_add= ress(0)); + if (!n) return NULL; =20 --=20 2.39.2 From nobody Wed Oct 8 16:08:18 2025 Received: from mailrelay-egress12.pub.mailoutpod2-cph3.one.com (mailrelay-egress12.pub.mailoutpod2-cph3.one.com [46.30.211.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4A673293C7C for ; Thu, 26 Jun 2025 08:36:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.30.211.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750927000; cv=none; b=dfkn9oKWsBjVSe/k4DFVWyixkISk1KMffObrbb1zotoEoUTq6kkWuNF6/lFJzqd/PZh4vqaFpPHW+QF8yvQipstZDDcqz67tfD+v2AO0lnNDX854Pkfv4jBLfO/dkMYimaqn3e8/7XEeuuSo630wx6mxdvvj0SAtQZPQPQrScPc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750927000; c=relaxed/simple; bh=7YJuPkik1KBD4lbPP0cuZ1cG07RJnRRNZjS8MiZCo2w=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=eTa1BiiaRHDYK6MOZ01zM+DMUI294PRpuz5rmt0t1yLpUUUjaTF0u+qQ0DIH7Q7fMlpLzuRuPyyONKh4iTMo7CbcgDLC0syCKWueDiDxDM0ZNhyerEx2qK8saIQeXsJQraypwVVZQUp8c8E4ABzntnjvKqla+LgFnIzszhK55pU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=konsulko.se; spf=none smtp.mailfrom=konsulko.se; dkim=pass (2048-bit key) header.d=konsulko.se header.i=@konsulko.se header.b=MaS7+d3L; dkim=permerror (0-bit key) header.d=konsulko.se header.i=@konsulko.se header.b=qnY2tAg/; arc=none smtp.client-ip=46.30.211.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=konsulko.se Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=konsulko.se Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=konsulko.se header.i=@konsulko.se header.b="MaS7+d3L"; dkim=permerror (0-bit key) header.d=konsulko.se header.i=@konsulko.se header.b="qnY2tAg/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1750926995; x=1751531795; d=konsulko.se; s=rsa1; h=content-transfer-encoding:mime-version:references:in-reply-to:message-id:date: subject:cc:to:from:from; bh=Q5e5J6xYEr32Saw5MlCRa9dyPVfRH3gV92WpTITaL6o=; b=MaS7+d3L0+J4gcShT3GTbAbNh5ouzKp+jOaPmM0g+E+7fLZVh6GgLfaeu+UosCXCzM9R0y8gixXA4 eNfqL+pMtCT6Pj+vfp5hcRW2RyZX9DXhO5iq+KDhMiWNQUE4yTsuqIyagAgWW5gsWsXMVIXBVsIHEw lL7alYl0yFc4kW4E3zCaI7k7PQhS6onHggDC446DlYqAUo7VLRU/hRt2BM3BubhtVGJWzPRjzEU9ts CbOB5SxwUOKyIBTsHrqQNe8RuBby/DA8uiPVFxCojeZcxXXN/B7F6gGzs+GPAU8svugc+JxVasZFAw Nb2GeCwPgU4K5jRrij+MJ3uq7qC3iWQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1750926995; x=1751531795; d=konsulko.se; s=ed1; h=content-transfer-encoding:mime-version:references:in-reply-to:message-id:date: subject:cc:to:from:from; bh=Q5e5J6xYEr32Saw5MlCRa9dyPVfRH3gV92WpTITaL6o=; b=qnY2tAg/vZxKCqbs9EOFAShQHto+WqH5SYbgnc7coU/nZHRzgBwuwh6CbUt4Abl7Jj1kEKetkd4gI v6O2GoJCg== X-HalOne-ID: a964cd49-5268-11f0-9a7d-4f541c8bf1cc Received: from localhost.localdomain (host-90-238-19-233.mobileonline.telia.com [90.238.19.233]) by mailrelay3.pub.mailoutpod2-cph3.one.com (Halon) with ESMTPSA id a964cd49-5268-11f0-9a7d-4f541c8bf1cc; Thu, 26 Jun 2025 08:36:34 +0000 (UTC) From: Vitaly Wool To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org, Uladzislau Rezki , Danilo Krummrich , Alice Ryhl , rust-for-linux@vger.kernel.org, Vitaly Wool Subject: [PATCH v4 2/4] mm/slub: allow to set node and align in k[v]realloc Date: Thu, 26 Jun 2025 10:36:32 +0200 Message-Id: <20250626083632.3596363-1-vitaly.wool@konsulko.se> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20250626083516.3596197-1-vitaly.wool@konsulko.se> References: <20250626083516.3596197-1-vitaly.wool@konsulko.se> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Reimplement k[v]realloc() to be able to set node and alignment should a user need to do so. Rename the respective functions to k[v]realloc_node() to better match what they actually do now and introduce macros for k[v]realloc() for backward compatibility. With that change we also provide the ability for the Rust part of the kernel to set node and aligmnent in its K[v]xxx [re]allocations. Signed-off-by: Vitaly Wool --- include/linux/slab.h | 12 ++++++++---- mm/slub.c | 33 ++++++++++++++++++++++----------- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/include/linux/slab.h b/include/linux/slab.h index d5a8ab98035c..119f100978c8 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -465,9 +465,11 @@ int kmem_cache_shrink(struct kmem_cache *s); /* * Common kmalloc functions provided by all allocators */ -void * __must_check krealloc_noprof(const void *objp, size_t new_size, - gfp_t flags) __realloc_size(2); -#define krealloc(...) alloc_hooks(krealloc_noprof(__VA_ARGS__)) +void * __must_check krealloc_node_noprof(const void *objp, size_t new_size, + gfp_t flags, int nid) __realloc_size(2); +#define krealloc_node(...) alloc_hooks(krealloc_node_noprof(__VA_ARGS__)) +#define krealloc_noprof(o, s, f) krealloc_node_noprof(o, s, f, NUMA_NO_NOD= E) +#define krealloc(...) alloc_hooks(krealloc_noprof(__VA_ARGS__)) =20 void kfree(const void *objp); void kfree_sensitive(const void *objp); @@ -1073,8 +1075,10 @@ kvmalloc_array_node_noprof(size_t n, size_t size, gf= p_t flags, int node) #define kvcalloc_node(...) alloc_hooks(kvcalloc_node_noprof(__VA_ARGS__)) #define kvcalloc(...) alloc_hooks(kvcalloc_noprof(__VA_ARGS__)) =20 -void *kvrealloc_noprof(const void *p, size_t size, gfp_t flags) +void *kvrealloc_node_noprof(const void *p, size_t size, gfp_t flags, int n= id) __realloc_size(2); +#define kvrealloc_node(...) alloc_hooks(kvrealloc_node_noprof(__VA_ARGS_= _)) +#define kvrealloc_noprof(p, s, f) kvrealloc_node_noprof(p, s, f, NUMA_NO_= NODE) #define kvrealloc(...) alloc_hooks(kvrealloc_noprof(__VA_ARGS__)) =20 extern void kvfree(const void *addr); diff --git a/mm/slub.c b/mm/slub.c index c4b64821e680..2d5150d075d5 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -4845,7 +4845,7 @@ void kfree(const void *object) EXPORT_SYMBOL(kfree); =20 static __always_inline __realloc_size(2) void * -__do_krealloc(const void *p, size_t new_size, gfp_t flags) +__do_krealloc(const void *p, size_t new_size, gfp_t flags, int nid) { void *ret; size_t ks =3D 0; @@ -4859,6 +4859,15 @@ __do_krealloc(const void *p, size_t new_size, gfp_t = flags) if (!kasan_check_byte(p)) return NULL; =20 + /* + * it is possible to support reallocation with a different nid, but + * it doesn't go well with the concept of krealloc(). Such + * reallocation should be done explicitly instead. + */ + if (WARN(nid !=3D NUMA_NO_NODE && nid !=3D page_to_nid(virt_to_page(p)), + "krealloc() has mismatched nids\n")) + return NULL; + if (is_kfence_address(p)) { ks =3D orig_size =3D kfence_ksize(p); } else { @@ -4903,7 +4912,7 @@ __do_krealloc(const void *p, size_t new_size, gfp_t f= lags) return (void *)p; =20 alloc_new: - ret =3D kmalloc_node_track_caller_noprof(new_size, flags, NUMA_NO_NODE, _= RET_IP_); + ret =3D kmalloc_node_track_caller_noprof(new_size, flags, nid, _RET_IP_); if (ret && p) { /* Disable KASAN checks as the object's redzone is accessed. */ kasan_disable_current(); @@ -4919,6 +4928,7 @@ __do_krealloc(const void *p, size_t new_size, gfp_t f= lags) * @p: object to reallocate memory for. * @new_size: how many bytes of memory are required. * @flags: the type of memory to allocate. + * @nid: NUMA node or NUMA_NO_NODE * * If @p is %NULL, krealloc() behaves exactly like kmalloc(). If @new_size * is 0 and @p is not a %NULL pointer, the object pointed to is freed. @@ -4947,7 +4957,7 @@ __do_krealloc(const void *p, size_t new_size, gfp_t f= lags) * * Return: pointer to the allocated memory or %NULL in case of error */ -void *krealloc_noprof(const void *p, size_t new_size, gfp_t flags) +void *krealloc_node_noprof(const void *p, size_t new_size, gfp_t flags, in= t nid) { void *ret; =20 @@ -4956,13 +4966,13 @@ void *krealloc_noprof(const void *p, size_t new_siz= e, gfp_t flags) return ZERO_SIZE_PTR; } =20 - ret =3D __do_krealloc(p, new_size, flags); + ret =3D __do_krealloc(p, new_size, flags, nid); if (ret && kasan_reset_tag(p) !=3D kasan_reset_tag(ret)) kfree(p); =20 return ret; } -EXPORT_SYMBOL(krealloc_noprof); +EXPORT_SYMBOL(krealloc_node_noprof); =20 static gfp_t kmalloc_gfp_adjust(gfp_t flags, size_t size) { @@ -5079,10 +5089,11 @@ void kvfree_sensitive(const void *addr, size_t len) EXPORT_SYMBOL(kvfree_sensitive); =20 /** - * kvrealloc - reallocate memory; contents remain unchanged + * kvrealloc_node - reallocate memory; contents remain unchanged * @p: object to reallocate memory for * @size: the size to reallocate * @flags: the flags for the page level allocator + * @nid: NUMA node id * * If @p is %NULL, kvrealloc() behaves exactly like kvmalloc(). If @size i= s 0 * and @p is not a %NULL pointer, the object pointed to is freed. @@ -5100,17 +5111,17 @@ EXPORT_SYMBOL(kvfree_sensitive); * * Return: pointer to the allocated memory or %NULL in case of error */ -void *kvrealloc_noprof(const void *p, size_t size, gfp_t flags) +void *kvrealloc_node_noprof(const void *p, size_t size, gfp_t flags, int n= id) { void *n; =20 if (is_vmalloc_addr(p)) - return vrealloc_noprof(p, size, flags); + return vrealloc_node_noprof(p, size, 1, flags, nid); =20 - n =3D krealloc_noprof(p, size, kmalloc_gfp_adjust(flags, size)); + n =3D krealloc_node_noprof(p, size, kmalloc_gfp_adjust(flags, size), nid); if (!n) { /* We failed to krealloc(), fall back to kvmalloc(). */ - n =3D kvmalloc_noprof(size, flags); + n =3D kvmalloc_node_noprof(size, flags, nid); if (!n) return NULL; =20 @@ -5126,7 +5137,7 @@ void *kvrealloc_noprof(const void *p, size_t size, gf= p_t flags) =20 return n; } -EXPORT_SYMBOL(kvrealloc_noprof); +EXPORT_SYMBOL(kvrealloc_node_noprof); =20 struct detached_freelist { struct slab *slab; --=20 2.39.2 From nobody Wed Oct 8 16:08:18 2025 Received: from mailrelay-egress12.pub.mailoutpod2-cph3.one.com (mailrelay-egress12.pub.mailoutpod2-cph3.one.com [46.30.211.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EEFC1294A15 for ; Thu, 26 Jun 2025 08:36:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.30.211.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750927008; cv=none; b=Ik1o+w2IH66CfoexbzZWcSxlElJ2hix9W0L2RmTnQVgaCYR4tSq0wCVVWjngY0M4fa396MfUfbA2BmbabRtjb8futcYGTICSY7kJJWLad/zkT/isUM64UoWIMhoYV5jDohIzmiVa7RoiLvOEFaIOV+CjnhKQZEDjPlXeLZl+JLk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750927008; c=relaxed/simple; bh=s49bqDVsFhjHPmMT9sFI5qUHSjOibuALwhdsRHZnH58=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DxYC1x5Txw/MrISQAHPrsXPLt3/gWzQPGqNVvQdig+acJw16jAypSPaBb11ORHeyCl5CNgHE0I3t/QNc/5CiK40EgTrGkDOemUfy+r2/KiW0cOSBW5f35o/X0Utcv8n/VeP+CCQSwaLmspA999rhz/y7BxFjjMF1X4ubtbtnhTk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=konsulko.se; spf=none smtp.mailfrom=konsulko.se; dkim=pass (2048-bit key) header.d=konsulko.se header.i=@konsulko.se header.b=WeWVR6F1; dkim=permerror (0-bit key) header.d=konsulko.se header.i=@konsulko.se header.b=NdjUMegl; arc=none smtp.client-ip=46.30.211.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=konsulko.se Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=konsulko.se Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=konsulko.se header.i=@konsulko.se header.b="WeWVR6F1"; dkim=permerror (0-bit key) header.d=konsulko.se header.i=@konsulko.se header.b="NdjUMegl" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1750927005; x=1751531805; d=konsulko.se; s=rsa1; h=content-transfer-encoding:mime-version:references:in-reply-to:message-id:date: subject:cc:to:from:from; bh=knXSD5S79O6CdllCbDYQ90STJZQwheeGaY9xHv0HFjs=; b=WeWVR6F1DZzK9aJJpyYfcIHvevfq/ymYN4+/WB+T2NSKYkVk112r00ki4TkOSV8S4FFOf43Iln9U8 XYzyjXchohDKzwDDgj5taaKCx6fDS/0ezC36rhEka/SidbkcgPrFTxLFk24LDusZfOyCCklwyLOCjj LZ/ZjHTtNvdd2KiZoJaTPt2WlcQgqEARtYRsWZlLjwgUUUF+PWNfYPogid3tWhselQXnEPDdqSOwVE qI6cJwQ+7Wpt+UoJDs0kr1bTPTT8eaSWRTr5M9zKkyfpYTqXGD9NfnT7p65RayVOestCOScj7prnhh F0hFSec7ZmBYJsoobDgb5mhi/7aULwA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1750927005; x=1751531805; d=konsulko.se; s=ed1; h=content-transfer-encoding:mime-version:references:in-reply-to:message-id:date: subject:cc:to:from:from; bh=knXSD5S79O6CdllCbDYQ90STJZQwheeGaY9xHv0HFjs=; b=NdjUMegl0YpZPkrK+HYEkoohulFB3JW2aImrbECIF8X6VuzFRs6P7g14qMhgbHaHca8xNKcZYgrJD 1LBOE/FBQ== X-HalOne-ID: aff13161-5268-11f0-bfae-494313b7f784 Received: from localhost.localdomain (host-90-238-19-233.mobileonline.telia.com [90.238.19.233]) by mailrelay6.pub.mailoutpod2-cph3.one.com (Halon) with ESMTPSA id aff13161-5268-11f0-bfae-494313b7f784; Thu, 26 Jun 2025 08:36:44 +0000 (UTC) From: Vitaly Wool To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org, Uladzislau Rezki , Danilo Krummrich , Alice Ryhl , rust-for-linux@vger.kernel.org, Vitaly Wool Subject: [PATCH v4 3/4] rust: support large alignments in allocations Date: Thu, 26 Jun 2025 10:36:42 +0200 Message-Id: <20250626083642.3596388-1-vitaly.wool@konsulko.se> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20250626083516.3596197-1-vitaly.wool@konsulko.se> References: <20250626083516.3596197-1-vitaly.wool@konsulko.se> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add support for large (> PAGE_SIZE) alignments in Rust allocators (Kmalloc support for large alignments is limited to the requested size, which is a reasonable limitation anyway). Signed-off-by: Vitaly Wool --- rust/helpers/slab.c | 4 ++-- rust/helpers/vmalloc.c | 4 ++-- rust/kernel/alloc/allocator.rs | 16 ++-------------- 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/rust/helpers/slab.c b/rust/helpers/slab.c index a842bfbddcba..5e9e8dd2bba0 100644 --- a/rust/helpers/slab.c +++ b/rust/helpers/slab.c @@ -3,13 +3,13 @@ #include =20 void * __must_check __realloc_size(2) -rust_helper_krealloc(const void *objp, size_t new_size, gfp_t flags) +rust_helper_krealloc(const void *objp, size_t new_size, unsigned long alig= n, gfp_t flags) { return krealloc(objp, new_size, flags); } =20 void * __must_check __realloc_size(2) -rust_helper_kvrealloc(const void *p, size_t size, gfp_t flags) +rust_helper_kvrealloc(const void *p, size_t size, unsigned long align, gfp= _t flags) { return kvrealloc(p, size, flags); } diff --git a/rust/helpers/vmalloc.c b/rust/helpers/vmalloc.c index 80d34501bbc0..4618c0b79283 100644 --- a/rust/helpers/vmalloc.c +++ b/rust/helpers/vmalloc.c @@ -3,7 +3,7 @@ #include =20 void * __must_check __realloc_size(2) -rust_helper_vrealloc(const void *p, size_t size, gfp_t flags) +rust_helper_vrealloc(const void *p, size_t size, unsigned long align, gfp_= t flags) { - return vrealloc(p, size, flags); + return vrealloc_node(p, size, align, flags, NUMA_NO_NODE); } diff --git a/rust/kernel/alloc/allocator.rs b/rust/kernel/alloc/allocator.rs index aa2dfa9dca4c..a0d78c497974 100644 --- a/rust/kernel/alloc/allocator.rs +++ b/rust/kernel/alloc/allocator.rs @@ -58,7 +58,7 @@ fn aligned_size(new_layout: Layout) -> usize { /// /// One of the following: `krealloc`, `vrealloc`, `kvrealloc`. struct ReallocFunc( - unsafe extern "C" fn(*const crate::ffi::c_void, usize, u32) -> *mut cr= ate::ffi::c_void, + unsafe extern "C" fn(*const crate::ffi::c_void, usize, usize, u32) -> = *mut crate::ffi::c_void, ); =20 impl ReallocFunc { @@ -110,7 +110,7 @@ unsafe fn call( // - Those functions provide the guarantees of this function. let raw_ptr =3D unsafe { // If `size =3D=3D 0` and `ptr !=3D NULL` the memory behind th= e pointer is freed. - self.0(ptr.cast(), size, flags.0).cast() + self.0(ptr.cast(), size, layout.align(), flags.0).cast() }; =20 let ptr =3D if size =3D=3D 0 { @@ -152,12 +152,6 @@ unsafe fn realloc( old_layout: Layout, flags: Flags, ) -> Result, AllocError> { - // TODO: Support alignments larger than PAGE_SIZE. - if layout.align() > bindings::PAGE_SIZE { - pr_warn!("Vmalloc does not support alignments larger than PAGE= _SIZE yet.\n"); - return Err(AllocError); - } - // SAFETY: If not `None`, `ptr` is guaranteed to point to valid me= mory, which was previously // allocated with this `Allocator`. unsafe { ReallocFunc::VREALLOC.call(ptr, layout, old_layout, flags= ) } @@ -176,12 +170,6 @@ unsafe fn realloc( old_layout: Layout, flags: Flags, ) -> Result, AllocError> { - // TODO: Support alignments larger than PAGE_SIZE. - if layout.align() > bindings::PAGE_SIZE { - pr_warn!("KVmalloc does not support alignments larger than PAG= E_SIZE yet.\n"); - return Err(AllocError); - } - // SAFETY: If not `None`, `ptr` is guaranteed to point to valid me= mory, which was previously // allocated with this `Allocator`. unsafe { ReallocFunc::KVREALLOC.call(ptr, layout, old_layout, flag= s) } --=20 2.39.2 From nobody Wed Oct 8 16:08:18 2025 Received: from mailrelay3-3.pub.mailoutpod3-cph3.one.com (mailrelay3-3.pub.mailoutpod3-cph3.one.com [46.30.212.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5C26829550C for ; Thu, 26 Jun 2025 08:37:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.30.212.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750927025; cv=none; b=A0cj8pejAsEyU2ZvOEHXYkxjpeCpG6axamIjLDkke0rTeOeIv1YhyUN8rDwEGxP3q2/YMkYDKJhJmM1vm8iOo1X9zoRc0RpZ4wbmgvVgsm90dp7TaVccOT5rCt9wxRgAgKaQRGoEPwNZVP/PsumNCEzpJXoJX+npzKAosdG6eGo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750927025; c=relaxed/simple; bh=tZ6whH1q7CVG/zi0ymHgjD/jli8w2mYD4Bq31hbIZVI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=i9Zn2SWbu04W8Mb0/pCPJUQMm3zwGBPFhmG/n1mEZgyfhwiNnLhXZCTbpCbdLIJWSR9xf04esXUrre1qbX5kkr+MMw3BR/ySlNgzEkeJLB7w7oFco3RDQNyHFnIn5I9rf8ibnZsEZ2VpvFF6cGD3VyuQ16lHxamLC4MUc2H4ivs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=konsulko.se; spf=none smtp.mailfrom=konsulko.se; dkim=pass (2048-bit key) header.d=konsulko.se header.i=@konsulko.se header.b=QKEutYsi; dkim=permerror (0-bit key) header.d=konsulko.se header.i=@konsulko.se header.b=5NJ99EEw; arc=none smtp.client-ip=46.30.212.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=konsulko.se Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=konsulko.se Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=konsulko.se header.i=@konsulko.se header.b="QKEutYsi"; dkim=permerror (0-bit key) header.d=konsulko.se header.i=@konsulko.se header.b="5NJ99EEw" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1750927016; x=1751531816; d=konsulko.se; s=rsa1; h=content-transfer-encoding:mime-version:references:in-reply-to:message-id:date: subject:cc:to:from:from; bh=eY2PvRpyBIA97uJAt2Gqql9RLK3sKrcnmWF3Jybxl34=; b=QKEutYsiXmFvFBsUfSQmw8LXHu7Nfuo+e68Hc5tXHU+S8ex6ZXK5lU22xkT8Z9q/PxmgQRoBf1Q3Z yfzr1unCGpB3MWu1WkCWaX4sM94zAj/wpQwEhZTNn6jm2oJACWGfMoeUqxX+fXeC4plwTJIjUgqX4J GvmTXchwdJjJR8icpEZq0mudHnj3O9fIjl7F6Xe4Xl6bETePbwBSWza+YQW0US1XbIROwREZC8AoRx SgRJdlju7amQvQ0vHxj+p8woDi/t3HeA9a/K+xyYhClkKrO5I3U7YPlI0jKdkLyg20E0ywLALeqKB9 E/JsFF5lpKig8M/POPwKDPmjyJsi0tg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1750927016; x=1751531816; d=konsulko.se; s=ed1; h=content-transfer-encoding:mime-version:references:in-reply-to:message-id:date: subject:cc:to:from:from; bh=eY2PvRpyBIA97uJAt2Gqql9RLK3sKrcnmWF3Jybxl34=; b=5NJ99EEwK9PPy829s2VDLjcc6yLi+kA/M0eIYzUp5WovVkAJUNMRG8oqGMiqPBUy+1RdKmwJNpL1l CeU/xojCg== X-HalOne-ID: b680223f-5268-11f0-86c4-2b8368a4d5c5 Received: from localhost.localdomain (host-90-238-19-233.mobileonline.telia.com [90.238.19.233]) by mailrelay3.pub.mailoutpod3-cph3.one.com (Halon) with ESMTPSA id b680223f-5268-11f0-86c4-2b8368a4d5c5; Thu, 26 Jun 2025 08:36:55 +0000 (UTC) From: Vitaly Wool To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org, Uladzislau Rezki , Danilo Krummrich , Alice Ryhl , rust-for-linux@vger.kernel.org, Vitaly Wool Subject: [PATCH v4 4/4] rust: support NUMA ids in allocations Date: Thu, 26 Jun 2025 10:36:53 +0200 Message-Id: <20250626083653.3596424-1-vitaly.wool@konsulko.se> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20250626083516.3596197-1-vitaly.wool@konsulko.se> References: <20250626083516.3596197-1-vitaly.wool@konsulko.se> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add support for specifying NUMA ids in Rust allocators as an Option (i. e. providing `None` as nid corresponds to NUMA_NO_NODE). This will allow to specify node to use for allocation of e. g. {KV}Box. Signed-off-by: Vitaly Wool --- rust/helpers/slab.c | 9 +++++---- rust/helpers/vmalloc.c | 4 ++-- rust/kernel/alloc.rs | 28 ++++++++++++++++++++++++++-- rust/kernel/alloc/allocator.rs | 26 ++++++++++++++++++-------- rust/kernel/alloc/kvec.rs | 3 ++- 5 files changed, 53 insertions(+), 17 deletions(-) diff --git a/rust/helpers/slab.c b/rust/helpers/slab.c index 5e9e8dd2bba0..ab1cf72f8353 100644 --- a/rust/helpers/slab.c +++ b/rust/helpers/slab.c @@ -3,13 +3,14 @@ #include =20 void * __must_check __realloc_size(2) -rust_helper_krealloc(const void *objp, size_t new_size, unsigned long alig= n, gfp_t flags) +rust_helper_krealloc_node(const void *objp, size_t new_size, unsigned long= align, gfp_t flags, + int nid) { - return krealloc(objp, new_size, flags); + return krealloc_node(objp, new_size, flags, nid); } =20 void * __must_check __realloc_size(2) -rust_helper_kvrealloc(const void *p, size_t size, unsigned long align, gfp= _t flags) +rust_helper_kvrealloc_node(const void *p, size_t size, unsigned long align= , gfp_t flags, int nid) { - return kvrealloc(p, size, flags); + return kvrealloc_node(p, size, flags, nid); } diff --git a/rust/helpers/vmalloc.c b/rust/helpers/vmalloc.c index 4618c0b79283..9131279222fa 100644 --- a/rust/helpers/vmalloc.c +++ b/rust/helpers/vmalloc.c @@ -3,7 +3,7 @@ #include =20 void * __must_check __realloc_size(2) -rust_helper_vrealloc(const void *p, size_t size, unsigned long align, gfp_= t flags) +rust_helper_vrealloc_node(const void *p, size_t size, unsigned long align,= gfp_t flags, int node) { - return vrealloc_node(p, size, align, flags, NUMA_NO_NODE); + return vrealloc_node(p, size, align, flags, node); } diff --git a/rust/kernel/alloc.rs b/rust/kernel/alloc.rs index a2c49e5494d3..1e26c2a7f47c 100644 --- a/rust/kernel/alloc.rs +++ b/rust/kernel/alloc.rs @@ -156,7 +156,30 @@ pub unsafe trait Allocator { fn alloc(layout: Layout, flags: Flags) -> Result, AllocE= rror> { // SAFETY: Passing `None` to `realloc` is valid by its safety requ= irements and asks for a // new memory allocation. - unsafe { Self::realloc(None, layout, Layout::new::<()>(), flags) } + unsafe { Self::realloc(None, layout, Layout::new::<()>(), flags, N= one) } + } + + /// Allocate memory based on `layout`, `flags` and `nid`. + /// + /// On success, returns a buffer represented as `NonNull<[u8]>` that s= atisfies the layout + /// constraints (i.e. minimum size and alignment as specified by `layo= ut`). + /// + /// This function is equivalent to `realloc` when called with `None`. + /// + /// # Guarantees + /// + /// When the return value is `Ok(ptr)`, then `ptr` is + /// - valid for reads and writes for `layout.size()` bytes, until it i= s passed to + /// [`Allocator::free`] or [`Allocator::realloc`], + /// - aligned to `layout.align()`, + /// + /// Additionally, `Flags` are honored as documented in + /// . + fn alloc_node(layout: Layout, flags: Flags, nid: Option) + -> Result, AllocError> { + // SAFETY: Passing `None` to `realloc` is valid by its safety requ= irements and asks for a + // new memory allocation. + unsafe { Self::realloc(None, layout, Layout::new::<()>(), flags, n= id) } } =20 /// Re-allocate an existing memory allocation to satisfy the requested= `layout`. @@ -196,6 +219,7 @@ unsafe fn realloc( layout: Layout, old_layout: Layout, flags: Flags, + nid: Option, ) -> Result, AllocError>; =20 /// Free an existing memory allocation. @@ -211,7 +235,7 @@ unsafe fn free(ptr: NonNull, layout: Layout) { // SAFETY: The caller guarantees that `ptr` points at a valid allo= cation created by this // allocator. We are passing a `Layout` with the smallest possible= alignment, so it is // smaller than or equal to the alignment previously used with thi= s allocation. - let _ =3D unsafe { Self::realloc(Some(ptr), Layout::new::<()>(), l= ayout, Flags(0)) }; + let _ =3D unsafe { Self::realloc(Some(ptr), Layout::new::<()>(), l= ayout, Flags(0), None) }; } } =20 diff --git a/rust/kernel/alloc/allocator.rs b/rust/kernel/alloc/allocator.rs index a0d78c497974..5a0d0a57dfe5 100644 --- a/rust/kernel/alloc/allocator.rs +++ b/rust/kernel/alloc/allocator.rs @@ -58,18 +58,19 @@ fn aligned_size(new_layout: Layout) -> usize { /// /// One of the following: `krealloc`, `vrealloc`, `kvrealloc`. struct ReallocFunc( - unsafe extern "C" fn(*const crate::ffi::c_void, usize, usize, u32) -> = *mut crate::ffi::c_void, + unsafe extern "C" fn(*const crate::ffi::c_void, usize, usize, u32, i32) + -> *mut crate::ffi::c_void, ); =20 impl ReallocFunc { // INVARIANT: `krealloc` satisfies the type invariants. - const KREALLOC: Self =3D Self(bindings::krealloc); + const KREALLOC: Self =3D Self(bindings::krealloc_node); =20 // INVARIANT: `vrealloc` satisfies the type invariants. - const VREALLOC: Self =3D Self(bindings::vrealloc); + const VREALLOC: Self =3D Self(bindings::vrealloc_node); =20 // INVARIANT: `kvrealloc` satisfies the type invariants. - const KVREALLOC: Self =3D Self(bindings::kvrealloc); + const KVREALLOC: Self =3D Self(bindings::kvrealloc_node); =20 /// # Safety /// @@ -87,6 +88,7 @@ unsafe fn call( layout: Layout, old_layout: Layout, flags: Flags, + nid: Option, ) -> Result, AllocError> { let size =3D aligned_size(layout); let ptr =3D match ptr { @@ -100,6 +102,11 @@ unsafe fn call( None =3D> ptr::null(), }; =20 + let c_nid =3D match nid { + None =3D> bindings::NUMA_NO_NODE, + Some(n) =3D> n, + }; + // SAFETY: // - `self.0` is one of `krealloc`, `vrealloc`, `kvrealloc` and th= us only requires that // `ptr` is NULL or valid. @@ -110,7 +117,7 @@ unsafe fn call( // - Those functions provide the guarantees of this function. let raw_ptr =3D unsafe { // If `size =3D=3D 0` and `ptr !=3D NULL` the memory behind th= e pointer is freed. - self.0(ptr.cast(), size, layout.align(), flags.0).cast() + self.0(ptr.cast(), size, layout.align(), flags.0, c_nid).cast() }; =20 let ptr =3D if size =3D=3D 0 { @@ -134,9 +141,10 @@ unsafe fn realloc( layout: Layout, old_layout: Layout, flags: Flags, + nid: Option, ) -> Result, AllocError> { // SAFETY: `ReallocFunc::call` has the same safety requirements as= `Allocator::realloc`. - unsafe { ReallocFunc::KREALLOC.call(ptr, layout, old_layout, flags= ) } + unsafe { ReallocFunc::KREALLOC.call(ptr, layout, old_layout, flags= , nid) } } } =20 @@ -151,10 +159,11 @@ unsafe fn realloc( layout: Layout, old_layout: Layout, flags: Flags, + nid: Option, ) -> Result, AllocError> { // SAFETY: If not `None`, `ptr` is guaranteed to point to valid me= mory, which was previously // allocated with this `Allocator`. - unsafe { ReallocFunc::VREALLOC.call(ptr, layout, old_layout, flags= ) } + unsafe { ReallocFunc::VREALLOC.call(ptr, layout, old_layout, flags= , nid) } } } =20 @@ -169,9 +178,10 @@ unsafe fn realloc( layout: Layout, old_layout: Layout, flags: Flags, + nid: Option ) -> Result, AllocError> { // SAFETY: If not `None`, `ptr` is guaranteed to point to valid me= mory, which was previously // allocated with this `Allocator`. - unsafe { ReallocFunc::KVREALLOC.call(ptr, layout, old_layout, flag= s) } + unsafe { ReallocFunc::KVREALLOC.call(ptr, layout, old_layout, flag= s, nid) } } } diff --git a/rust/kernel/alloc/kvec.rs b/rust/kernel/alloc/kvec.rs index 1a0dd852a468..ef4f977ba012 100644 --- a/rust/kernel/alloc/kvec.rs +++ b/rust/kernel/alloc/kvec.rs @@ -633,6 +633,7 @@ pub fn reserve(&mut self, additional: usize, flags: Fla= gs) -> Result<(), AllocEr layout.into(), self.layout.into(), flags, + None, )? }; =20 @@ -1058,7 +1059,7 @@ pub fn collect(self, flags: Flags) -> Vec { // the type invariant to be smaller than `cap`. Depending on `= realloc` this operation // may shrink the buffer or leave it as it is. ptr =3D match unsafe { - A::realloc(Some(buf.cast()), layout.into(), old_layout.int= o(), flags) + A::realloc(Some(buf.cast()), layout.into(), old_layout.int= o(), flags, None) } { // If we fail to shrink, which likely can't even happen, c= ontinue with the existing // buffer. --=20 2.39.2