Re: Improve page refcount scalability
From: Kiryl Shutsemau
Date: Fri Oct 16 2026 - 10:51:59 EST
On Tue, Oct 13, 2026 at 11:43:14AM -0700, Linus Torvalds wrote:
> Comments?
There's a regression: the lockless read loses on large reads from large
folios.
In a 64-vCPU guest on a Threadripper 7975WX, 1 MiB reads of a cached
ext4 file are 9% slower from one thread with rcu-free-v3 than without
it, 64K reads 4% slower.
The reference path looks a large folio up once and copies it in one go.
The lockless one walks i_pages from the root and calls
copy_page_to_iter() for every 4K page.
I've added a cutoff to the lockless path: if the folio is large and the
read covers more than four of its pages, leave it to the slow path,
where one reference covers all of them.
if (folio != prev) {
if (!filemap_read_rcu_can_copy(folio, index, *last_index))
break;
/* Many pages of a large folio: one reference is cheaper */
if (folio_test_large(folio) &&
min_t(unsigned long, folio_next_index(folio) - index,
DIV_ROUND_UP(offset + iov_iter_count(iter),
PAGE_SIZE)) > 4)
break;
prev = folio;
}
With it, ext4 1 MiB reads match base and 64K reads are within 2%. Small
reads do not change. The cut is on the folio, not on the read size, so
files in 4K folios keep the gain on large reads: 1 MiB tmpfs reads from
one thread are ~30% faster than base.
Sounds reasonable?
I've pushed my tree here:
https://git.kernel.org/pub/scm/linux/kernel/git/kas/linux.git rcu-free/rfc-v1
I'm thinking of posting it as an RFC to make it easier to review.
Objections?
--
Kiryl Shutsemau / Kirill A. Shutemov