Skip to contentSkip to conversation

mm/vmalloc: reclaim tail resources on large vrealloc() shrink

RFC PATCH In review fujunjie 3 participants 5 messages Apr 26 – Apr 28 Memory management

lore
Share & tools
lore

fujunjie

author
#0 lore raw

cover mm/vmalloc: reclaim tail resources on large vrealloc() shrink

Hi,

This RFC explores closing the resource retention gap in the vmalloc-backed shrink path of vrealloc().

Today, when a vmalloc-backed allocation is shrunk, vrealloc() updates the requested size but can keep most of the old vmalloc mapping and backing pages alive. For sufficiently large shrink operations, this can retain a large amount of tail resources even though the logical object became much smaller.

This first RFC keeps the scope intentionally conservative:

- only ordinary VM_ALLOC areas
- only page_order == 0 allocations
- skip more complex vmalloc object types
- only reclaim tail resources when the retained waste is at least PMD_SIZE

The current evidence supports this as a resource reclamation fix rather than a workload-tuned performance optimization. Local validation currently covers:

- synthetic large shrink correctness
- shrink-then-grow regression
- threshold boundary correctness for the current heuristic
- KASAN run-rootfs vmalloc_oob regression coverage

I would especially appreciate feedback on:

1. whether this shrink direction is desirable upstream at all
2. whether the initial object-type restrictions are reasonable
3. whether a conservative PMD_SIZE threshold is an acceptable first heuristic
4. what kind of in-tree regression test would be preferred

Thanks.

fujunjie (1):
mm/vmalloc: reclaim tail resources on large vrealloc() shrink

 mm/vmalloc.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 100 insertions(+), 5 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw
Quoted 25 lines · fujunjie

Hi,

This RFC explores closing the resource retention gap in the vmalloc-backed shrink path of vrealloc().

Today, when a vmalloc-backed allocation is shrunk, vrealloc() updates the requested size but can keep most of the old vmalloc mapping and backing pages alive. For sufficiently large shrink operations, this can retain a large amount of tail resources even though the logical object became much smaller.

This first RFC keeps the scope intentionally conservative:

- only ordinary VM_ALLOC areas
- only page_order == 0 allocations
- skip more complex vmalloc object types
- only reclaim tail resources when the retained waste is at least PMD_SIZE

The current evidence supports this as a resource reclamation fix rather than a workload-tuned performance optimization. Local validation currently covers:

- synthetic large shrink correctness
- shrink-then-grow regression
- threshold boundary correctness for the current heuristic
- KASAN run-rootfs vmalloc_oob regression coverage

Quoted 7 lines

I would especially appreciate feedback on:

1. whether this shrink direction is desirable upstream at all
2. whether the initial object-type restrictions are reasonable
3. whether a conservative PMD_SIZE threshold is an acceptable first heuristic
4. what kind of in-tree regression test would be preferred

Could you please have a look at this work:
https://lore.kernel.org/all/[email protected]/

Shivam is working on the same feature. Could you please check?

--
Uladzislau Rezki

author
#2 lore raw
Quoted 33 lines · Uladzislau Rezki
Quoted 25 lines · fujunjie

Hi,

This RFC explores closing the resource retention gap in the vmalloc-backed shrink path of vrealloc().

Today, when a vmalloc-backed allocation is shrunk, vrealloc() updates the requested size but can keep most of the old vmalloc mapping and backing pages alive. For sufficiently large shrink operations, this can retain a large amount of tail resources even though the logical object became much smaller.

This first RFC keeps the scope intentionally conservative:

- only ordinary VM_ALLOC areas
- only page_order == 0 allocations
- skip more complex vmalloc object types
- only reclaim tail resources when the retained waste is at least PMD_SIZE

The current evidence supports this as a resource reclamation fix rather than a workload-tuned performance optimization. Local validation currently covers:

- synthetic large shrink correctness
- shrink-then-grow regression
- threshold boundary correctness for the current heuristic
- KASAN run-rootfs vmalloc_oob regression coverage

Quoted 7 lines

I would especially appreciate feedback on:

1. whether this shrink direction is desirable upstream at all
2. whether the initial object-type restrictions are reasonable
3. whether a conservative PMD_SIZE threshold is an acceptable first heuristic
4. what kind of in-tree regression test would be preferred

Quoted 7 lines

Could you please have a look at this work:
https://lore.kernel.org/all/[email protected]/

Shivam is working on the same feature. Could you please check?

--
Uladzislau Rezki

Thanks for the pointer, and sorry for missing Shivam's series before sending this RFC.

I will read through it first and avoid duplicating the effort.

Thanks,
fujunjie

#3 lore raw
Quoted 39 lines · Fujunjie
Quoted 36 lines · Uladzislau Rezki
Quoted 25 lines · fujunjie

Hi,

This RFC explores closing the resource retention gap in the vmalloc-backed shrink path of vrealloc().

Today, when a vmalloc-backed allocation is shrunk, vrealloc() updates the requested size but can keep most of the old vmalloc mapping and backing pages alive. For sufficiently large shrink operations, this can retain a large amount of tail resources even though the logical object became much smaller.

This first RFC keeps the scope intentionally conservative:

- only ordinary VM_ALLOC areas
- only page_order == 0 allocations
- skip more complex vmalloc object types
- only reclaim tail resources when the retained waste is at least PMD_SIZE

The current evidence supports this as a resource reclamation fix rather than a workload-tuned performance optimization. Local validation currently covers:

- synthetic large shrink correctness
- shrink-then-grow regression
- threshold boundary correctness for the current heuristic
- KASAN run-rootfs vmalloc_oob regression coverage

Quoted 7 lines

I would especially appreciate feedback on:

1. whether this shrink direction is desirable upstream at all
2. whether the initial object-type restrictions are reasonable
3. whether a conservative PMD_SIZE threshold is an acceptable first heuristic
4. what kind of in-tree regression test would be preferred

Could you please have a look at this work:
https://lore.kernel.org/all/[email protected]/

Quoted 9 lines
Quoted 4 lines

Shivam is working on the same feature. Could you please check?

--
Uladzislau Rezki

Thanks for the pointer, and sorry for missing Shivam's series before sending this RFC.

I will read through it first and avoid duplicating the effort.

Thank you!

Maybe Shivam can also have a look at your work. I put him into To.

--
Uladzislau Rezki

#4 lore raw

Hey Fujunjie

In my patch series,
1. I am freeing at least a single page.
2. Did not change the vmap area, only changed the nr_pages at vm_struct and update the pages array.

Rest of the questions are addressed in my patch series.

Feel free to review or test my patch series and let me know if you have any suggestions.

Shivam