Re: [PATCH v3 2/2] rust: support align and NUMA id in allocations

From: Uladzislau Rezki
Date: Wed Jun 25 2025 - 12:07:56 EST


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.

--
Uladzislau Rezki