From: Shivam Kalra <shivamkalra98@zohomail.in>
To: linux-mm@kvack.org
Cc: Danilo Krummrich <dakr@kernel.org>,
Uladzislau Rezki <urezki@gmail.com>,
akpm@linux-foundation.org
Subject: [RFC] mm/vmalloc: vrealloc() shrink TODO - seeking direction before implementing
Date: Thu, 19 Feb 2026 04:36:54 +0530 [thread overview]
Message-ID: <29e454bc-5a46-43b2-80b0-4d8d93e3feae@zohomail.in> (raw)
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
next reply other threads:[~2026-02-18 23:07 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-18 23:06 Shivam Kalra [this message]
2026-02-19 16:57 ` Uladzislau Rezki
2026-02-19 17:01 ` Danilo Krummrich
2026-02-20 8:01 ` Alice Ryhl
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=29e454bc-5a46-43b2-80b0-4d8d93e3feae@zohomail.in \
--to=shivamkalra98@zohomail.in \
--cc=akpm@linux-foundation.org \
--cc=dakr@kernel.org \
--cc=linux-mm@kvack.org \
--cc=urezki@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox