From: Uladzislau Rezki <urezki@gmail.com>
To: Shivam Kalra <shivamkalra98@zohomail.in>
Cc: linux-mm@kvack.org, Danilo Krummrich <dakr@kernel.org>,
Uladzislau Rezki <urezki@gmail.com>,
akpm@linux-foundation.org
Subject: Re: [RFC] mm/vmalloc: vrealloc() shrink TODO - seeking direction before implementing
Date: Thu, 19 Feb 2026 17:57:48 +0100 [thread overview]
Message-ID: <aZdBDOPUccXa85O2@pc636> (raw)
In-Reply-To: <29e454bc-5a46-43b2-80b0-4d8d93e3feae@zohomail.in>
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
next prev parent reply other threads:[~2026-02-19 16:57 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-18 23:06 Shivam Kalra
2026-02-19 16:57 ` Uladzislau Rezki [this message]
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=aZdBDOPUccXa85O2@pc636 \
--to=urezki@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=dakr@kernel.org \
--cc=linux-mm@kvack.org \
--cc=shivamkalra98@zohomail.in \
/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