[PATCH 0/3] rust: allocator: Vmalloc: Support alignments larger than PAGE_SIZE

Hui Zhu posted 3 patches 2 months, 3 weeks ago
include/linux/vmalloc.h        |   5 ++
mm/vmalloc.c                   |  80 ++++++++++++++++---------
rust/helpers/vmalloc.c         |   7 +++
rust/kernel/alloc/allocator.rs |  32 ++++++----
samples/rust/Kconfig           |  10 ++++
samples/rust/Makefile          |   1 +
samples/rust/rust_allocator.rs | 104 +++++++++++++++++++++++++++++++++
7 files changed, 199 insertions(+), 40 deletions(-)
create mode 100644 samples/rust/rust_allocator.rs
[PATCH 0/3] rust: allocator: Vmalloc: Support alignments larger than PAGE_SIZE
Posted by Hui Zhu 2 months, 3 weeks ago
From: Hui Zhu <zhuhui@kylinos.cn>

There is a TODO in Vmalloc::realloc "Support alignments larger than
PAGE_SIZE."

These commits make allocator vmalloc support alignments larger than
PAGE_SIZE.
The function vrealloc_align is added to vmalloc.c to support reallocating
aligned vmap pages.
When Vmalloc::realloc intends to reallocate memory aligned beyond PAGE_SIZE,
vrealloc_align should be used instead of vrealloc, thus enabling support
for alignments larger than PAGE_SIZE.
And add a sample to the samples memory allocator usage.

Hui Zhu (3):
  vmalloc: Add vrealloc_align to support allocation of aligned vmap
    pages
  rust: allocator: Vmalloc: Support alignments larger than PAGE_SIZE
  rust: add a sample allocator usage

 include/linux/vmalloc.h        |   5 ++
 mm/vmalloc.c                   |  80 ++++++++++++++++---------
 rust/helpers/vmalloc.c         |   7 +++
 rust/kernel/alloc/allocator.rs |  32 ++++++----
 samples/rust/Kconfig           |  10 ++++
 samples/rust/Makefile          |   1 +
 samples/rust/rust_allocator.rs | 104 +++++++++++++++++++++++++++++++++
 7 files changed, 199 insertions(+), 40 deletions(-)
 create mode 100644 samples/rust/rust_allocator.rs

-- 
2.43.0
Re: [PATCH 0/3] rust: allocator: Vmalloc: Support alignments larger than PAGE_SIZE
Posted by Danilo Krummrich 2 months, 3 weeks ago
Hi Hui,

On Tue Jul 15, 2025 at 11:59 AM CEST, Hui Zhu wrote:
> From: Hui Zhu <zhuhui@kylinos.cn>
>
> There is a TODO in Vmalloc::realloc "Support alignments larger than
> PAGE_SIZE."
>
> These commits make allocator vmalloc support alignments larger than
> PAGE_SIZE.
> The function vrealloc_align is added to vmalloc.c to support reallocating
> aligned vmap pages.
> When Vmalloc::realloc intends to reallocate memory aligned beyond PAGE_SIZE,
> vrealloc_align should be used instead of vrealloc, thus enabling support
> for alignments larger than PAGE_SIZE.

Thanks for the patch!

Please note that there is already a rather progressed patch series addressing
this [1].

However, I'd be interested in your use-case for alignments larger than
PAGE_SIZE. :)

> And add a sample to the samples memory allocator usage.

The example looks a bit odd, more on that in the corresponding patch.

We already have other examples in the form of documentation tests [2]. Not all
of them are for VVec, some of them are for KVec and KVVec, however, they all
share the same code, only the allocator backend differs.

If you'd like to introduce additional examples, please do so in the context of
documentation tests in rust/kernel/alloc/kvec.rs.

If you enable CONFIG_RUST_KERNEL_DOCTESTS they're compiled and executed at boot
time.

[1] https://lore.kernel.org/lkml/20250709172345.1031907-1-vitaly.wool@konsulko.se/
[2] https://rust.docs.kernel.org/kernel/alloc/kvec/type.VVec.html