From: Vlastimil Babka <vbabka@suse.cz>
To: Alice Ryhl <aliceryhl@google.com>
Cc: linux-mm@kvack.org, David Rientjes <rientjes@google.com>,
Christoph Lameter <cl@linux.com>,
Hyeonggon Yoo <42.hyeyoo@gmail.com>,
Roman Gushchin <roman.gushchin@linux.dev>,
Kees Cook <keescook@chromium.org>,
Boqun Feng <boqun.feng@gmail.com>,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
patches@lists.linux.dev
Subject: Re: [PATCH] mm, slab: extend kmalloc() alignment for non power-of-two sizes
Date: Tue, 2 Jul 2024 23:18:36 +0200 [thread overview]
Message-ID: <c8061293-8457-4d2b-85c2-7c631c00245a@suse.cz> (raw)
In-Reply-To: <CAH5fLgj=uOktnNCEm+npBh8LLbYUEO8uO30YUBsLS-iK+BKQJQ@mail.gmail.com>
On 7/2/24 6:40 PM, Alice Ryhl wrote:
> On Tue, Jul 2, 2024 at 5:58 PM Vlastimil Babka <vbabka@suse.cz> wrote:
> Thanks!
>
> Since this change is motivated by Rust, why not also include the Rust
> change in this patch? You would need to remove the if inside
> krealloc_aligned in rust/kernel/alloc/allocator.rs and update the
> comments.
Right, thanks. Does this look ok? (not tested as I don't have the
environment working)
diff --git a/rust/kernel/alloc/allocator.rs b/rust/kernel/alloc/allocator.rs
index 229642960cd1..c619acb8b285 100644
--- a/rust/kernel/alloc/allocator.rs
+++ b/rust/kernel/alloc/allocator.rs
@@ -18,23 +18,16 @@ pub(crate) unsafe fn krealloc_aligned(ptr: *mut u8, new_layout: Layout, flags: F
// Customized layouts from `Layout::from_size_align()` can have size < align, so pad first.
let layout = new_layout.pad_to_align();
+ // Note that `layout.size()` (after padding) is guaranteed to be a multiple of `layout.align()`
+ // which together with the slab guarantee means the `krealloc` will return a properly aligned
+ // object (see comments in `kmalloc()` for more information).
let mut size = layout.size();
- if layout.align() > bindings::ARCH_SLAB_MINALIGN {
- // The alignment requirement exceeds the slab guarantee, thus try to enlarge the size
- // to use the "power-of-two" size/alignment guarantee (see comments in `kmalloc()` for
- // more information).
- //
- // Note that `layout.size()` (after padding) is guaranteed to be a multiple of
- // `layout.align()`, so `next_power_of_two` gives enough alignment guarantee.
- size = size.next_power_of_two();
- }
-
// SAFETY:
// - `ptr` is either null or a pointer returned from a previous `k{re}alloc()` by the
// function safety requirement.
// - `size` is greater than 0 since it's either a `layout.size()` (which cannot be zero
- // according to the function safety requirement) or a result from `next_power_of_two()`.
+ // according to the function safety requirement)
unsafe { bindings::krealloc(ptr as *const core::ffi::c_void, size, flags.0) as *mut u8 }
}
next prev parent reply other threads:[~2024-07-02 21:18 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-02 15:58 Vlastimil Babka
2024-07-02 16:40 ` Alice Ryhl
2024-07-02 21:18 ` Vlastimil Babka [this message]
2024-07-02 21:41 ` Boqun Feng
2024-07-02 19:30 ` Roman Gushchin
2024-07-02 20:25 ` Vlastimil Babka
2024-07-02 21:13 ` Roman Gushchin
2024-07-02 21:20 ` Vlastimil Babka
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=c8061293-8457-4d2b-85c2-7c631c00245a@suse.cz \
--to=vbabka@suse.cz \
--cc=42.hyeyoo@gmail.com \
--cc=aliceryhl@google.com \
--cc=boqun.feng@gmail.com \
--cc=cl@linux.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=patches@lists.linux.dev \
--cc=rientjes@google.com \
--cc=roman.gushchin@linux.dev \
--cc=rust-for-linux@vger.kernel.org \
/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