From: "David Hildenbrand (Arm)" <david@kernel.org>
To: "Matthew Wilcox (Oracle)" <willy@infradead.org>,
Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org
Subject: Re: [PATCH] mm: Document the folio refcount a little better
Date: Wed, 17 Jun 2026 13:22:16 +0200 [thread overview]
Message-ID: <aa419310-de31-4119-84cd-67474d2ba917@kernel.org> (raw)
In-Reply-To: <20260526200032.353868-1-willy@infradead.org>
On 5/26/26 22:00, Matthew Wilcox (Oracle) wrote:
> Expand the documentation of folio_ref_count() to talk about expected,
> temporary and spurious refcounts as well as the concept of freezing.
>
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> ---
> include/linux/page_ref.h | 18 ++++++++++++++++++
> 1 file changed, 18 insertions(+)
>
> diff --git a/include/linux/page_ref.h b/include/linux/page_ref.h
> index 94d3f0e71c06..9f5c75d06f76 100644
> --- a/include/linux/page_ref.h
> +++ b/include/linux/page_ref.h
> @@ -71,6 +71,12 @@ static inline int page_ref_count(const struct page *page)
> * folio_ref_count - The reference count on this folio.
> * @folio: The folio.
> *
> + * Folios contain a reference count. When that reference count reaches
> + * zero, the folio is referred to as frozen. At this point, it will
> + * usually be returned to the memory allocator, but some parts of the
> + * kernel freeze folios in order to perform unusual operations on them
> + * such as splitting or migration.
> + *
> * The refcount is usually incremented by calls to folio_get() and
> * decremented by calls to folio_put(). Some typical users of the
> * folio refcount:
> @@ -82,6 +88,18 @@ static inline int page_ref_count(const struct page *page)
> * - Pipes
> * - Direct IO which references this page in the process address space
> *
> + * The reference count has three components: expected, temporary and
> + * spurious. The expected reference count of a folio is that which
> + * we would logically expect it to be from just reading the code.
> + * Temporary refcounts are gained by threads which need a temporary
> + * reference to make sure the folio isn't reallocated while they use it.
> + * Spurious refcounts are gained by threads which, thanks to RCU walks
I think we often call them "Speculative references".
Not just RCU (GUP-fast doesn't even use RCU for page tables). We also have PFN
walkers that don't involve the pagecache or page tables at all. They don't find
stale pointers.
In essence, all these users use folio_try_get() and friends to grab a reference
speculatively, while the folio might have been freed concurrently, or the
pointer from where they might have obtained the folio could now be stale.
Maybe it's clearer to explain it from that angle.
--
Cheers,
David
next prev parent reply other threads:[~2026-06-17 11:22 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-26 20:00 [PATCH] mm: Document the folio refcount a little better Matthew Wilcox (Oracle)
2026-06-17 11:22 ` David Hildenbrand (Arm) [this message]
2026-06-17 13:31 ` Matthew Wilcox
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=aa419310-de31-4119-84cd-67474d2ba917@kernel.org \
--to=david@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=linux-mm@kvack.org \
--cc=willy@infradead.org \
/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