The title's map/unmap calls wait for Windows' large-page worker on the one big section; 2 MiB sections remove the wait #1087

Open
opened 2026-11-25 19:04:34 +00:00 by RyanCase94 · 4 comments
RyanCase94 commented 2026-11-25 19:04:34 +00:00 (Migrated from github.com)
Contributor

Imported from fxceless/victory-fork. Originally posted by RyanCase94 on 2026-11-25T19:04:34Z.


Following on from d510ee4 ("the dips while moving, measured"): a kernel trace says what the title's map and unmap calls wait for, and a small change removes the wait without changing how pages are mapped. Patch below; it applies cleanly to main at d510ee4.

What the calls wait for

Setup: RTX 4070 Ti, Ryzen 7 5800X, Windows 11 26200, --console series-x, the first minutes of the prologue. An xperf trace (PROC_THREAD+LOADER+CSWITCH+DISPATCHER, stacks on CSwitch and ReadyThread) taken while the title streams, read for 4 seconds:

  • 806 of the title's map/unmap calls blocked for 1 ms or more, 2.6 s in total.
  • Where they stood: ExfAcquirePushLockExclusiveEx under MiPostInsertVad < MiInsertVad < MiMapViewOfDataSection (1.06 s) and under MiManageSubsectionView < MiDeleteVad < MiUnmapVad (1.00 s). So mostly not the address space lock itself but the section's.
  • Who released them: for 2.06 s of the 2.6 s, one thread of the System process, from
    ExfReleasePushLockShared < MiTrimSection < MiTrimSharedPage < MiTradePage < MiClaimPhysicalRun < MiFindContiguousPagesEx < MiRebuildLargePage < MiRebuildLargePages < ExpWorkerThread.
  • That worker was on a processor 93 % of the time, nearly always inside MiViewMayContainPage < MiTrimSection.

So: Windows' large-page rebuild worker trades the section's pages one by one. For each page it looks through the section's views and holds the section meanwhile. XMemAllocatePhysicalPages makes one section per request (the title asks for 6.1 GiB at once) and the title maps it a 64 KiB view at a time, so that one section has views by the hundred thousand: every trade is slow and every trade holds all of the title's physical memory.

Ruled out on the way, by measurement: the kernel reads of title memory (VICTORY_COPY_PLAIN=1 changed nothing), write-watch askings (none over 1 ms), and crowding of the title's pinned threads (VICTORY_SPREAD=1 with all processors spare changed nothing).

The change

Sections of 2 MiB instead of one per request (VICTORY_SECTION_MB, 0 = as before). A trade then looks through a few dozen views and holds one small section. Mapping is otherwise as it was (still one view per run of consecutive pages of one section, so map_alias still maps page by page); Views::sections becomes a map because there are now thousands.

Measured

First 90 s after reaching the prison, map/unmap system calls of 1 ms or more:

calls time
one section per request about 11,000 about 60 s
2 MiB sections 31 55 ms

Not shown

  • Frame times in that phase did not change here (same share of frames over 250 ms; settled frame 128 ms either way). In my runs the long frames of that phase are the submit thread's (140 to 190 MB copied and up to 259 texture uploads a frame), so the mapping calls were not what the frame waited for. d510ee4 measures them on the render thread's way in cutscenes, so it may show more there.
  • Picture: no errors in the log and the prologue looks as before, but I have not checked faces through a whole cutscene, which is where the longer views broke.
  • Only NVIDIA, only Series X mode, only Windows (not Wine).
Patch
diff --git a/crates/victory-gpu/src/inplace.rs b/crates/victory-gpu/src/inplace.rs
index 0173b97..e660d27 100644
--- a/crates/victory-gpu/src/inplace.rs
+++ b/crates/victory-gpu/src/inplace.rs
@@ -274,11 +274,11 @@ struct Views {
     /// (`crate::watch` guards them all).
     pages: BTreeMap<(usize, u64), Vec<usize>>,
     /// Sections by handle: bytes, and whether made committed.
-    sections: Vec<(usize, u64, bool)>,
+    sections: BTreeMap<usize, (u64, bool)>,
 }
 
 static VIEWS: Mutex<Views> =
-    Mutex::new(Views { views: BTreeMap::new(), pages: BTreeMap::new(), sections: Vec::new() });
+    Mutex::new(Views { views: BTreeMap::new(), pages: BTreeMap::new(), sections: BTreeMap::new() });
 
 fn views() -> std::sync::MutexGuard<'static, Views> {
     VIEWS.lock().unwrap_or_else(|e| e.into_inner())
