mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Daniel Sedlak <daniel@sedlak.dev>
To: "Benno Lossin" <lossin@kernel.org>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Shankari Anand" <shankari.ak0208@gmail.com>
Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] rust: sync: extend module documentation of aref
Date: Wed, 23 Jul 2025 12:25:49 +0200	[thread overview]
Message-ID: <9bae0d3c-7900-474a-a0af-d2f90ec65012@sedlak.dev> (raw)
In-Reply-To: <20250722121441.224439-1-lossin@kernel.org>

Hi Benno,

On 7/22/25 2:14 PM, Benno Lossin wrote:
> Commit 07dad44aa9a9 ("rust: kernel: move ARef and AlwaysRefCounted to
> sync::aref") moved `ARef` and `AlwaysRefCounted` into their own module.
> In that process only a short, single line description of the module was
> added. Extend the description by explaining what is meant by "internal
> reference counting", the two items in the trait & the difference to
> `Arc`.
> 
> Signed-off-by: Benno Lossin <lossin@kernel.org>
> ---
>   rust/kernel/sync/aref.rs | 15 +++++++++++++++
>   1 file changed, 15 insertions(+)
> 
> diff --git a/rust/kernel/sync/aref.rs b/rust/kernel/sync/aref.rs
> index dbd77bb68617..1c212238c0e5 100644
> --- a/rust/kernel/sync/aref.rs
> +++ b/rust/kernel/sync/aref.rs
> @@ -1,6 +1,21 @@
>   // SPDX-License-Identifier: GPL-2.0
>   
>   //! Internal reference counting support.
> +//!
> +//! Many C types already have their own reference counting mechanism (e.g. by storing a
> +//! `refcount_t`). This module provides support for directly using their internal reference count
> +//! from Rust; instead of making users have to use an additional Rust-reference count in the form of
> +//! [`Arc`].
> +//!
> +//! The smart pointer [`ARef<T>`] acts similarly to [`Arc<T>`] in that it holds a refcount on the
> +//! underlying object, but this refcount is internal to the object. It essentially is a Rust
> +//! implementation of the `get_` and `put_` pattern used in C for reference counting.
> +//!
> +//! To make use of [`ARef<MyType>`], `MyType` needs to implement [`AlwaysRefCounted`]. It is a trait
> +//! for accessing the internal reference count of an object of the `MyType` type.
> +//!
> +//! [`Arc`]: crate::sync::Arc
> +//! [`Arc<T>`]: crate::sync::Arc

It got me curios. Why is it required to declare the doc reference for 
Arc and Arc<T>, but not ARef<MyType> and ARef<T>?

Is it because ARef is in file scope but not the Arc?

If so, you could just add

	use crate::sync::Arc;

in the file imports and you wouldn't have to duplicate the

	//! [`Arc`]: crate::sync::Arc
	//! [`Arc<T>`]: crate::sync::Arc

And even cleanup it a bit by simplifying

	[`Arc`](crate::sync::Arc) to [`Arc`]

in the AlwaysRefCounted trait.

Thanks!
Daniel


  reply	other threads:[~2025-07-23 10:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-22 12:14 Benno Lossin
2025-07-23 10:25 ` Daniel Sedlak [this message]
2025-07-23 10:51   ` Miguel Ojeda
2025-08-08  3:20 ` Alexandre Courbot
2025-09-14 23:19 ` Miguel Ojeda

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=9bae0d3c-7900-474a-a0af-d2f90ec65012@sedlak.dev \
    --to=daniel@sedlak.dev \
    --cc=a.hindborg@kernel.org \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=dakr@kernel.org \
    --cc=gary@garyguo.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=shankari.ak0208@gmail.com \
    --cc=tmgross@umich.edu \
    /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®