* [RFC] mm/vmalloc: vrealloc() shrink TODO - seeking direction before implementing
@ 2026-02-18 23:06 Shivam Kalra
2026-02-19 16:57 ` Uladzislau Rezki
0 siblings, 1 reply; 4+ messages in thread
From: Shivam Kalra @ 2026-02-18 23:06 UTC (permalink / raw)
To: linux-mm; +Cc: Danilo Krummrich, Uladzislau Rezki, akpm
Hi all,
I've been looking at the TODO comment introduced in commit 3ddc2fefe6f3
("mm: vmalloc: implement vrealloc()"):
```c
/*
* TODO: Shrink the vm_area, i.e. unmap and free unused pages. What
* would be a good heuristic for when to shrink the vm_area?
*/
```
Before spending time on an implementation I'd like to check with
maintainers that the approach is sound.
Current state
When vrealloc() shrinks an allocation, it only updates `vm->requested_size`
and KASAN shadow - no physical pages are freed. This leaves wasted
pages mapped for the lifetime of the allocation.
Proposed approach
When the new size crosses a page boundary, free the tail pages in-place.
I'm proposing to always shrink when pages can be freed (no threshold
heuristic), matching the simplicity of krealloc()'s in-place shrink
approach. For huge-page vmalloc allocations (page_order > 0) I'd skip
the shrink, since partial freeing would require splitting.
Questions
1. Does the in-place approach (keep `vm->size`, free tail pages) look
acceptable, or is there a preferred alternative?
2. Is "always shrink when crossing a page boundary" a reasonable
heuristic, or would you prefer a threshold (e.g., free only if
> N pages are reclaimed)?
3. Is skipping huge-page allocations the right call for a first
patch, or should it be handled upfront?
Thanks in advance for any guidance
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [RFC] mm/vmalloc: vrealloc() shrink TODO - seeking direction before implementing
2026-02-18 23:06 [RFC] mm/vmalloc: vrealloc() shrink TODO - seeking direction before implementing Shivam Kalra
@ 2026-02-19 16:57 ` Uladzislau Rezki
2026-02-19 17:01 ` Danilo Krummrich
0 siblings, 1 reply; 4+ messages in thread
From: Uladzislau Rezki @ 2026-02-19 16:57 UTC (permalink / raw)
To: Shivam Kalra; +Cc: linux-mm, Danilo Krummrich, Uladzislau Rezki, akpm
On Thu, Feb 19, 2026 at 04:36:54AM +0530, Shivam Kalra wrote:
> Hi all,
>
> I've been looking at the TODO comment introduced in commit 3ddc2fefe6f3
> ("mm: vmalloc: implement vrealloc()"):
>
> ```c
> /*
> * TODO: Shrink the vm_area, i.e. unmap and free unused pages. What
> * would be a good heuristic for when to shrink the vm_area?
> */
> ```
>
> Before spending time on an implementation I'd like to check with
> maintainers that the approach is sound.
>
> Current state
>
> When vrealloc() shrinks an allocation, it only updates `vm->requested_size`
> and KASAN shadow - no physical pages are freed. This leaves wasted
> pages mapped for the lifetime of the allocation.
>
> Proposed approach
>
> When the new size crosses a page boundary, free the tail pages in-place.
>
> I'm proposing to always shrink when pages can be freed (no threshold
> heuristic), matching the simplicity of krealloc()'s in-place shrink
> approach. For huge-page vmalloc allocations (page_order > 0) I'd skip
> the shrink, since partial freeing would require splitting.
>
>
> Questions
>
> 1. Does the in-place approach (keep `vm->size`, free tail pages) look
> acceptable, or is there a preferred alternative?
>
> 2. Is "always shrink when crossing a page boundary" a reasonable
> heuristic, or would you prefer a threshold (e.g., free only if
> > N pages are reclaimed)?
>
> 3. Is skipping huge-page allocations the right call for a first
> patch, or should it be handled upfront?
>
I think we have 0 users of vrealloc(). It was added because of Rust folk
wanted this.
From the other hand, if we free some tail pages without saving much in
memory consumption, IMO it does not make sense to introduce more complexity
then. Also, as an example, if you want grow you need to alloc/map back.
I mean it all depends on number of use cases and sensitive to it workloads.
--
Uladzislau Rezki
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [RFC] mm/vmalloc: vrealloc() shrink TODO - seeking direction before implementing
2026-02-19 16:57 ` Uladzislau Rezki
@ 2026-02-19 17:01 ` Danilo Krummrich
2026-02-20 8:01 ` Alice Ryhl
0 siblings, 1 reply; 4+ messages in thread
From: Danilo Krummrich @ 2026-02-19 17:01 UTC (permalink / raw)
To: Uladzislau Rezki; +Cc: Shivam Kalra, linux-mm, akpm, aliceryhl
(Cc: Alice)
On Thu Feb 19, 2026 at 5:57 PM CET, Uladzislau Rezki wrote:
> I think we have 0 users of vrealloc(). It was added because of Rust folk
> wanted this.
We just gained a user with the Rust binder driver.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFC] mm/vmalloc: vrealloc() shrink TODO - seeking direction before implementing
2026-02-19 17:01 ` Danilo Krummrich
@ 2026-02-20 8:01 ` Alice Ryhl
0 siblings, 0 replies; 4+ messages in thread
From: Alice Ryhl @ 2026-02-20 8:01 UTC (permalink / raw)
To: Danilo Krummrich; +Cc: Uladzislau Rezki, Shivam Kalra, linux-mm, akpm
On Thu, Feb 19, 2026 at 06:01:29PM +0100, Danilo Krummrich wrote:
> (Cc: Alice)
>
> On Thu Feb 19, 2026 at 5:57 PM CET, Uladzislau Rezki wrote:
> > I think we have 0 users of vrealloc(). It was added because of Rust folk
> > wanted this.
>
> We just gained a user with the Rust binder driver.
Yeah, if I have a long-lived resizable array (allocated with kvmalloc)
then I'd like to be able to shrink it if the number of elements decrease
again, to prevent unnecessary indefinite memory usage.
Alice
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-02-20 8:02 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-02-18 23:06 [RFC] mm/vmalloc: vrealloc() shrink TODO - seeking direction before implementing Shivam Kalra
2026-02-19 16:57 ` Uladzislau Rezki
2026-02-19 17:01 ` Danilo Krummrich
2026-02-20 8:01 ` Alice Ryhl
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox