Re: [RFC PATCH 00/18] mm: read the page cache without folio references
From: Harry Yoo
Date: Mon Oct 19 2026 - 17:24:53 EST
On Mon, Oct 19, 2026 at 04:48:53PM +0100, Kiryl Shutsemau (Meta) wrote:
> Small reads of one file from many CPUs all take and drop a reference on
> the same folio, and its refcount bounces between the CPUs. This series
> lets filemap_read() and shmem copy from the page cache without taking a
> reference. It is Linus' RFC [1], reworked: a folio that such a reader
> may copy from is freed only after an RCU grace period.
>
> Only the folios that reads keep coming back to get the flag,
> PG_rcu_free: those that folio_mark_accessed() finds as accessed as the
> LRU records. Streaming reads and data that never gets hot are not
> deferred, so the memory held back stays small and most frees are not
> touched.
By applying this to hot folios only, small reads would benefit only when
they contend on the refcount. That further narrows down the scope of
workload that would benefit from this. Random or sequential small reads
still perform the atomics on the refcount.
Looking at what Linus mentioned as "Willy reported real users having
scalability issues in that area a couple of years ago in a discussion
about buffereed IO scalability limits:
https://lore.kernel.org/all/Zds8T9O4AYAmdS9d@xxxxxxxxxxxxxxxxxxxx/
"
On that thread, from Willy:
> Not artificial; this was a real customer with a real workload. I don't
> know how much about it I can discuss publically, but my memory of it was a
> system writing a log with 64 byte entries, millions of entries per second.
> Occasionally the system would have to go back and look at an entry in the
> last few seconds worth of data (so it would still be in the page cache).
>
> This customer was quite savvy, so they actually implemented and tested
> the lookup-copy-lookup-again algorithm in their custom kernel, and saw
> a speedup from it.
https://lore.kernel.org/all/Zdz9p_Kn0puI1KEL@xxxxxxxxxxxxxxxxxxxx
Again from willy, from the same thread:
> On Mon, Feb 26, 2024 at 09:17:33AM -0800, Linus Torvalds wrote:
> > Willy - tangential side note: I looked closer at the issue that you
> > reported (indirectly) with the small reads during heavy write
> > activity.
> >
> > Our _reading_ side is very optimized and has none of the write-side
> > oddities that I can see, and we just have
> >
> > filemap_read ->
> > filemap_get_pages ->
> > filemap_get_read_batch ->
> > folio_try_get_rcu()
> >
> > and there is no page locking or other locking involved (assuming the
> > page is cached and marked uptodate etc, of course).
> >
> > So afaik, it really is just that *one* atomic access (and the matching
> > page ref decrement afterwards).
>
> Yep, that was what the customer reported on their ancient kernel, and
> we at least didn't make that worse ...
https://lore.kernel.org/all/Zduto30LUEqIHg4h@xxxxxxxxxxxxxxxxxxxx
>From the discussion I'm not sure if the scenario above would benefit
from this.
Maybe we should try to either 1) find a better heuristic to mark
which folios should have PG_rcu_free to make it beneficial for wider
range of workloads or 2) identify workload that heavly contends on the
refcount of a small set of folios...
--
Cheers,
Harry / Hyeonggon