Re: [PATCH v3 0/4] rust: alloc: add Vec shrinking methods
From: Danilo Krummrich
Date: Tue Feb 10 2026 - 10:08:24 EST
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.