Skip to content
HN On Hacker News ↗

Reversing the Next-Page Prefetcher in Skylake-X

▲ 31 points • 0 comments • by todsacerdoti • 5d ago • HN discussion ↗

Pangram verdict · v3.3

We believe that this entire text is human-written.

0 %

AI likelihood · overall

Human
100% human-written 0% AI-generated
SEGMENTS · HUMAN 2 of 2
SEGMENTS · AI 0 of 2
WORD COUNT 639
PEAK AI % 0% · §2
Analyzed
Nov 22
backend: pangram/v3.3
Segments scanned
2 windows
avg 320 words each
Distribution
100 / 0%
human / AI fraction
Verdict
Human
Pangram v3.3

Article text · 639 words · 2 segments analyzed

Human AI-generated
§1 Human · 0%

Introduction Intel publishes very little about next-page prefetchers in their P-cores. Back in the Ivy Bridge days, it was known that IVB included a next-page prefetcher thanks to this ancient excerpt from an old copy of the Intel Architectures Optimization Reference Manual: Hardware prefetch enhancement: A next-page prefetcher (NPP) is added in Intel microarchitecture code name Ivy Bridge. The NPP is triggered by sequential accesses to cache lines approaching the page boundary, either upwards or downwards. A recent issue of the optimization manual states that Redwood Cove includes a Last Level Cache (LLC) Page Prefetcher which is like NPP but with a slightly more sophisticated prefetch algorithm: The LLC Page Prefetcher extends the Next-Page-Prefetcher algorithm, which detects a sequence of accesses that are about to reach the end of a page (either going up towards the next page in memory or down towards the previous page in memory) and triggers a linear prefetch to the start of the next predicted page. NPP intends to prefetch the translation of the next page and initiate prefetching of the first few cache lines from that predicted page. The LLC Page Prefetch enhances Next-Page Prefetcher in two significant ways: It issues prefetches two pages ahead in linear address space. The prefetch attempts to bring the entire 4Kb page to the last level cache using opportunistic IDI request slots without the DCU or MLC buffers. Redwood Cove is a relatively recent microarchitecture which shipped in Meteor Lake P-cores starting late 2023. Ivy Bridge on the other hand is very old; It launched back in 2012 and was discontinued by 2015 right before Skylake launched. That raises the question, what happened in-between? Did every microarchitecture after IVB include a next-page prefetcher? It’s unlikely that the details remain unchanged from one microarchitecture to the next but as it turns out, I recently got unlimited access to a Skylake-X machine that I didn’t have to pay a single dime for. Given the setup, it’s only natural I got nerd-sniped into reversing the next-page prefetcher…and that’s what this post is about. I hope you enjoy it! So What’s a Prefetcher Hardware component that preloads data that the program might need soon. The goal is to eliminate memory stalls when the CPU actually demands the piece of data that the prefetcher could have loaded earlier. All kinds of prefetchers exist in modern CPUs. Next-Line prefetchers prefetch the immediate next cache line when the N’th cache line is accessed. Stride prefetchers (usually IP-based) track the stride of consecutive memory accesses that originate from the same instruction and if the access pattern turns out to be regular enough, it eagerly initiates the load from address that it predicted. Next-Page Prefetchers preload page table entries into the Translation Lookaside Buffer (TLB) provided software traverses memory pages in predictable manner. These by no means are the only three kind; a high-performance CPU may implement many other types of prefetchers, some of which are documented in this Intel whitepaper. Prefetchers that are required to act fast are logically simple and tend not to cross page boundaries because that may complicate things with, e.g. page faults and page walks on TLB misses. For example, the next-line prefetcher is supposed to fetch the next cache line if the accesses are sequential, but if the next cache line sits in a different page it may decide not to prefetch at all. Next-page prefetchers are slightly different in that regard; they prefetch the next page table entry (PTE) into the TLB. They have to work across page boundaries by design. In this post I’ll try to answer the following questions: Does Skylake-X have a next-page prefetcher? If yes, what triggers the next-page prefetch? How many “future” PTEs are prefetched? Where does the NPP load future PTEs? What’s the direction of the prefetch? Forward-only? Backward-only (that’d be weird!)?

§2 Human · 0%

Both?