All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] mm/vmalloc: free unused pages on vrealloc() shrink
@ 2026-03-04 14:53 ` Shivam Kalra via B4 Relay
  0 siblings, 0 replies; 9+ messages in thread
From: Shivam Kalra @ 2026-03-04 14:53 UTC (permalink / raw)
  To: Andrew Morton, Uladzislau Rezki
  Cc: linux-mm, linux-kernel, Alice Ryhl, Danilo Krummrich,
	Shivam Kalra

This series implements the TODO in vrealloc() to unmap and free unused
pages when shrinking across a page boundary.

Problem:
When vrealloc() shrinks an allocation, it updates bookkeeping
(requested_size, KASAN shadow) but does not free the underlying physical
pages. This wastes memory for the lifetime of the allocation.

Solution:
- Patch 1: Extracts a vmalloc_free_pages(vm, start, end) helper from
  vfree() that frees a range of pages with memcg and nr_vmalloc_pages
  accounting. Pure refactor, no functional change.
- Patch 2: Uses the helper to free tail pages when vrealloc() shrinks
  across a page boundary. Skips huge page allocations (page_order > 0)
  since compound pages cannot be partially freed. Also fixes the
  grow-in-place path to check vm->nr_pages instead of
  get_vm_area_size(), which reflects the virtual reservation and does
  not change on shrink.
The virtual address reservation is kept intact to preserve the range
for potential future grow-in-place support.
A concrete user is the Rust binder driver's KVVec::shrink_to [1], which
performs explicit vrealloc() shrinks for memory reclamation.

Tested:
- KASAN KUnit (vmalloc_oob passes)
- lib/test_vmalloc stress tests (3/3, 1M iterations each)
- checkpatch, sparse, W=1, allmodconfig, coccicheck clean

[1] https://lore.kernel.org/all/20260216-binder-shrink-vec-v3-v6-0-ece8e8593e53@zohomail.in/

Signed-off-by: Shivam Kalra <shivamkalra98@zohomail.in>
---
Changes in v2:
- Updated the base-commit to mm-new
- Fix conflicts after rebase
- Ran `clang-format` on the changes made
- Use a single `kasan_vrealloc` (Alice Ryhl)
- Link to v1: https://lore.kernel.org/r/20260302-vmalloc-shrink-v1-0-46deff465b7e@zohomail.in

---
Shivam Kalra (2):
      mm/vmalloc: extract vmalloc_free_pages() helper from vfree()
      mm/vmalloc: free unused pages on vrealloc() shrink

 mm/vmalloc.c | 61 +++++++++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 42 insertions(+), 19 deletions(-)
---
base-commit: 2bff1816949a0849a384ed3cc66c8385d9590861
change-id: 20260302-vmalloc-shrink-04b2fa688a14

Best regards,
-- 
Shivam Kalra <shivamkalra98@zohomail.in>


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-03-11 17:33 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-04 14:53 [PATCH v2 0/2] mm/vmalloc: free unused pages on vrealloc() shrink Shivam Kalra
2026-03-04 14:53 ` Shivam Kalra via B4 Relay
2026-03-04 14:53 ` [PATCH v2 1/2] mm/vmalloc: extract vmalloc_free_pages() helper from vfree() Shivam Kalra
2026-03-04 14:53   ` Shivam Kalra via B4 Relay
2026-03-04 21:44   ` Alice Ryhl
2026-03-05  8:10     ` Shivam Kalra
2026-03-11 17:33   ` Uladzislau Rezki
2026-03-04 14:53 ` [PATCH v2 2/2] mm/vmalloc: free unused pages on vrealloc() shrink Shivam Kalra
2026-03-04 14:53   ` Shivam Kalra via B4 Relay

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.