@@ -289,8 +289,7 @@ fn views() -> std::sync::MutexGuard<'static, Views> {
 pub fn title_memory_section(section: usize, bytes: u64, committed: bool) {
     {
         let mut v = views();
-        v.sections.retain(|s| s.0 != section);
-        v.sections.push((section, bytes, committed));
+        v.sections.insert(section, (bytes, committed));
     }
     // A view of our own made on an earlier section that had this handle's
     // number shows that section's pages, not this one's: it is forgotten
@@ -518,7 +517,7 @@ pub(crate) fn write_own(at: usize, bytes: &[u8]) -> Option<Vec<usize>> {
         if shown.len() > crate::watch::MANY_VIEWS {
             return None;
         }
-        let section_bytes = v.sections.iter().find(|s| s.0 == section)?.1;
+        let section_bytes = v.sections.get(&section)?.0;
         (section, offset, shown, section_bytes)
     };
     if offset + bytes.len() as u64 > section_bytes {
@@ -540,11 +539,18 @@ pub(crate) fn write_own(at: usize, bytes: &[u8]) -> Option<Vec<usize>> {
                 );
                 return None;
             }
-            tracing::info!(
-                section,
-                mb = section_bytes >> 20,
-                "a view of our own on a section of title pages, for what shaders wrote (VICTORY_BACK_OWN_VIEW=1)"
-            );
+            // Sections are small and many (the runtime's `VICTORY_SECTION_MB`):
+            // the first few are said, the rest counted.
+            static SAID: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0);
+            let said = SAID.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
+            if said < 4 || said.is_power_of_two() {
+                tracing::info!(
+                    section,
+                    mb = section_bytes >> 20,
+                    so_far = said + 1,
+                    "a view of our own on a section of title pages, for what shaders wrote (VICTORY_BACK_OWN_VIEW=1)"
+                );
+            }
             Some(Own {
                 base: at.Value as usize,
                 bytes: section_bytes,
@@ -1162,7 +1168,7 @@ fn census_of(spans: &[(u64, u64, bool)]) -> Vec<String> {
         bytes >> 20,
         big >> 20
     ));
-    for &(_, bytes, committed) in &v.sections {
+    for &(bytes, committed) in v.sections.values() {
         lines.push(format!(
             "census, a section of {} MB, {}",
             bytes >> 20,
diff --git a/crates/victory-hle/src/modules/xmem.rs b/crates/victory-hle/src/modules/xmem.rs
index e9d0dd8..0450d8b 100644
--- a/crates/victory-hle/src/modules/xmem.rs
+++ b/crates/victory-hle/src/modules/xmem.rs
@@ -412,59 +412,103 @@ pub extern "system" fn XMemAllocatePhysicalPages(
     }
     // SAFETY: checked non-null.
     let n = unsafe { *count };
-    let Some(size) = n.checked_mul(PAGE).filter(|&s| s > 0) else {
+    let Some(_) = n.checked_mul(PAGE).filter(|&s| s > 0) else {
         return 0;
     };
-    // A pagefile-backed section of `size` bytes, its pages committed when
-    // first mapped or written (`commit`): the title asks for 6.1
-    // GiB at once, which a busy host often cannot commit (error 1450).
-    // SAFETY: plain section creation.
-    let handle = unsafe {
-        CreateFileMappingW(
-            INVALID_HANDLE_VALUE,
-            std::ptr::null(),
-            // Under Wine a committed section is a sparse file, free until
-            // touched, and committing a reserved one page by page costs a
-            // wineserver request each that scans every range committed so
-            // far: commit it whole there.
-            PAGE_READWRITE | if on_wine() { SEC_COMMIT } else { SEC_RESERVE },
-            (size as u64 >> 32) as u32,
-            size as u32,
-            std::ptr::null(),
-        )
-    };
-    if handle.is_null() {
-        let error = std::io::Error::last_os_error();
-        tracing::warn!(n, %error, "XMemAllocatePhysicalPages failed");
-        // SAFETY: checked non-null.
-        unsafe { count.write(0) };
-        return 0;
+    // Pagefile-backed sections of `size` bytes together, their pages
+    // committed when first mapped or written (`commit`): the title asks for
+    // 6.1 GiB at once, which a busy host often cannot commit (error 1450).
+    //
+    // Not one section for the whole request but one per `section_pages()`
+    // pages (2 MiB; `VICTORY_SECTION_MB=0`: one section, as before). Why:
+    // the title maps these pages a 64 KiB view at a time, so one section
+    // came to have views by the hundred thousand. Windows' worker that
+    // gathers physical memory into large pages (MiRebuildLargePages) trades
+    // such a section's pages one by one, looks through all of the section's
+    // views for each (MiViewMayContainPage) and holds the section meanwhile;
+    // every map and unmap of any of its pages waits for it. A kernel trace
+    // while the title streamed (RTX 4070 Ti, Ryzen 7 5800X, 2026-11-25): the
+    // worker 93 % of a core in exactly that, 806 of the title's map and
+    // unmap calls blocked for 2.6 s out of 4, 2.06 s of it released by that
+    // worker; frames of half a second and more. With small sections a trade
+    // looks through a few dozen views and holds only its own section.
+    let per = section_pages().unwrap_or(n).max(1);
+    let mut sections: Vec<(Arc<Section>, usize)> = Vec::with_capacity(n.div_ceil(per));
+    let mut left = n;
+    while left > 0 {
+        let pages_here = left.min(per);
+        let bytes = pages_here * PAGE;
+        // SAFETY: plain section creation.
+        let handle = unsafe {
+            CreateFileMappingW(
+                INVALID_HANDLE_VALUE,
+                std::ptr::null(),
+                // Under Wine a committed section is a sparse file, free until
+                // touched, and committing a reserved one page by page costs a
+                // wineserver request each that scans every range committed so
+                // far: commit it whole there.
+                PAGE_READWRITE | if on_wine() { SEC_COMMIT } else { SEC_RESERVE },
+                (bytes as u64 >> 32) as u32,
+                bytes as u32,
+                std::ptr::null(),
+            )
+        };
+        if handle.is_null() {
+            let error = std::io::Error::last_os_error();
+            tracing::warn!(n, %error, "XMemAllocatePhysicalPages failed");
+            // All or nothing: the sections made so far close as they drop.
+            // SAFETY: checked non-null.
+            unsafe { count.write(0) };
+            return 0;
+        }
+        // For the GPU side's in-place census: only a committed section can
+        // be opened as a host heap.
+        victory_gpu::title_memory_section(handle as usize, bytes as u64, on_wine());
+        sections.push((Arc::new(Section(handle)), pages_here));
+        left -= pages_here;
     }
     tracing::debug!(
         n,
+        sections = sections.len(),
         flags = format_args!("{flags:#x}"),
         "XMemAllocatePhysicalPages"
     );
-    // For the GPU side's in-place census: only a committed section can be
-    // opened as a host heap.
-    victory_gpu::title_memory_section(handle as usize, size as u64, on_wine());
-    let section = Arc::new(Section(handle));
     let mut physical = physical();
     let first = physical.next_page;
     physical.next_page += n * FRAMES;
-    for index in 0..n {
-        let slice = Slice {
-            section: section.clone(),
-            index,
-        };
-        let number = first + index * FRAMES;
-        physical.pages.insert(number, slice);
-        // SAFETY: the title passes room for `n` page numbers.
-        unsafe { pages.add(index).write(number) };
+    let mut k = 0;
+    for (section, pages_here) in sections {
+        for index in 0..pages_here {
+            let slice = Slice {
+                section: section.clone(),
+                index,
+            };
+            let number = first + k * FRAMES;
+            physical.pages.insert(number, slice);
+            // SAFETY: the title passes room for `n` page numbers.
+            unsafe { pages.add(k).write(number) };
+            k += 1;
+        }
     }
     1
 }
 
+/// How many 64 KiB pages a section of physical pages holds at most
+/// (`VICTORY_SECTION_MB`, 2 by default; 0: `None`, one section for each
+/// request however large).
+fn section_pages() -> Option<usize> {
+    static PAGES: std::sync::OnceLock<Option<usize>> = std::sync::OnceLock::new();
+    *PAGES.get_or_init(|| {
+        let mb = std::env::var("VICTORY_SECTION_MB").ok().and_then(|v| v.parse::<usize>().ok()).unwrap_or(2);
+        let pages = (mb << 20) / PAGE;
+        tracing::info!(
+            "physical pages: {} (VICTORY_SECTION_MB)",
+            if pages == 0 { "one section for each request".to_string() } else { format!("sections of {mb} MiB") }
+        );
+        (pages > 0).then_some(pages)
+    })
+}
+
 /// Page numbers count 4 KiB frames, so a 64 KiB page's is a multiple of
 /// 16: the title keeps them as 21-bit `number >> 4` and rebuilds
 /// them with `<< 4` (128 GiB of pages at most).
<!-- greyfinch-sync:fxceless/victory-fork:issue:6611657679 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/issues/1089). Originally posted by [RyanCase94](https://github.com/RyanCase94) on 2026-11-25T19:04:34Z. --- Following on from d510ee4 ("the dips while moving, measured"): a kernel trace says what the title's map and unmap calls wait for, and a small change removes the wait without changing how pages are mapped. Patch below; it applies cleanly to `main` at d510ee4. ## What the calls wait for Setup: RTX 4070 Ti, Ryzen 7 5800X, Windows 11 26200, `--console series-x`, the first minutes of the prologue. An `xperf` trace (`PROC_THREAD+LOADER+CSWITCH+DISPATCHER`, stacks on `CSwitch` and `ReadyThread`) taken while the title streams, read for 4 seconds: - 806 of the title's map/unmap calls blocked for 1 ms or more, 2.6 s in total. - Where they stood: `ExfAcquirePushLockExclusiveEx` under `MiPostInsertVad < MiInsertVad < MiMapViewOfDataSection` (1.06 s) and under `MiManageSubsectionView < MiDeleteVad < MiUnmapVad` (1.00 s). So mostly not the address space lock itself but the section's. - Who released them: for 2.06 s of the 2.6 s, one thread of the System process, from `ExfReleasePushLockShared < MiTrimSection < MiTrimSharedPage < MiTradePage < MiClaimPhysicalRun < MiFindContiguousPagesEx < MiRebuildLargePage < MiRebuildLargePages < ExpWorkerThread`. - That worker was on a processor 93 % of the time, nearly always inside `MiViewMayContainPage < MiTrimSection`. So: Windows' large-page rebuild worker trades the section's pages one by one. For each page it looks through the section's views and holds the section meanwhile. `XMemAllocatePhysicalPages` makes one section per request (the title asks for 6.1 GiB at once) and the title maps it a 64 KiB view at a time, so that one section has views by the hundred thousand: every trade is slow and every trade holds all of the title's physical memory. Ruled out on the way, by measurement: the kernel reads of title memory (`VICTORY_COPY_PLAIN=1` changed nothing), write-watch askings (none over 1 ms), and crowding of the title's pinned threads (`VICTORY_SPREAD=1` with all processors spare changed nothing). ## The change Sections of 2 MiB instead of one per request (`VICTORY_SECTION_MB`, 0 = as before). A trade then looks through a few dozen views and holds one small section. Mapping is otherwise as it was (still one view per run of consecutive pages of one section, so `map_alias` still maps page by page); `Views::sections` becomes a map because there are now thousands. ## Measured First 90 s after reaching the prison, map/unmap system calls of 1 ms or more: | | calls | time | |---|---|---| | one section per request | about 11,000 | about 60 s | | 2 MiB sections | 31 | 55 ms | ## Not shown - Frame times in that phase did not change here (same share of frames over 250 ms; settled frame 128 ms either way). In my runs the long frames of that phase are the submit thread's (140 to 190 MB copied and up to 259 texture uploads a frame), so the mapping calls were not what the frame waited for. d510ee4 measures them on the render thread's way in cutscenes, so it may show more there. - Picture: no errors in the log and the prologue looks as before, but I have not checked faces through a whole cutscene, which is where the longer views broke. - Only NVIDIA, only Series X mode, only Windows (not Wine). <details><summary>Patch</summary> ```diff diff --git a/crates/victory-gpu/src/inplace.rs b/crates/victory-gpu/src/inplace.rs index 0173b97..e660d27 100644 --- a/crates/victory-gpu/src/inplace.rs +++ b/crates/victory-gpu/src/inplace.rs @@ -274,11 +274,11 @@ struct Views { /// (`crate::watch` guards them all). pages: BTreeMap<(usize, u64), Vec<usize>>, /// Sections by handle: bytes, and whether made committed. - sections: Vec<(usize, u64, bool)>, + sections: BTreeMap<usize, (u64, bool)>, } static VIEWS: Mutex<Views> = - Mutex::new(Views { views: BTreeMap::new(), pages: BTreeMap::new(), sections: Vec::new() }); + Mutex::new(Views { views: BTreeMap::new(), pages: BTreeMap::new(), sections: BTreeMap::new() }); fn views() -> std::sync::MutexGuard<'static, Views> { VIEWS.lock().unwrap_or_else(|e| e.into_inner()) @@ -289,8 +289,7 @@ fn views() -> std::sync::MutexGuard<'static, Views> { pub fn title_memory_section(section: usize, bytes: u64, committed: bool) { { let mut v = views(); - v.sections.retain(|s| s.0 != section); - v.sections.push((section, bytes, committed)); + v.sections.insert(section, (bytes, committed)); } // A view of our own made on an earlier section that had this handle's // number shows that section's pages, not this one's: it is forgotten @@ -518,7 +517,7 @@ pub(crate) fn write_own(at: usize, bytes: &[u8]) -> Option<Vec<usize>> { if shown.len() > crate::watch::MANY_VIEWS { return None; } - let section_bytes = v.sections.iter().find(|s| s.0 == section)?.1; + let section_bytes = v.sections.get(&section)?.0; (section, offset, shown, section_bytes) }; if offset + bytes.len() as u64 > section_bytes { @@ -540,11 +539,18 @@ pub(crate) fn write_own(at: usize, bytes: &[u8]) -> Option<Vec<usize>> { ); return None; } - tracing::info!( - section, - mb = section_bytes >> 20, - "a view of our own on a section of title pages, for what shaders wrote (VICTORY_BACK_OWN_VIEW=1)" - ); + // Sections are small and many (the runtime's `VICTORY_SECTION_MB`): + // the first few are said, the rest counted. + static SAID: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0); + let said = SAID.fetch_add(1, std::sync::atomic::Ordering::Relaxed); + if said < 4 || said.is_power_of_two() { + tracing::info!( + section, + mb = section_bytes >> 20, + so_far = said + 1, + "a view of our own on a section of title pages, for what shaders wrote (VICTORY_BACK_OWN_VIEW=1)" + ); + } Some(Own { base: at.Value as usize, bytes: section_bytes, @@ -1162,7 +1168,7 @@ fn census_of(spans: &[(u64, u64, bool)]) -> Vec<String> { bytes >> 20, big >> 20 )); - for &(_, bytes, committed) in &v.sections { + for &(bytes, committed) in v.sections.values() { lines.push(format!( "census, a section of {} MB, {}", bytes >> 20, diff --git a/crates/victory-hle/src/modules/xmem.rs b/crates/victory-hle/src/modules/xmem.rs index e9d0dd8..0450d8b 100644 --- a/crates/victory-hle/src/modules/xmem.rs +++ b/crates/victory-hle/src/modules/xmem.rs @@ -412,59 +412,103 @@ pub extern "system" fn XMemAllocatePhysicalPages( } // SAFETY: checked non-null. let n = unsafe { *count }; - let Some(size) = n.checked_mul(PAGE).filter(|&s| s > 0) else { + let Some(_) = n.checked_mul(PAGE).filter(|&s| s > 0) else { return 0; }; - // A pagefile-backed section of `size` bytes, its pages committed when - // first mapped or written (`commit`): the title asks for 6.1 - // GiB at once, which a busy host often cannot commit (error 1450). - // SAFETY: plain section creation. - let handle = unsafe { - CreateFileMappingW( - INVALID_HANDLE_VALUE, - std::ptr::null(), - // Under Wine a committed section is a sparse file, free until - // touched, and committing a reserved one page by page costs a - // wineserver request each that scans every range committed so - // far: commit it whole there. - PAGE_READWRITE | if on_wine() { SEC_COMMIT } else { SEC_RESERVE }, - (size as u64 >> 32) as u32, - size as u32, - std::ptr::null(), - ) - }; - if handle.is_null() { - let error = std::io::Error::last_os_error(); - tracing::warn!(n, %error, "XMemAllocatePhysicalPages failed"); - // SAFETY: checked non-null. - unsafe { count.write(0) }; - return 0; + // Pagefile-backed sections of `size` bytes together, their pages + // committed when first mapped or written (`commit`): the title asks for + // 6.1 GiB at once, which a busy host often cannot commit (error 1450). + // + // Not one section for the whole request but one per `section_pages()` + // pages (2 MiB; `VICTORY_SECTION_MB=0`: one section, as before). Why: + // the title maps these pages a 64 KiB view at a time, so one section + // came to have views by the hundred thousand. Windows' worker that + // gathers physical memory into large pages (MiRebuildLargePages) trades + // such a section's pages one by one, looks through all of the section's + // views for each (MiViewMayContainPage) and holds the section meanwhile; + // every map and unmap of any of its pages waits for it. A kernel trace + // while the title streamed (RTX 4070 Ti, Ryzen 7 5800X, 2026-11-25): the + // worker 93 % of a core in exactly that, 806 of the title's map and + // unmap calls blocked for 2.6 s out of 4, 2.06 s of it released by that + // worker; frames of half a second and more. With small sections a trade + // looks through a few dozen views and holds only its own section. + let per = section_pages().unwrap_or(n).max(1); + let mut sections: Vec<(Arc<Section>, usize)> = Vec::with_capacity(n.div_ceil(per)); + let mut left = n; + while left > 0 { + let pages_here = left.min(per); + let bytes = pages_here * PAGE; + // SAFETY: plain section creation. + let handle = unsafe { + CreateFileMappingW( + INVALID_HANDLE_VALUE, + std::ptr::null(), + // Under Wine a committed section is a sparse file, free until + // touched, and committing a reserved one page by page costs a + // wineserver request each that scans every range committed so + // far: commit it whole there. + PAGE_READWRITE | if on_wine() { SEC_COMMIT } else { SEC_RESERVE }, + (bytes as u64 >> 32) as u32, + bytes as u32, + std::ptr::null(), + ) + }; + if handle.is_null() { + let error = std::io::Error::last_os_error(); + tracing::warn!(n, %error, "XMemAllocatePhysicalPages failed"); + // All or nothing: the sections made so far close as they drop. + // SAFETY: checked non-null. + unsafe { count.write(0) }; + return 0; + } + // For the GPU side's in-place census: only a committed section can + // be opened as a host heap. + victory_gpu::title_memory_section(handle as usize, bytes as u64, on_wine()); + sections.push((Arc::new(Section(handle)), pages_here)); + left -= pages_here; } tracing::debug!( n, + sections = sections.len(), flags = format_args!("{flags:#x}"), "XMemAllocatePhysicalPages" ); - // For the GPU side's in-place census: only a committed section can be - // opened as a host heap. - victory_gpu::title_memory_section(handle as usize, size as u64, on_wine()); - let section = Arc::new(Section(handle)); let mut physical = physical(); let first = physical.next_page; physical.next_page += n * FRAMES; - for index in 0..n { - let slice = Slice { - section: section.clone(), - index, - }; - let number = first + index * FRAMES; - physical.pages.insert(number, slice); - // SAFETY: the title passes room for `n` page numbers. - unsafe { pages.add(index).write(number) }; + let mut k = 0; + for (section, pages_here) in sections { + for index in 0..pages_here { + let slice = Slice { + section: section.clone(), + index, + }; + let number = first + k * FRAMES; + physical.pages.insert(number, slice); + // SAFETY: the title passes room for `n` page numbers. + unsafe { pages.add(k).write(number) }; + k += 1; + } } 1 } +/// How many 64 KiB pages a section of physical pages holds at most +/// (`VICTORY_SECTION_MB`, 2 by default; 0: `None`, one section for each +/// request however large). +fn section_pages() -> Option<usize> { + static PAGES: std::sync::OnceLock<Option<usize>> = std::sync::OnceLock::new(); + *PAGES.get_or_init(|| { + let mb = std::env::var("VICTORY_SECTION_MB").ok().and_then(|v| v.parse::<usize>().ok()).unwrap_or(2); + let pages = (mb << 20) / PAGE; + tracing::info!( + "physical pages: {} (VICTORY_SECTION_MB)", + if pages == 0 { "one section for each request".to_string() } else { format!("sections of {mb} MiB") } + ); + (pages > 0).then_some(pages) + }) +} + /// Page numbers count 4 KiB frames, so a 64 KiB page's is a multiple of /// 16: the title keeps them as 21-bit `number >> 4` and rebuilds /// them with `<< 4` (128 GiB of pages at most). ``` </details>
HLVM04 commented 2026-11-25 21:05:55 +00:00 (Migrated from github.com)
Author
Contributor

Imported from fxceless/victory-fork. Originally posted by HLVM04 on 2026-11-25T20:34:29Z.


A data point for two of the "not shown" items: Series S mode, and frame times. RTX 5070 Ti, Ryzen 7 9800X3D, Windows 11 build 26200, first gameplay scene, on our own stack (an older fork main plus several open PRs and local changes).

The patch from this issue, applied alone with the default VICTORY_SECTION_MB=2:

  • median frame 73 ms; p90 105 ms, against about 118 ms without it
  • copy-back 18 ms a frame

So here the gain is mostly in the long frames, which fits the dips you describe. That's one scene and few runs, and I didn't take a kernel trace, so I can't say how many map/unmap calls still block. On top of it, #868's VICTORY_SKIP_WC_BACK=1 gave a median of 71–72 ms with no crash or device loss in 2 runs of 200 s.

Edit (2026-11-26): VICTORY_SKIP_WC_BACK=1 turned out not to be free on our stack: the room's lamp light goes missing and rooms render dark (our earlier runs were judged only by the character). The section-patch numbers above were taken without it.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7173872198 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/issues/1089#issuecomment-7173872198). Originally posted by [HLVM04](https://github.com/HLVM04) on 2026-11-25T20:34:29Z. --- A data point for two of the "not shown" items: Series S mode, and frame times. RTX 5070 Ti, Ryzen 7 9800X3D, Windows 11 build 26200, first gameplay scene, on our own stack (an older fork main plus several open PRs and local changes). The patch from this issue, applied alone with the default `VICTORY_SECTION_MB=2`: - median frame 73 ms; p90 105 ms, against about 118 ms without it - copy-back 18 ms a frame So here the gain is mostly in the long frames, which fits the dips you describe. That's one scene and few runs, and I didn't take a kernel trace, so I can't say how many map/unmap calls still block. On top of it, #868's `VICTORY_SKIP_WC_BACK=1` gave a median of 71–72 ms with no crash or device loss in 2 runs of 200 s. **Edit (2026-11-26):** `VICTORY_SKIP_WC_BACK=1` turned out not to be free on our stack: the room's lamp light goes missing and rooms render dark (our earlier runs were judged only by the character). The section-patch numbers above were taken without it.
Exopus-0x65f7ad0 commented 2026-11-25 22:07:25 +00:00 (Migrated from github.com)
Author
Contributor

Imported from fxceless/victory-fork. Originally posted by Exopus-0x65f7ad0 on 2026-11-25T21:47:59Z.


Confirmed on a third machine, and in the opening cutscene, where it pays the most: RTX 5060 Ti 8 GB, Ryzen 7 8700F, 16 GB RAM, Windows 11, Series S. Tree: fork main d510ee4 plus a stack of fork PRs (#868, #1031, #1063 among them). I applied your patch unchanged, with the default VICTORY_SECTION_MB=2.

I summed the frame log's remapping: field over the long frames from the first 3D frame to the first gameplay frame:

cutscene length frames mean fps remapping, summed
one section per request (runs 96-102, 5 runs) 112-155 s 118-305 1.0-2.6 32-65 s
2 MiB sections (run 104) 95 s 305 3.2 2.5 s

What remains in the cutscene's long frames is mostly the submit thread's copies (~11 GB over the cutscene) and page faults. No new defect in the picture: faces through the bar and prison shots look as they did before. One run with the patch so far, so the fps figure is a first reading. The remapping drop, though, is far outside the run-to-run noise.

🤖 Generated with Claude Code

<!-- greyfinch-sync:fxceless/victory-fork:comment:7175553759 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/issues/1089#issuecomment-7175553759). Originally posted by [Exopus-0x65f7ad0](https://github.com/Exopus-0x65f7ad0) on 2026-11-25T21:47:59Z. --- Confirmed on a third machine, and in the **opening cutscene**, where it pays the most: RTX 5060 Ti 8 GB, Ryzen 7 8700F, **16 GB RAM**, Windows 11, **Series S**. Tree: fork `main` d510ee4 plus a stack of fork PRs (#868, #1031, #1063 among them). I applied your patch unchanged, with the default `VICTORY_SECTION_MB=2`. I summed the frame log's `remapping:` field over the long frames from the first 3D frame to the first gameplay frame: | | cutscene length | frames | mean fps | remapping, summed | |---|---:|---:|---:|---:| | one section per request (runs 96-102, 5 runs) | 112-155 s | 118-305 | 1.0-2.6 | **32-65 s** | | 2 MiB sections (run 104) | **95 s** | 305 | **3.2** | **2.5 s** | What remains in the cutscene's long frames is mostly the submit thread's copies (~11 GB over the cutscene) and page faults. No new defect in the picture: faces through the bar and prison shots look as they did before. One run with the patch so far, so the fps figure is a first reading. The remapping drop, though, is far outside the run-to-run noise. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
KainanP commented 2026-11-26 12:07:19 +00:00 (Migrated from github.com)
Author
Contributor

Imported from fxceless/victory-fork. Originally posted by KainanP on 2026-11-26T11:23:37Z.


A synthetic reproduction of this stall, which needs no game, with numbers on an i7-14650HX: https://github.com/fxceless/victory-fork/pull/1274 (comment below the PR). 4 GiB of physical pages in one section, remapped page by page while another thread makes and frees memory, had 1,386 remaps of 1 ms or more in 10 s. With 2 MiB sections that drops to 28, and throughput goes from 6,644 to 50,607 remaps/s (median of 5 rounds). The same change is also proposed for upstream (Marvisak/VIctory#3177) and AnyXboxX (LooperSalty/AnyXboxX#352), with credit to you for the idea and the first patch.

AI use: Claude Code (Claude Opus 5.5) wrote the benchmark and this note.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7190667670 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/issues/1089#issuecomment-7190667670). Originally posted by [KainanP](https://github.com/KainanP) on 2026-11-26T11:23:37Z. --- A synthetic reproduction of this stall, which needs no game, with numbers on an i7-14650HX: https://github.com/fxceless/victory-fork/pull/1274 (comment below the PR). 4 GiB of physical pages in one section, remapped page by page while another thread makes and frees memory, had 1,386 remaps of 1 ms or more in 10 s. With 2 MiB sections that drops to 28, and throughput goes from 6,644 to 50,607 remaps/s (median of 5 rounds). The same change is also proposed for upstream (Marvisak/VIctory#3177) and AnyXboxX (LooperSalty/AnyXboxX#352), with credit to you for the idea and the first patch. _AI use: Claude Code (Claude Opus 5.5) wrote the benchmark and this note._
luisaugustz commented 2026-11-28 15:38:27 +00:00 (Migrated from github.com)
Author
Contributor

Imported from fxceless/victory-fork. Originally posted by luisaugustz on 2026-11-28T15:38:27Z.


Data point from AMD: RX 9070 XT, Ryzen 7 5800X, 32 GB, Windows 11, Series X 1.0.2.1, gameplay (driving around). Own fork build, VICTORY_MAP_THREADS=1.

Before the fix, xperf agreed with this issue: in a 12 s capture of a slow stretch, 91% of the blocked time in mapping calls was released by the System process's large page rebuild worker. A 12 s capture of a fast stretch had none from it.

Then I cherry-picked a531978d6 from #1274 and set VICTORY_SECTION_MB=2. One run before and one after, different driving:

one section 2 MiB sections
frames over 200 ms, per minute 12.0 0.6
frames over 400 ms, per minute 2.9 0
p99 frame time 235 ms 128 ms
time per mapping call 107 us 12 us

Median frame time at similar draw counts stayed about the same. No mapping errors.

Also: 8 mapping threads was clearly worse than 1 here before the fix (mean 119 vs 84 ms over six alternating 30 s pairs).

If you use VICTORY_PORT_CONSTANTS=1: it needs the title's 185 MB heap in one section. Keeping allocations up to 512 MB whole and splitting only larger ones let it open again for me.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7241622161 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/issues/1089#issuecomment-7241622161). Originally posted by [luisaugustz](https://github.com/luisaugustz) on 2026-11-28T15:38:27Z. --- Data point from AMD: RX 9070 XT, Ryzen 7 5800X, 32 GB, Windows 11, Series X 1.0.2.1, gameplay (driving around). Own fork build, `VICTORY_MAP_THREADS=1`. Before the fix, xperf agreed with this issue: in a 12 s capture of a slow stretch, 91% of the blocked time in mapping calls was released by the System process's large page rebuild worker. A 12 s capture of a fast stretch had none from it. Then I cherry-picked a531978d6 from #1274 and set `VICTORY_SECTION_MB=2`. One run before and one after, different driving: | | one section | 2 MiB sections | |---|---|---| | frames over 200 ms, per minute | 12.0 | 0.6 | | frames over 400 ms, per minute | 2.9 | 0 | | p99 frame time | 235 ms | 128 ms | | time per mapping call | 107 us | 12 us | Median frame time at similar draw counts stayed about the same. No mapping errors. Also: 8 mapping threads was clearly worse than 1 here before the fix (mean 119 vs 84 ms over six alternating 30 s pairs). If you use `VICTORY_PORT_CONSTANTS=1`: it needs the title's 185 MB heap in one section. Keeping allocations up to 512 MB whole and splitting only larger ones let it open again for me.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
fxceless/victory-fork#1087
No description provided.