linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Vitaly Wool <vitaly.wool@konsulko.se>
To: 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,
	Vitaly Wool <vitaly.wool@konsulko.se>
Subject: [PATCH v5 4/4] rust: support large alignments in allocations
Date: Fri, 27 Jun 2025 11:39:18 +0200	[thread overview]
Message-ID: <20250627093918.415888-1-vitaly.wool@konsulko.se> (raw)
In-Reply-To: <20250627092901.356909-1-vitaly.wool@konsulko.se>

Add support for large (> PAGE_SIZE) alignments in Rust allocators.
With _NODE primitives introduced in the previous patch, we actually
have all the infractructure in place so let's just start using it.

Signed-off-by: Vitaly Wool <vitaly.wool@konsulko.se>
---
 rust/kernel/alloc/allocator.rs | 14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)

diff --git a/rust/kernel/alloc/allocator.rs b/rust/kernel/alloc/allocator.rs
index 4f0fe2b67593..75c9e4220ac3 100644
--- a/rust/kernel/alloc/allocator.rs
+++ b/rust/kernel/alloc/allocator.rs
@@ -118,7 +118,7 @@ unsafe fn call(
         // - Those functions provide the guarantees of this function.
         let raw_ptr = unsafe {
             // If `size == 0` and `ptr != NULL` the memory behind the pointer is freed.
-            self.0(ptr.cast(), size, 1, flags.0, c_nid).cast()
+            self.0(ptr.cast(), size, layout.align(), flags.0, c_nid).cast()
         };
 
         let ptr = if size == 0 {
@@ -162,12 +162,6 @@ unsafe fn realloc(
         flags: Flags,
         nid: Option<i32>,
     ) -> Result<NonNull<[u8]>, 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 memory, which was previously
         // allocated with this `Allocator`.
         unsafe { ReallocFunc::VREALLOC_NODE.call(ptr, layout, old_layout, flags, nid) }
@@ -187,12 +181,6 @@ unsafe fn realloc(
         flags: Flags,
         nid: Option<i32>,
     ) -> Result<NonNull<[u8]>, AllocError> {
-        // TODO: Support alignments larger than PAGE_SIZE.
-        if layout.align() > bindings::PAGE_SIZE {
-            pr_warn!("KVmalloc does not support alignments larger than PAGE_SIZE yet.\n");
-            return Err(AllocError);
-        }
-
         // SAFETY: If not `None`, `ptr` is guaranteed to point to valid memory, which was previously
         // allocated with this `Allocator`.
         unsafe { ReallocFunc::KVREALLOC_NODE.call(ptr, layout, old_layout, flags, nid) }
-- 
2.39.2



      parent reply	other threads:[~2025-06-27  9:39 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-27  9:29 [PATCH v5 0/4] support large align and nid in Rust allocators Vitaly Wool
2025-06-27  9:35 ` [PATCH v5 1/4] mm/vmalloc: allow to set node and align in vrealloc Vitaly Wool
2025-06-27  9:37 ` [PATCH 2/4] mm/slub: allow to set node and align in k[v]realloc Vitaly Wool
2025-06-27 10:41   ` Danilo Krummrich
2025-06-27 11:42     ` Uladzislau Rezki
2025-06-27 12:01       ` Vitaly Wool
2025-06-27 17:54         ` Uladzislau Rezki
2025-06-27 22:14           ` Vitaly Wool
2025-06-27 11:57     ` Vitaly Wool
2025-06-27  9:38 ` [PATCH v5 3/4] rust: add support for NUMA ids in allocations Vitaly Wool
2025-06-27 11:20   ` Danilo Krummrich
2025-06-27  9:39 ` Vitaly Wool [this message]

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=20250627093918.415888-1-vitaly.wool@konsulko.se \
    --to=vitaly.wool@konsulko.se \
    --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 \
    /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