zephyr/arch/x86/include
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Nicolas Pitre b488151896 arch/x86: mmu: support LRU eviction algorithm for demand paging
The LRU eviction algorithm needs to catch the first access to a loaded
page in order to call k_mem_paging_eviction_accessed() and move that
page to the tail of the queue. On ARM64 this is done with the MMU's
Access Flag: clearing AF causes a distinct fault on the next access.

On x86 there is no access-flag fault. The Accessed bit (PTE bit 5) is
set by hardware on access but never traps. The only way to force a
fault is to clear the Present bit, which already encodes the
"paged out" state — so a new state is needed:

   PTE == 0                         -> unmapped
   P=0, A=1, upper=location         -> paged out
   P=0, G=1, upper=PFN              -> LRU-tracked (new)
   P=1                              -> normally mapped

Bit G (Global, bit 8) is never set by Zephyr on x86 (CR4.PGE is not
used), so it is free to use as a private marker when P=0. No existing
PTE state needs to be displaced. This stays out of the way of the
KPTI path (which uses the PAT bit) and of the permission-backup bits
(IGNORED0..2) used for memory domain handling.

arch_page_info_get(addr, NULL, clear_accessed=true) is overloaded
under CONFIG_EVICTION_LRU to both query the prior flags and transition
the page to the LRU-tracked state via a new helper that updates all
domain ptables. arch_page_location_get() recognizes the tracked state
as paged-in so the core demand-paging code treats the page as resident.

The page fault handler intercepts LRU-tracking faults in-line before
k_mem_page_fault() dispatch: restore P, clear the tracking bit, and
call k_mem_paging_eviction_accessed() directly. This avoids the risk
of recursing through do_page_fault() with z_mm_lock held.

KPTI co-exists with demand paging but its PTE encoding is not yet
wired up to the LRU state, so tracking is gated on !X86_KPTI for now.

Fixes: #75132

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2026-05-12 22:16:56 +02:00
..
ia32 arch: *: remove check for CONFIG_SOC_PER_CORE_INIT_HOOK 2026-01-07 19:39:53 +01:00
intel64 arch: *: remove check for CONFIG_SOC_PER_CORE_INIT_HOOK 2026-01-07 19:39:53 +01:00
cet.h arch/x86: Use Zephyr HW shadow stack arch interface 2025-09-02 07:56:48 +02:00
cet_asm.inc arch/x86: Support shadow stack on ia32 2025-09-02 07:56:48 +02:00
kernel_arch_data.h x86: add exception handling for control protection exception 2025-09-02 07:56:48 +02:00
kernel_arch_func.h arch: define struct arch_esf and deprecate z_arch_esf_t 2024-06-04 14:02:51 -05:00
offsets_short_arch.h x86: optimize locations of psp and thread ptables 2020-01-13 16:35:10 -05:00
x86_mmu.h arch/x86: mmu: support LRU eviction algorithm for demand paging 2026-05-12 22:16:56 +02:00