From b545ae2debc8555bd6a9b734046ed7e9752e0019 Mon Sep 17 00:00:00 2001 From: Vax Date: Mon, 23 Nov 2026 19:36:23 -0500 Subject: [PATCH] kernelx: a page moving between addresses is copied there, not via home A physical page mapped at one address and then mapped at another (XMemMapPhysicalPages / MapTitlePhysicalPages, one page a call) went home first: unmap_away committed its home again (home_again) and copied the page there, then map_pages copied it from home to the new address and gave the home back at the end of the call (move_home_away). In a sparse window each of those commits and decommits is a tile mapping (UpdateTileMappings), about 0.12-0.15 ms each on an RTX 4070 Ti: two of the four a moved page cost were the home's. A retail title moves tens of thousands of pages this way after its menus, one per call, on the thread that presents. Timing probes in that phase: about 1,400 calls a second at ~0.68 ms each, 96% of the thread's time, and thread dumps put it in the driver under map_tiles / unmap_tiles. With the presents stopped for more than 30 s the title's own stall watchdog ended it. A page that is mapped somewhere (and was used there) is now copied straight to its new address, and the old address is given back as unmap_away gives it back (decommit_away). Its home stays as it was: a home given back stays given back, and one still pending in away.gone is given back at the end of the call as before. A page mapped but never used (lazy) still takes the old path, which has nothing to copy. Assisted-by: Claude Code (Claude Opus 5.5) --- crates/xcl/src/hle/kernelx.rs | 91 ++++++++++++++++++++++++++++-- crates/xcl/src/hle/kernelx/lazy.rs | 5 ++ 2 files changed, 91 insertions(+), 5 deletions(-) diff --git a/crates/xcl/src/hle/kernelx.rs b/crates/xcl/src/hle/kernelx.rs index 69f13e05c6..6ac9cf7e6a 100644 --- a/crates/xcl/src/hle/kernelx.rs +++ b/crates/xcl/src/hle/kernelx.rs @@ -1038,12 +1038,19 @@ unsafe fn unmap_away(away: &mut Away, at: usize, committed: &std::ops::Range bool { + LAZY.read().unwrap_or_else(|e| e.into_inner()).contains(&page) +} + /// `page` is unmapped: true if it was never used (nothing to keep of it). pub(super) fn unmark(page: usize) -> bool { LAZY.write().unwrap_or_else(|e| e.into_inner()).remove(&page)