[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aFwno6S5x7M-_YDP@pc636>
Date: Wed, 25 Jun 2025 18:45:23 +0200
From: Uladzislau Rezki <urezki@...il.com>
To: Boqun Feng <boqun.feng@...il.com>
Cc: Uladzislau Rezki <urezki@...il.com>,
Vitaly Wool <vitaly.wool@...sulko.se>, linux-mm@...ck.org,
akpm@...ux-foundation.org, linux-kernel@...r.kernel.org,
Danilo Krummrich <dakr@...nel.org>,
Alice Ryhl <aliceryhl@...gle.com>, rust-for-linux@...r.kernel.org
Subject: Re: [PATCH v3 2/2] rust: support align and NUMA id in allocations
On Wed, Jun 25, 2025 at 09:12:21AM -0700, Boqun Feng wrote:
> On Wed, Jun 25, 2025 at 06:07:06PM +0200, Uladzislau Rezki wrote:
> > On Wed, Jun 25, 2025 at 06:12:52AM -0700, Boqun Feng wrote:
> > > On Wed, Jun 25, 2025 at 08:30:26AM +0200, Vitaly Wool wrote:
> > > [...]
> > > > @@ -151,16 +159,11 @@ unsafe fn realloc(
> > > > layout: Layout,
> > > > old_layout: Layout,
> > > > flags: Flags,
> > > > + nid: Option<i32>,
> > > > ) -> Result<NonNull<[u8]>, AllocError> {
> > > > - // TODO: Support alignments larger than PAGE_SIZE.
> > >
> > > Thanks a lot for doing this! While you're at it, maybe we can add a few
> > > tests for various alignments of allocation? I'm thinking:
> > >
> > > #[repr(align(65536)]
> > > pub struct Test64k {
> > > a: i32
> > > }
> > >
> > > #[kunit_tests(rust_vbox)]
> > > mod tests {
> > > #[test]
> > > fn large_allocation() -> Result {
> > > // Better use `new_uninit()` to avoid allocation on the stack.
> > > let x = VBox::<Test64k>::new_uninit(...)?;
> > >
> > > assert!(x.as_ptr().addr() & (kernel::sizes::SZ_64K - 1) == 0);
> > > }
> > > }
> > >
> > > Thoughts?
> > >
> > > Regards,
> > > Boqun
> > >
> > > > - 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.call(ptr, layout, old_layout, flags) }
> > > > + unsafe { ReallocFunc::VREALLOC.call(ptr, layout, old_layout, flags, nid) }
> > > > }
> > > > }
> > > >
> > > [...]
> > >
> > At least we are lacking of vrealloc() exercising in the vmalloc-test suite.
> > I am not sure it makes a lot of sense to add a kunit test on top of rust-wrapper
> > around vrealloc().
> >
> > From my side, i will add the test case to the test_vmalloc.c test-suite.
> >
>
> Thanks! But we will need these tests from Rust side anyway, to test
> 1) whether the Rust wrapper does the right thing, and 2) whether any C
> change cause the behavior changes on the API that Rust wrapper rely on.
>
Ah. Got it :)
--
Uladzislau Rezki
Powered by blists - more mailing lists