freenode
Kernel & Low-Level

Kernel page-table helpers drop useless loads on folded levels

Dummy returns and compile-time checks aim to fix redundant READ_ONCE traffic and unblock wider use of pXdp_get() in common code.

Yeoreum Yun and David Hildenbrand have proposed changing how Linux's generic page-table getters behave when a level is folded away at compile time, so the helpers stop forcing memory loads the kernel never uses.

By default, ptep_get() and its counterparts expand to READ_ONCE(). On configurations with compile-time folded tables, that still emits a load even though higher-level present and leaf checks are hardcoded and the value is ignored. Christophe Leroy hit the cost on 32-bit PowerPC, which blocked converting more common code to the helpers. The same pattern shows up on arm64 builds with two- or three-level tables, including redundant loads in the perf page-size path.

The series makes the getters return a dummy entry for folded levels instead of reading memory. Related offset, set, and page helpers gain compile-time checks so misuse of those dummies (stack copies passed where a live table pointer is required, or set operations on dummy values) fails the build. Call sites that already walked tables via stack snapshots, including KVM host mapping walks on RISC-V and LoongArch, vmscan range walks, and RISC-V vmalloc fault syncing, were reworked to pass real pointers or the lockless offset variants. x86 page-table dump and 1G direct-map gating were tightened so folded levels and Kconfig-disabled huge pages stay invisible to the compiler.

Existing code that still pokes folded levels through the older direct helpers is left alone. The new rules apply only to the pXdp_get()-based access model. The payoff is smaller generated code on folded configs and a path to move more generic MM logic onto the portable helpers without paying for dead loads.