All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Danilo Krummrich" <dakr@kernel.org>
To: "Alice Ryhl" <aliceryhl@google.com>
Cc: "Shivam Kalra" <shivamklr@cock.li>, <cmllamas@google.com>,
	<gregkh@linuxfoundation.org>, <rust-for-linux@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>, <lorenzo.stoakes@oracle.com>,
	<vbabka@suse.cz>, <Liam.Howlett@oracle.com>, <urezki@gmail.com>
Subject: Re: [PATCH v2 1/3] rust: alloc: Add shrink_to and shrink_to_fit methods to Vec
Date: Tue, 03 Feb 2026 16:43:05 +0100	[thread overview]
Message-ID: <DG5FWZ2CA3DR.2WBZ27YUYS705@kernel.org> (raw)
In-Reply-To: <aYIWd9wzPIRa4gZc@google.com>

On Tue Feb 3, 2026 at 4:38 PM CET, Alice Ryhl wrote:
> On Tue, Feb 03, 2026 at 04:19:14PM +0100, Danilo Krummrich wrote:
>> 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
>
> If kvrealloc() does the right thing, then let's use it.

It should once the TODOs of vrealloc() are addressed. The reason I left them as
TODOs was that I didn't want to implement all the shrink and grow logic for
struct vm_area without having a user that actually needs it.

If binder needs it, I think we should do it.

  reply	other threads:[~2026-02-03 15:43 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-31 15:40 [PATCH v2 0/3] rust: alloc: add Vec shrinking methods Shivam Kalra
2026-01-31 15:40 ` [PATCH v2 1/3] rust: alloc: Add shrink_to and shrink_to_fit methods to Vec Shivam Kalra
2026-02-03 15:19   ` Danilo Krummrich
2026-02-03 15:38     ` Alice Ryhl
2026-02-03 15:43       ` Danilo Krummrich [this message]
2026-02-03 17:48         ` Shivam Kalra
2026-02-04 10:32           ` Alice Ryhl
2026-02-04 11:50             ` Danilo Krummrich
2026-02-04 21:55               ` Shivam Kalra
2026-01-31 15:40 ` [PATCH v2 2/3] rust: alloc: add KUnit tests for Vec shrinking Shivam Kalra
2026-02-01  0:08 ` [PATCH v2 3/3] binder: context: shrink all_procs vector to reclaim memory Shivam Kalra

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=DG5FWZ2CA3DR.2WBZ27YUYS705@kernel.org \
    --to=dakr@kernel.org \
    --cc=Liam.Howlett@oracle.com \
    --cc=aliceryhl@google.com \
    --cc=cmllamas@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=shivamklr@cock.li \
    --cc=urezki@gmail.com \
    --cc=vbabka@suse.cz \
    /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 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.