From: Andreas Hindborg <a.hindborg@kernel.org>
To: Danilo Krummrich <dakr@kernel.org>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Tamir Duberstein" <tamird@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Onur Özkan" <work@onurozkan.dev>,
"Lorenzo Stoakes" <ljs@kernel.org>,
"Vlastimil Babka" <vbabka@kernel.org>,
"Liam R. Howlett" <liam@infradead.org>,
"Uladzislau Rezki" <urezki@gmail.com>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org
Subject: Re: [PATCH v4] rust: add a ring buffer implementation
Date: Wed, 02 Dec 2026 19:48:42 +0100 [thread overview]
Message-ID: <8733sfselx.fsf@t14s.mail-host-address-is-not-set> (raw)
In-Reply-To: <DN9JOBBO20ZC.1GHJZQT3KJ4B4@kernel.org>
"Danilo Krummrich" <dakr@kernel.org> writes:
> On Thu Nov 26, 2026 at 1:53 PM CET, Andreas Hindborg wrote:
>> Add a fixed-capacity FIFO ring buffer. The implementation uses a circular
>> buffer with head and tail pointers, providing constant-time push and pop
>> operations.
>>
>> The module includes a few tests covering basic operations, wrap-around
>> behavior, interleaved push/pop sequences, and edge cases such as
>> single-capacity buffers.
>>
>> Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
>
> NIT: Please add the "alloc:" prefix to the patch subject.
>
>> + pub fn new(capacity: usize, flags: Flags) -> Result<Self> {
>> + let slots = capacity.checked_add(1).ok_or(ENOMEM)?;
>> + let mut nodes = Vec::with_capacity(slots, flags)?;
>> +
>> + for _ in 0..nodes.capacity() {
>
> I think this should be 0..slots. When Option<T> is zero-sized, nodes.capacity()
> returns usize::MAX, so the ring reports usize::MAX - 1 free slots instead of the
> requested capacity.
>
>> + nodes.push_within_capacity(None)?;
>> + }
>> +
>> + // INVARIANT: `nodes` holds `nodes.capacity() >= slots >= 1` slots, all
>> + // of which are vacant. Thus:
>> + // - `head` points at a vacant slot.
>> + // - `tail` need not point at an occupied slot, since the buffer is
>> + // empty.
>> + // - The buffer is empty and `head == tail`.
>> + // - The buffer has at least one vacant slot.
>> + Ok(Self {
>> + nodes,
>> + head: 0,
>> + tail: 0,
>> + })
>> + }
>
> [snip]
>
>> +#[kunit_tests(rust_kernel_ringbuffer)]
>> +mod tests {
>
> This needs a separate Kconfig.
>
> I did consider fixing this up on my end, but didn't want to make too many
> changes without having it on the list.
>
> I'm happy to still pick it up if you want to provide a quick diff (or simply a
> v5).
I'll ship a v5 today.
Best regards,
Andreas Hindborg
prev parent reply other threads:[~2026-12-02 18:48 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 12:53 Andreas Hindborg
2026-12-01 16:42 ` Danilo Krummrich
2026-12-02 18:48 ` Andreas Hindborg [this message]
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=8733sfselx.fsf@t14s.mail-host-address-is-not-set \
--to=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=gary@garyguo.net \
--cc=liam@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ljs@kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=urezki@gmail.com \
--cc=vbabka@kernel.org \
--cc=work@onurozkan.dev \
/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
all inboxes | Powered by JetHome®