From: "Danilo Krummrich" <dakr@kernel.org>
To: "Shivam Kalra via B4 Relay"
<devnull+shivamkalra98.zohomail.in@kernel.org>
Cc: shivamkalra98@zohomail.in,
"Lorenzo Stoakes" <lorenzo.stoakes@oracle.com>,
"Vlastimil Babka" <vbabka@suse.cz>,
"Liam R. Howlett" <Liam.Howlett@oracle.com>,
"Uladzislau Rezki" <urezki@gmail.com>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Arve Hjønnevåg" <arve@android.com>,
"Todd Kjos" <tkjos@android.com>,
"Christian Brauner" <brauner@kernel.org>,
"Carlos Llamas" <cmllamas@google.com>,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v5 2/3] rust: alloc: add KUnit tests for KVVec shrink_to
Date: Sun, 15 Feb 2026 23:10:33 +0100 [thread overview]
Message-ID: <DGFVO6LW5B9C.18MHNWH1WFM28@kernel.org> (raw)
In-Reply-To: <20260215-binder-shrink-vec-v3-v5-2-6e5e56d69766@zohomail.in>
On Sat Feb 14, 2026 at 9:35 PM CET, Shivam Kalra via B4 Relay wrote:
> diff --git a/rust/kernel/alloc/kvec.rs b/rust/kernel/alloc/kvec.rs
> index e7bc439538e4..0d5d69296a9f 100644
> --- a/rust/kernel/alloc/kvec.rs
> +++ b/rust/kernel/alloc/kvec.rs
> @@ -1510,4 +1510,116 @@ fn add(value: &mut [bool]) {
> func.push_within_capacity(false).unwrap();
> }
> }
> +
> + #[test]
> + fn test_kvvec_shrink_to() {
> + use crate::page::PAGE_SIZE;
> +
> + // Calculate elements per page for u32.
> + let elements_per_page = PAGE_SIZE / core::mem::size_of::<u32>();
NIT: Wouldn't it be a bit more straight forward to just use u8 for all the
tests?
> + #[test]
> + fn test_kvvec_shrink_to_empty() {
> + use crate::page::PAGE_SIZE;
> +
> + let elements_per_page = PAGE_SIZE / core::mem::size_of::<u64>();
> +
> + // Create a vector with large capacity but no elements.
> + let mut v = KVVec::<u64>::with_capacity(elements_per_page * 4, GFP_KERNEL).unwrap();
> +
> + assert!(v.is_empty());
> + let initial_capacity = v.capacity();
> +
> + // Shrink empty vector to zero.
> + v.shrink_to(0, GFP_KERNEL).unwrap();
> +
> + // Should have freed the allocation.
> + assert!(v.capacity() < initial_capacity);
I think this assert!() should rather check for v.capacity() == 0.
> + assert!(v.is_empty());
> + }
next prev parent reply other threads:[~2026-02-15 22:10 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-14 20:35 [PATCH v5 0/3] rust: alloc: add KVVec shrinking method Shivam Kalra via B4 Relay
2026-02-14 20:35 ` [PATCH v5 1/3] rust: kvec: implement shrink_to for KVVec Shivam Kalra via B4 Relay
2026-02-14 20:35 ` [PATCH v5 2/3] rust: alloc: add KUnit tests for KVVec shrink_to Shivam Kalra via B4 Relay
2026-02-15 22:10 ` Danilo Krummrich [this message]
2026-02-14 20:35 ` [PATCH v5 3/3] rust_binder: shrink all_procs when deregistering processes Shivam Kalra via B4 Relay
2026-02-15 22:13 ` [PATCH v5 0/3] rust: alloc: add KVVec shrinking method Danilo Krummrich
2026-02-16 8:40 ` Alice Ryhl
2026-02-16 9:41 ` Shivam Kalra
2026-02-16 8:45 ` Alice Ryhl
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DGFVO6LW5B9C.18MHNWH1WFM28@kernel.org \
--to=dakr@kernel.org \
--cc=Liam.Howlett@oracle.com \
--cc=a.hindborg@kernel.org \
--cc=aliceryhl@google.com \
--cc=arve@android.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=brauner@kernel.org \
--cc=cmllamas@google.com \
--cc=devnull+shivamkalra98.zohomail.in@kernel.org \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=shivamkalra98@zohomail.in \
--cc=tkjos@android.com \
--cc=tmgross@umich.edu \
--cc=urezki@gmail.com \
--cc=vbabka@suse.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox