linux/rust/kernel/alloc
Shivam Kalra 47ac2a4b5c 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>
2026-02-26 21:37:53 -08:00
..
allocator rust: alloc: implement VmallocPageIter 2025-09-04 23:33:27 +02:00
kvec rust: alloc: use kernel::fmt 2025-10-20 04:04:23 +02:00
allocator.rs Summary of significant series in this pull request: 2025-10-02 18:18:33 -07:00
kbox.rs Summary of significant series in this pull request: 2025-10-02 18:18:33 -07:00
kvec.rs rust: kvec: implement shrink_to for KVVec 2026-02-26 21:37:53 -08:00
layout.rs drm next for 6.18-rc1 2025-10-02 12:47:25 -07:00