Re: [PATCH v3 0/4] rust: alloc: add Vec shrinking methods

From: Shivam Kalra

Date: Wed Feb 11 2026 - 04:36:34 EST


On 11/02/26 14:27, Danilo Krummrich wrote:
> On Wed Feb 11, 2026 at 9:41 AM CET, Shivam Kalra wrote:
>> Thanks Alice. I'll go with the standalone helper function approach
>> with separate impl blocks for Vec<T, Vmalloc> and Vec<T, KVmalloc>.
>
> If it's only needed for KVmalloc, which apparently is the case, let's just add
> it for KVVec only.
>
> Also, please make sure to add a TODO comment mentioning why this workaround
> exists and what it should be replaced with, i.e. a generic shrink_to() that
> calls into A::realloc().
Thanks for the discussion on v3. The direction for v4 is now clear.
Summary of changes for v4:
1. Drop the Shrinkable trait entirely. (Danilo)
2. Implement shrink_to() only for KVVec (impl<T> Vec<T, KVmalloc>),
since that covers the actual use case (binder). No new traits
needed. (Danilo,Alice)
3. Add a TODO comment explaining this is a temporary workaround
(page-boundary check + manual alloc+copy+free) that should be
replaced with a generic Vec<T, A>::shrink_to() calling
A::realloc() once vrealloc gains in-place shrinking. (Danilo)
4. In the binder patch, use a less aggressive shrink strategy to
avoid shrink-then-regrow oscillation: (Alice)
if len < cap / 4 {
shrink_to(cap / 2);
}
5. Fix commit prefix to rust_binder: instead of rust: binder:. (Alice)

Also noting that starting from v4, I will be sending patches from
a new email address: shivamkalra98@xxxxxxxxxxx
I previously sent patches as shivamklr@xxxxxxx, then briefly from
shivamkalra98@xxxxxxxxx. Both accounts ran out of quota, so all
future patches (v4+) will come from this address.
Thanks,
Shivam