Re: [PATCH v2 2/2] mm/memory: reuse the whole exclusive large folio on a write fault
From: David Hildenbrand (Arm)
Date: Sat Sep 19 2026 - 06:11:16 EST
On 9/19/26 09:31, Yuan-Hao Hsu wrote:
> With blocks of 16 PTEs a PTE-mapped 2M THP still takes 32 reuse faults
> and a 1M folio 16. Lift the bound to the page table: the walk then
> covers the PTEs that map the folio in this page table, at most
> PTRS_PER_PTE of them, and one fault does the work for the folio.
>
> Its cost, measured as the time of the store that takes it, against
> 420 ns for a reuse fault today (x86-64, i7-12700KF, medians, ns):
>
> reuse fault fault that COW fault that
> (patched) allocated it copies 4K
> 1M mTHP 5,400- 5,700 63,000-68,000 1,500
> 2M THP, PTE-mapped 10,000-10,500 126,000 1,500
>
> That is 14-20 ns per PTE, about 2 ns of it the scan. Builds that
> differ only by NOPs in front of the function take either 10,100 or
> 7,500 ns for the 2M folio, with a period of 32 bytes: the loop of
> modify_prot_commit_ptes() changes speed with its address.
>
> What it buys, 256 MiB after fork() and the child's exit, medians of 15
> runs, two boots of each kernel:
>
> 16 PTEs whole folio
> one byte per page, seq
> 1M mTHP 5.7 / 5.8 ms 4.1 / 4.0 ms
> 2M THP, PTE-mapped 5.7 / 5.8 ms 3.9 / 3.9 ms
> one byte per page, random order
> 2M THP, PTE-mapped 7.4 / 7.5 ms 4.9 / 5.1 ms
> memset()
> 2M THP, PTE-mapped 40.2 / 39.4 ms 38.1 / 37.2 ms
> 8 threads, random order
> 2M THP, PTE-mapped 0.9 / 1.0 ms 0.7 / 0.7 ms
> one store per 64K, 2M folios 3.3 / 3.3 ms 1.5 / 1.6 ms
> one store per 2M, 2M folios 0.1 / 0.1 ms 1.4 / 1.4 ms
>
Are you measuring the worst-case latency of a single write fault or only the
average over all writes?
--
Cheers,
David