mirror of
https://github.com/torvalds/linux.git
synced 2026-11-20 13:03:48 +00:00
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 <[email protected]> Suggested-by: Danilo Krummrich <[email protected]> Reviewed-by: Alice Ryhl <[email protected]> Acked-by: Danilo Krummrich <[email protected]> Signed-off-by: Shivam Kalra <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>