]> git.ipfire.org Git - thirdparty/linux.git/commit
rust: kvec: implement shrink_to for KVVec
authorShivam Kalra <shivamkalra98@zohomail.in>
Mon, 16 Feb 2026 14:09:55 +0000 (19:39 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 27 Feb 2026 05:37:53 +0000 (21:37 -0800)
commit47ac2a4b5cd8f0cb826f6368c2fc0eeb97e5d55f
tree27b1fad3b4bf018a690ebd7dcd60084eabaae80e
parentd31ed22a0678da8948439c3009b01c4806a677c9
rust: kvec: implement shrink_to for KVVec

Implement shrink_to method specifically for `KVVec` (i.e.,
`Vec<T, KVmalloc>`). `shrink_to` reduces the vector's capacity to a
specified minimum.

For kmalloc-backed allocations, the method delegates to realloc(),
letting the allocator decide whether shrinking is worthwhile. For
vmalloc-backed allocations (detected via is_vmalloc_addr), shrinking
only occurs if at least one page of memory can be freed, using an
explicit alloc+copy+free since vrealloc does not yet support in-place
shrinking.

A TODO note marks this for future replacement with a generic shrink_to
for all allocators that uses A::realloc() once the underlying allocators
properly support shrinking via realloc.

Suggested-by: Alice Ryhl <aliceryhl@google.com>
Suggested-by: Danilo Krummrich <dakr@kernel.org>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Acked-by: Danilo Krummrich <dakr@kernel.org>
Signed-off-by: Shivam Kalra <shivamkalra98@zohomail.in>
Link: https://patch.msgid.link/20260216-binder-shrink-vec-v3-v6-1-ece8e8593e53@zohomail.in
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
rust/kernel/alloc/kvec.rs