Re: Improve page refcount scalability

From: Linus Torvalds

Date: Tue Oct 13 2026 - 19:43:01 EST


On Tue, 13 Oct 2026 at 15:43, Kiryl Shutsemau <kirill@xxxxxxxxxxxxx> wrote:
>
> There's a race in filemap_read_rcu_batch(). If the folio is replaced
> under us with a new one and then i_size is extended, we can read data
> that never got written there:

Hmm. Wouldn't it be better to move the i_size check up, and then have
one single check for that

if (xas_reload(&xas) != folio)
break;

case?

Otherwise we end up with two of them, one inside that "folio != prev" case...

IOW, I wonder if we could just make the whole

if (!test_bit(PG_rcu_free, &folio->flags.f))
break;
smp_rmb();
if (xas_reload(&xas) != folio)
break;

be unconditional, and move the i_size read up there too (I notice that
the comment about uptodate got in there too - PG_rcu_free indirectly
does imply that, so it's not *wrong*, but it's perhaps a bit
surprising).

That said:

> My branch contains a few more changes that address downstream effects of
> RCU-freeing the page cache. But we can come back to that later once we get
> agreement on the core mechanism.

Would you be willing to take this whole series over? I'm going to be
on vacation starting Friday *and* do the merge window next week, and
realistically won't have time for it. So...

Linus