[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <DG5FEPO6RCK4.17KOY7PRLNFKV@kernel.org>
Date: Tue, 03 Feb 2026 16:19:14 +0100
From: "Danilo Krummrich" <dakr@...nel.org>
To: "Shivam Kalra" <shivamklr@...k.li>
Cc: <cmllamas@...gle.com>, <gregkh@...uxfoundation.org>,
<aliceryhl@...gle.com>, <rust-for-linux@...r.kernel.org>,
<linux-kernel@...r.kernel.org>, <lorenzo.stoakes@...cle.com>,
<vbabka@...e.cz>, <Liam.Howlett@...cle.com>, <urezki@...il.com>
Subject: Re: [PATCH v2 1/3] rust: alloc: Add shrink_to and shrink_to_fit
methods to Vec
On Sat Jan 31, 2026 at 4:40 PM CET, Shivam Kalra wrote:
> This implementation guarantees shrinking (unless already optimal),
> because the kernel allocators don't support in-place shrinking,
> a new allocation is always made.
I'm not sure we should go in this direction. There is a reason why krealloc()
does not migrate memory between kmalloc buckets, i.e. the cost of migration vs.
memory saving.
For Vmalloc buffers the story is a bit different though. When I wrote vrealloc()
I left some TODO comments [1][2].
(1) If a smaller buffer is requested we can shrink the vm_area, i.e. unmap and
free unused pages.
(2) If a bigger buffer is requested we can grow the vm_area, i.e. allocate and
map additional pages. (At least as long as we have enough space in the
virtual address space.)
So, I think we should just use A::realloc(), leave the rest to the underlying
specific realloc() implementations and address the TODOs in vrealloc() if
necessary.
[1] https://elixir.bootlin.com/linux/v6.18.6/source/mm/vmalloc.c#L4162
[2] https://elixir.bootlin.com/linux/v6.18.6/source/mm/vmalloc.c#L4192
Powered by blists - more mailing lists