Re: [PATCH v3 0/4] rust: alloc: add Vec shrinking methods
From: Danilo Krummrich
Date: Tue Feb 10 2026 - 15:54:18 EST
On Tue Feb 10, 2026 at 9:43 PM CET, Danilo Krummrich wrote:
> On Tue Feb 10, 2026 at 9:05 PM CET, Alice Ryhl wrote:
>> On Tue, Feb 10, 2026 at 4:05 PM Danilo Krummrich <dakr@xxxxxxxxxx> wrote:
>>>
>>> On Tue Feb 10, 2026 at 2:57 PM CET, Alice Ryhl wrote:
>>> > On Tue, Feb 10, 2026 at 07:08:09PM +0530, Shivam Kalra wrote:
>>> >> This is a follow-up to my v3 series:
>>> >> https://lore.kernel.org/rust-for-linux/20260207-binder-shrink-vec-v3-v3-0-8ff388563427@xxxxxxx/
>>> >>
>>> >> Hi all,
>>> >>
>>> >> Thanks for the feedback on v3. Before I respin, I want to confirm
>>> >> the direction for v4 to avoid unnecessary iterations.
>>> >>
>>> >> Proposed changes for v4:
>>> >>
>>> >> 1. Drop the Shrinkable trait entirely. Make shrink_to() a normal
>>> >> method on Vec<T, A> that calls A::realloc(). (Danilo)
>>> >>
>>> >> 2. Add a temporary ShrinkQuirk trait to handle the vmalloc workaround
>>> >> (page-boundary check + manual alloc+copy+free) until vrealloc
>>> >> gains in-place shrinking support. (Danilo)
>>> >
>>> > I don't think you want any new traits at all. What types would even
>>> > implement the trait? The special code can go in the realloc() method of
>>> > Vmalloc struct in rust/kernel/alloc/allocator.rs.
>>>
>>> I did not propose to move this into the realloc() functions of the corresponding
>>> allocators intentionally, as there is a difference between calling realloc() and
>>> shrink_to().
>>>
>>> I don't want that some user of e.g. Vmalloc::realloc() experiences page wise
>>> shrinking by copy. This is acceptable for Vec::shrink_to(), but not for
>>> realloc() in general.
>>
>> Ok. In that case we can add a method on KVVec directly for this
>> purpose, but I still don't think we need a trait?
>
> KVVec::realloc() should not have this behavior either, we only want it for
s/KVVec::realloc()/KVec::shrink_to()/
> VVec::shrink_to() and KVVec::shrink_to(), so I think we need a temporary quirk
> trait.
Unless you mean to implement shrink_to() for VVec and KVVec only, that would be
fine with me as well.