From: Boqun Feng <boqun.feng@gmail.com>
To: Vlastimil Babka <vbabka@suse.cz>
Cc: Alice Ryhl <aliceryhl@google.com>,
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>,
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 14:41:11 -0700 [thread overview]
Message-ID: <ZoRz9yEy5wQAu9R9@boqun-archlinux> (raw)
In-Reply-To: <c8061293-8457-4d2b-85c2-7c631c00245a@suse.cz>
On Tue, Jul 02, 2024 at 11:18:36PM +0200, Vlastimil Babka wrote:
> 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)
>
Thanks! This overall looks good to me.
> 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();
The `mut` needs to be removed since no need to modify `size` afterwards.
>
> - 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)
The word "either" needs to be removed as well.
With these changes,
Reviewed-by: Boqun Feng <boqun.feng@gmail.com>
Regards,
Boqun
> 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:42 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-02 15:58 [PATCH] mm, slab: extend kmalloc() alignment for non power-of-two sizes Vlastimil Babka
2024-07-02 16:40 ` Alice Ryhl
2024-07-02 21:18 ` Vlastimil Babka
2024-07-02 21:41 ` Boqun Feng [this message]
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=ZoRz9yEy5wQAu9R9@boqun-archlinux \
--to=boqun.feng@gmail.com \
--cc=42.hyeyoo@gmail.com \
--cc=aliceryhl@google.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 \
--cc=vbabka@suse.cz \
/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).