Skip to content

Memory: plan the coherent GPU heaps on the commit the page files can grow to - #3546

Open
Chrysana wants to merge 1 commit into
xcl-dev:mainfrom
Chrysana:memory/commit-free-page-file-growth
Open

Chrysana wants to merge 1 commit into
xcl-dev:mainfrom
Chrysana:memory/commit-free-page-file-growth

Conversation

@Chrysana

@Chrysana Chrysana commented Nov 30, 2026 •

Copy link
Copy Markdown

XCL reads free commit as GlobalMemoryStatusEx's ullAvailPageFile, which counts each page file only at its current size. Windows grows a page file only when commit gets close to the current limit. So on a PC whose page files start small (the Windows default, or for example 2 GB growing to 16/32 GB), XCL reads a few GB free while much more is available. The check in uma.rs that puts the title's GPU heaps in the coherent window wants 17,408 MB of free commit at startup, so it keeps them out. This PR lets that one check count what each page file can still grow by: the heaps are planned once and live the whole run.

The compile gates keep reading the commit that is free now. They admit compiles that allocate side by side, and Windows can fail allocations when page-file growth lags behind concurrent demand (Microsoft). Under a job's commit limit the growth isn't counted either, because such a limit doesn't rise with the page files. Both follow thehollowedone's reviews below. Part of #2996, where the plan was posted first (comment).

What #2996 measured on a 32 GB PC with an RX 9070 XT (amd-dev and the hive recipe), with growable page files:

  • In the run where every page file started at 2 GB, Windows grew the commit limit from 44.4 to 60.9 GB during the run. XCL read a median of 1.7 GB free and kept the title's GPU heaps out of the coherent window.
  • In all 4 runs the throttle cut pipeline building to 1–2 workers, and presents stopped at world load. This PR does not change that throttle; see Not tested.

What is in it

  • crates/xcl/src/gpu/recomp/dxc.rs:
    • CommitSource { now, growth, job_limited }.
    • commit_free() is ullAvailPageFile, as on main.
    • The new commit_capacity() adds page_file_growth(). For each page file that's its maximum minus its current size, from NtQuerySystemInformation(SystemPageFileInformationEx), capped by the free space on its volume (GetDiskFreeSpaceExW), and 0 when either is unknown. The page files are logged once (commit: the page files can grow by N MB more than their size now (…)).
    • job_commit_limit(): if the process's immediate job sets JOB_OBJECT_LIMIT_PROCESS_MEMORY or JOB_OBJECT_LIMIT_JOB_MEMORY, no growth is added (logged once). ullAvailPageFile doesn't show job limits: on Windows 11 build 26200 a process in an 8 GB job read the system's 42 GB free.
    • wait_for_memory admits through wait_admitted, which reads only the current value.
    • 4 unit tests: growth from small page files; the volume cap, a fixed size, an unknown volume and a file over its maximum; a read of this machine's page files; and the gate boundary (2 GiB now, 20 GiB of growth, one background compile running: the second waits until 7 GiB are free now).
  • crates/xcl/src/gpu/uma.rs: heaps_window() takes the capacity query (dxc::commit_capacity). 1 test from CommitSource to the window: 4 GiB now and 20 GiB of growth give 4,095 MB outside a job and 512 MB under a job's limit; 17 GiB now is enough on its own; with no stored heaps there's no query.
  • crates/xcl/src/hle/d3d12x/real.rs: big_compile_commit_free() reads dxc::commit_free() instead of calling GlobalMemoryStatusEx itself. It's the same value as before.
  • Changing the gate to read capacity(), or capacity() to ignore the job limit, fails the matching test.

Tested

  • AMD Radeon RX 9070 XT 16 GB (driver 32.0.32015.2008), Ryzen 7 9800X3D, 32 GB RAM, Windows 11 25H2 build 26200.9974, rustc 1.100.1 (stable-x86_64-pc-windows-msvc); debug build for the tests, release for the title runs
  • cargo test --workspace --no-fail-fast -- --test-threads=4 on main d0832e61 merged with ae8050f1 (clean merge, git diff --check clean): 2887 passed, 9 failed, 51 ignored. On main d0832e61: 2882 passed, 9 failed, 51 ignored. The 5 more passes are this PR's tests. The same 8 tests fail on both, so they come from main on this card, not this PR: fuzz_validate_and_gpu_1, fuzz_validate_and_gpu_3, gpu_smem_flat_descriptor_windows_and_limits, f32_programs_on_the_gpu, gpu_f32_compares_with_nan, gpu_float_compares_random, gpu_ps_readfirstlane_loop_on_a_primitive_edge_ends, and the e2e two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs (counted twice).
  • SKIPPED (6, the same on both): 2× no heap windows, 1× driver cache needs Windows Developer Mode, 3× no D3D12 debug layer
  • The page files read on this machine: C: 8,196 of 16,384 MB, D: 2,048 of 16,384 MB, X: 32,768 of 32,768 MB. Logged growth: 22,524 MB, which is (16,384 − 8,196) + (16,384 − 2,048) + 0.

Regression run

The page-file A/B on this head. Retail title, 60 s smoke runs, main and this PR alternated over 2 rounds, XCL_DIRECT_DXIL=1 on both sides: on AMD, current main crashes in AMD's shader compiler at ~43 s without it (#3544, fixed by #3455).

The page files on C: and D: can grow; X: is fixed at 32 GB. Before each run, a small helper held commit (VirtualAlloc(MEM_COMMIT), no RAM touched), so every run started at 11.4–12.3 GB of free commit. That's about what this PC has on a normal day with its usual programs open. The runs started from VS Code, inside a job with no memory limit.

run XCL's startup line frames peak commit
main ff0c364b r1 / r2 UMA: 12332 MB / 12164 MB of commit free, under 17408 MB: the title's GPU heaps stay outside unified memory (512 MB window) 1688 / crash at 56.7 s 17,168 / 18,424 MB
this PR ae8050f1 r1 / r2 commit: the page files can grow by 22524 MB more than their size now, then UMA opened (…, 4095 MB coherent window) 1687 / 1698 16,819 / 16,675 MB
  • main's r2 crash is in AMD's shader compiler (amdxc64.dll+0x85f80f, read at address 0x8). It hit the thread building graphics PSO 26aa07cb05c04290 (310,732 B DXIL). The PR's runs didn't get to that pipeline within 60 s, and neither did main's r1.
  • It isn't from this PR. On the previous head, cf7d80d2, it crashed main and this PR alike, 6 times. It went away after AMD's shader cache was cleared, and now it's back on the fresh cache as runs reach that pipeline again. So it's not a damaged cache, as I'd thought: AMD's compiler crashes on that pipeline. It's not Since #3243, AMD's shader compiler crashes (amdxc64.dll, null read) ~43 s into the retail title on an RX 9070 XT; XCL_DIRECT_DXIL=1 avoids it #3544's address (+0x735dd8), and with XCL_DIRECT_DXIL=1 graphics pipelines stay on the HLSL path.

Under a job's commit limit, the same 60 s title run of this head in a job with a 37 GB JOB_OBJECT_LIMIT_JOB_MEMORY (XCL_PREPARE=0), at 11.6 GB free, logged:

commit: this process's job caps its commit (process 0 MB, job 37888 MB): the page files' growth is not counted for the GPU heaps
UMA: 11655 MB of commit free, under 17408 MB: the title's GPU heaps stay outside unified memory (a larger page file gives them the coherent window)

It got the 512 MB window and ended by itself (exit 0, job peak commit 16.9 GB).

xcl-smoke v1
commit: ff0c364b3de011c13ed45865480c21918a79ec89
gpu: AMD Radeon RX 9070 XT
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1688 (PresentX 1688)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17168 MB
xcl-smoke v1
commit: ae8050f16375a210d3a3f12f56293d039cfe54bc
gpu: AMD Radeon RX 9070 XT
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1687 (PresentX 1687)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16819 MB
xcl-smoke v1
commit: ff0c364b3de011c13ed45865480c21918a79ec89
gpu: AMD Radeon RX 9070 XT
title: 21222967
seconds: 60
exit: 0xc0000005
frames shown: none logged (the run did not reach its end)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 2
peak commit: 18424 MB
xcl-smoke v1
commit: ae8050f16375a210d3a3f12f56293d039cfe54bc
gpu: AMD Radeon RX 9070 XT
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1698 (PresentX 1698)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16675 MB

Not tested

AI use

  • Claude Code (Claude Opus 5.5) wrote the code and the tests, ran the suite and the guarded title runs, and drafted this description. The gate/capacity split and the job-limit check follow thehollowedone's reviews. I read the diff and checked the results before pushing.

@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:memory Virtual/physical memory, arenas, VRAM budget, UMA area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 gpu:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test) labels Nov 30, 2026
@Chrysana
Chrysana marked this pull request as ready for review November 30, 2026 22:20
@github-actions github-actions Bot added needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU labels Nov 30, 2026
@thehollowedone

thehollowedone commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

merge-check
base: d0832e6
head: 7bbc957
merge: clean
build: cargo build --workspace -> not run after the focused finding
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> not run after the focused finding; SKIPPED: 0 in the focused runs. A test-only admission check on the unchanged head failed (0 passed, 1 failed, 0 ignored). With the local candidate below, cargo test --offline --locked -p xcl --lib memory_gate_tests --target-dir ..\target -- --test-threads=4 passed (7 passed, 0 failed, 0 ignored).
review: The new commit_free() adds possible future page-file growth to ullAvailPageFile for every caller. That estimate is useful when planning the coherent GPU heap, but wait_for_memory, big_slots, and the driver compile gates use it to admit concurrent allocations now. In the synthetic gate check, one background DXC compile was active, current headroom was 2 GiB, and the page file could grow by 20 GiB. The unchanged head admitted a second background compile despite a 6 GiB reserve; with this estimate, it can admit many more before the file grows. Microsoft documents allocation failures when page-file growth lags concurrent demand. Keep current commit headroom for compile admission and the growth-aware capacity for long-lived heap planning. Add a regression at the query-to-gate boundary that supplies both values, so the second background worker waits until current headroom reaches the threshold. I read the full three-file diff. A title run and an actual allocation-failure reproduction remain untested.
performance: Reasoned risk of additional concurrent compile memory pressure; no frame-time, world-load, or memory delta was measured. The candidate preserves the growth-aware UMA decision.
verdict: not yet: future page-file capacity is used as immediately available commit for parallel compile admission.
hardware / tool and model: NVIDIA RTX 3080 Ti (621.40), Ryzen 7 9800X3D, Windows build 26300, rustc 1.99.1 / OpenAI Codex (GPT-6.2 Sol) traced and tested the candidate; OpenAI Codex (GPT-6.2 Astra) independently checked the memory-budget contract.

Local candidate diff against the PR head
diff --git a/crates/xcl/src/gpu/recomp/dxc.rs b/crates/xcl/src/gpu/recomp/dxc.rs
@@
-/// Commit that can still be had, the page files' growth included ([`avail_page_file`]), or
-/// `None` if the query fails.
+/// Commit currently available to this process, or `None` if the query fails.
 pub fn commit_free() -> Option<u64> {
     avail_page_file()
 }

+/// Commit capacity after page-file growth, for planning long-lived GPU heaps.
+pub fn commit_capacity() -> Option<u64> {
+    avail_page_file().map(|now| now.saturating_add(page_file_growth()))
+}
@@
-/// Available page-file commit bytes from Windows, or `None` if the query fails: what is free
-/// against the page files' current size (`ullAvailPageFile`) and what they can still grow by
-/// (`page_file_growth`). Windows grows a page file when a commit needs it, so with page files that
-/// start small (the default, and a 2 GB start with a 16 GB maximum) `ullAvailPageFile` alone read
-/// a few GB free on a 32 GB PC while over 20 GB more could be had: the title's GPU heaps stayed
-/// out of the coherent window (`uma`) and the compiles it waited for stood at these gates.
+/// Available commit from Windows at the page files' current size, or `None` on query failure.
 fn avail_page_file() -> Option<u64> {
@@
-    (unsafe { GlobalMemoryStatusEx(&mut m) } != 0).then(|| m.ullAvailPageFile.saturating_add(page_file_growth()))
+    (unsafe { GlobalMemoryStatusEx(&mut m) } != 0).then_some(m.ullAvailPageFile)
 }
diff --git a/crates/xcl/src/gpu/uma.rs b/crates/xcl/src/gpu/uma.rs
@@
-/// Commit that can still be had, the page files' growth included (`dxc::commit_free`).
+/// Commit capacity including possible page-file growth (`dxc::commit_capacity`).
 fn free_commit() -> usize {
-    crate::gpu::recomp::dxc::commit_free().map_or(usize::MAX, |b| b as usize)
+    crate::gpu::recomp::dxc::commit_capacity().map_or(usize::MAX, |b| b as usize)
 }
diff --git a/crates/xcl/src/hle/d3d12x/real.rs b/crates/xcl/src/hle/d3d12x/real.rs
@@
-/// That much commit is free, the page files' growth included (true when that is not known).
+/// That much commit is free now (true when that is not known).

@github-actions github-actions Bot removed needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU labels Nov 30, 2026
@Chrysana
Chrysana force-pushed the memory/commit-free-page-file-growth branch from 7bbc957 to cf7d80d Compare December 1, 2026 03:25
@Chrysana

Chrysana commented Dec 1, 2026

Copy link
Copy Markdown
Author

Thanks, @thehollowedone, agreed. Counting growth that hasn't happened yet is right for the one-time heap plan but not for admitting compiles side by side. I adopted your split and squashed it into the one commit; new head cf7d80d2:

  • dxc::commit_free() is current headroom again (ullAvailPageFile alone). wait_for_memory, big_slots, pieces_at_once and the driver-compile and build-ahead checks through big_compile_commit_free admit on it, as on main.
  • New dxc::commit_capacity(): current headroom plus the page files' growth. Only uma::free_commit reads it, for the coherent-heap decision.
  • Regression at the query-to-gate boundary: wait_for_memory now goes through wait_admitted(gate, source, …), which takes a CommitSource { now, growth } and admits on now only. a_background_compile_waits_for_commit_free_now_not_the_page_files_growth supplies 2 GiB now and 20 GiB of growth, with one background compile running and a 6 GiB reserve. The second compile waits, then goes in once 7 GiB are free now. With wait_admitted reading capacity() instead, the test fails ("a second background compile went in on page-file growth that had not happened").

I updated the description with the suite, the page-file A/B and the regression runs on the new head. The A/B shows the split keeps the fix: the PR still gets the 4,095 MB coherent window at 11.5–11.9 GB free, where main stays at 512 MB. During the regression runs, main and this PR both started crashing in amdxc64.dll (+0x85f80f) compiling the same graphics PSO, main first. That's not #3544's address. After AMD's shader cache was moved aside, 3 more rounds ran clean on both sides. The details are in the description.

@Chrysana Chrysana changed the title Memory: count page-file growth in the commit XCL reads as free Memory: plan the coherent GPU heaps on the commit the page files can grow to Dec 1, 2026
@thehollowedone

Copy link
Copy Markdown
Contributor

One process-limit boundary remains on head cf7d80d2. CommitSource::capacity() adds system page-file growth to GlobalMemoryStatusEx().ullAvailPageFile. Microsoft defines that field as the maximum this process can still commit, which may be smaller than system-wide headroom; a hard job memory limit does not rise when a page file grows. For example, if a process has 4 GiB left under such a limit and the system page files could grow by 20 GiB, this calculation returns 24 GiB although the process can still commit only 4 GiB. coherent_hint_for can then clear its 17 GiB threshold and choose a coherent GPU-heap window the process cannot back.

Please cap growth-aware capacity by any remaining hard process/job commit limit, or conservatively use current process headroom when that limit is present; keep the page-file growth benefit for unrestricted processes. A synthetic query-to-routing regression can supply 4 GiB process headroom, 20 GiB system growth and a hard job limit, then check that the coherent window does not take the growth path. A control without the hard limit should retain it. This is an API-contract/source finding, not an observed allocation failure on this head. Microsoft's ullAvailPageFile definition

AI use: Codex (GPT-6.2 Sol) checked the PR call path and Microsoft documentation; Codex (GPT-6.2 Astra) independently checked the process-limit case.

@thehollowedone

Copy link
Copy Markdown
Contributor

One refinement to my process-limit note on head cf7d80d2: checking only QueryInformationJobObject(NULL, JobObjectExtendedLimitInformation) would miss a cap on an ancestor job. Microsoft says the null handle selects the process's immediate job, while nested jobs inherit the most restrictive applicable commit limit.

For a conservative fix that preserves growth-aware planning for processes outside jobs, use IsProcessInJob with a null job handle to detect any job. If it reports membership, use current process headroom for the heap decision unless an effective cap for the full job chain is known; otherwise retain the page-file growth estimate. A focused regression should cover an unconstrained immediate child job under a memory-limited parent, as well as a process outside a job. This is a source/API-contract follow-up; I did not run that nested-job regression.

AI use: Codex (GPT-6.2 Sol) checked the Windows API contracts and drafted this note.

…grow to

XCL reads free commit as GlobalMemoryStatusEx's ullAvailPageFile, which
counts each page file at its current size. Windows grows a page file only
when commit nears the current limit, so with page files that start small
(the default, or e.g. 2 GB growing to 16/32 GB) the reading stays at a few
GB for a whole run while much more can be had.

On a 32 GB PC with an RX 9070 XT (xcl-dev#2996), that kept the title's GPU heaps
out of the coherent window: uma.rs wants 17,408 MB of commit free before
the title starts, and read a few GB.

dxc::commit_capacity() is new: ullAvailPageFile plus what each page file
can still grow by (its maximum less its size, from NtQuerySystemInformation
(SystemPageFileInformationEx), capped by the free space on its volume, and
0 when that is not known; the sizes are logged once). uma::free_commit
reads it, since those heaps are planned once and live the whole run.

The compile gates keep admitting on commit free now (dxc::commit_free(),
ullAvailPageFile alone): wait_for_memory, big_slots, pieces_at_once and the
driver-compile and build-ahead checks through big_compile_commit_free,
which now reads dxc::commit_free() instead of its own GlobalMemoryStatusEx
call. Microsoft documents allocations failing when page-file growth lags
concurrent demand, so growth that has not happened is not counted for
compiles started side by side. A regression test at the query-to-gate
boundary supplies both values (2 GB now, 20 GB of growth, one background
compile running) and checks a second one waits until 7 GB are free now.

Under a job's commit limit the growth is not counted: such a limit does
not rise with the page files, and ullAvailPageFile does not show it (on
Windows 11 build 26200 a process in an 8 GB job read the system's 42 GB
free). dxc::job_commit_limit() reads the immediate job's limits
(QueryInformationJobObject with a null handle: JOB_OBJECT_LIMIT_PROCESS_MEMORY
or JOB_OBJECT_LIMIT_JOB_MEMORY); a limit on an outer job of nested jobs
cannot be read from inside. uma::heaps_window() takes the capacity query,
and a regression from CommitSource to the window checks that 4 GiB now
and 20 GiB of growth give the heaps the window outside a job and not
under a job limit.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Chrysana
Chrysana force-pushed the memory/commit-free-page-file-growth branch from cf7d80d to ae8050f Compare December 1, 2026 04:35
@Chrysana

Chrysana commented Dec 1, 2026

Copy link
Copy Markdown
Author

Thanks for both notes. I checked the API contract on this PC before changing anything, and it doesn't hold here. On Windows 11 build 26200, ullAvailPageFile doesn't show job limits:

process ullAvailPageFile system free commit (GetPerformanceInfo)
started from VS Code (already in a job, no memory limit) 42.4 GB 42.4 GB
in a job with an 8 GB JOB_OBJECT_LIMIT_JOB_MEMORY 42.6 GB 42.6 GB
in an unlimited job nested under that 8 GB job 42.6 GB 42.6 GB
in a job with an 8 GB JOB_OBJECT_LIMIT_PROCESS_MEMORY 42.6 GB 42.6 GB

So main's check already reads the system figure inside a job: an 8 GB job reads 42 GB, clears 17 GB and takes the window. Nothing in XCL sees a job limit today, and falling back to current headroom wouldn't respect one either.

On IsProcessInJob: everything started from VS Code here is in a job (pwsh ← cmd ← the IDE, breakaway allowed, no memory limit). Only processes started from Explorer are in none, and all my A/B runs ran inside such a job. Dropping the growth for any job would turn the fix off for IDE terminals and launchers that use jobs, without making the limited case right.

So head ae8050f1 takes the part that can be read from inside the process:

  • dxc::job_commit_limit(): if the immediate job (QueryInformationJobObject with a null handle) sets JOB_OBJECT_LIMIT_PROCESS_MEMORY or JOB_OBJECT_LIMIT_JOB_MEMORY, commit_capacity() adds no growth, and that's logged. A limit on an outer job of nested jobs can't be read from inside, as you say. I haven't written the nested-job regression, because the code can't detect that case; it's listed under Not tested. Honouring job limits in every gate (capping by what the job has left) would be its own change.
  • Query-to-routing regression: uma::heaps_window() now takes the capacity query. a_job_commit_limit_keeps_the_gpu_heaps_off_the_page_files_growth goes from CommitSource to the window: 4 GiB now and 20 GiB of growth give 4,095 MB outside a job and 512 MB under a job limit. It fails when capacity() ignores the limit.
  • On the retail title, inside a 37 GB JOB_MEMORY job at 11.6 GB free, the log shows commit: this process's job caps its commit (process 0 MB, job 37888 MB): the page files' growth is not counted for the GPU heaps, then the 512 MB window. Outside a job at the same free commit, this head takes 4,095 MB (A/B in the description).

The description is updated for the new head.

@thehollowedone

Copy link
Copy Markdown
Contributor

On head ae8050f1, the new compile-admission regression depends on the waiter thread running during a 300 ms sleep. If the worker starts after now rises to 7 GiB, even a regressed wait_admitted that admits on page-file growth can pass. This is a test coverage issue; I found no new production-path defect in this review.

The fake commit query can return 2 GiB on its first call and 7 GiB on its second. That makes the rejected first attempt and later admission deterministic without another thread. A growth closure that panics also catches an accidental switch from free() to capacity(). The candidate below is source-reviewed, not run.

Candidate test-only diff
diff --git a/crates/xcl/src/gpu/recomp/dxc.rs b/crates/xcl/src/gpu/recomp/dxc.rs
@@ fn a_background_compile_waits_for_commit_free_now_not_the_page_files_growth() {
-        use std::sync::atomic::AtomicU64;
+        use std::cell::Cell;
         let gate = MemoryGate::new();
         let reserve = 6 * GB;
-        let now = AtomicU64::new(2 * GB);
-        let source = CommitSource { now: || Some(now.load(Ordering::SeqCst)), growth: || 20 * GB, job_limited: || false };
-        assert_eq!(source.capacity(), Some(22 * GB));
+        let plan = CommitSource { now: || Some(2 * GB), growth: || 20 * GB, job_limited: || false };
+        assert_eq!(plan.capacity(), Some(22 * GB));
         let unwanted: Wanted = Box::new(|| false);
-        assert!(gate.try_admit(reserve, || source.free(), false, &unwanted), "the first compile goes in with none running");
-        let admitted = AtomicBool::new(false);
-        let early = std::thread::scope(|s| {
-            s.spawn(|| {
-                let unwanted: Wanted = Box::new(|| false);
-                wait_admitted(&gate, &source, reserve, Duration::from_secs(60), &unwanted);
-                admitted.store(true, Ordering::SeqCst);
-            });
-            std::thread::sleep(Duration::from_millis(300));
-            let early = admitted.load(Ordering::SeqCst);
-            now.store(7 * GB, Ordering::SeqCst);
-            early
-        });
-        assert!(!early, "a second background compile went in on page-file growth that had not happened");
-        assert!(admitted.load(Ordering::SeqCst), "it goes in once 7 GB are free now");
+        assert!(gate.try_admit(reserve, || Some(2 * GB), false, &unwanted));
+        let reads = Cell::new(0);
+        let source = CommitSource {
+            now: || {
+                let n = reads.get();
+                reads.set(n + 1);
+                Some(if n == 0 { 2 * GB } else { 7 * GB })
+            },
+            growth: || panic!("compile admission must not read future page-file growth"),
+            job_limited: || false,
+        };
+        wait_admitted(&gate, &source, reserve, Duration::from_secs(60), &unwanted);
+        assert_eq!(reads.get(), 2, "reject 2 GiB now, then admit at 7 GiB now");
         assert_eq!(gate.working.load(Ordering::SeqCst), 2);

AI use: OpenAI Codex (GPT-6.2 Astra) identified the scheduling gap; OpenAI Codex (GPT-6.2 Sol) checked the admission path and prepared this suggestion.

@thehollowedone

Copy link
Copy Markdown
Contributor

Correction to my process-limit note and follow-up: I inferred that GlobalMemoryStatusEx().ullAvailPageFile reflected the process's remaining job-memory allowance. The author's measured probes show that it continued to report system-wide free commit inside both process-limited and job-limited jobs, including a nested job. My proposed fallback to ullAvailPageFile for every job would therefore not enforce those limits, and would discard the page-file-growth benefit for jobs with no memory cap. Please disregard that recommendation.

Current head ae8050f1 instead detects the limits it can query on the immediate job and scopes the growth estimate accordingly. An inherited limit on an outer job remains a documented limitation, not a failure I reproduced. My separate compile-admission test finding is unaffected; it concerns whether that regression test can pass without exercising its intended low-headroom state.

AI use: OpenAI Codex (GPT-6.2 Sol) rechecked the thread and corrected its earlier inference.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

merge-check
base: 7d86c5d
head: ae8050f
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2901 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: read the whole diff (dxc.rs, uma.rs, real.rs). "Can grow to" is current free commit (ullAvailPageFile) plus, per page file, its maximum minus its current size capped by free space on its volume (NtQuerySystemInformation(SystemPageFileInformationEx)), with no growth counted inside a memory-limited job. It changes the default path only for the heap plan: on a PC whose page files are small now but can grow, the coherent window goes from 512 MB to the title's stored need plus 512 MB (up to 4095 MB at 24 GB of RAM or more, RAM/8 below that); the compile gates still read free commit as on main. Findings: (1) from reading, not measured: this doesn't add commit (the PR's runs peak about where main's does), but the window grows, and per auto_coherent_cap's comment Windows keeps that window resident in RAM, so PCs under 24 GB with small growable page files are the ones whose behaviour changes most, while all the PR's runs are on 32 GB; a 16 GB run or a Not tested line would cover it. (2) uma.rs ~1087-1091 still labels the number "MB of commit free" while outside a job it includes the growth. (3) The thread-timing gap in a_background_compile_waits_for_commit_free_now_not_the_page_files_growth that a reviewer raised is still open on this head. (4) #632 edits the same block and calls free_commit(), which this removes, so whichever lands second needs a rebase. Fine: the SYSTEM_PAGEFILE_INFORMATION_EX layout (40 bytes, info class 144), sizes in pages, an empty result when the buffer is too small or the volume is unknown, the compile gates and big_compile_commit_free still on ullAvailPageFile, and the immediate-job query.
performance: 60 s smoke of a retail title, main 7d86c5d vs this merge (2b5a13ad): 1663 -> 1666 frames shown (100 %; last presents per 2 s: 60 60 61), peak commit 17153 -> 18768 MB, 0 device removals, 0 crashes. Peak commit is about 1.6 GB above main here (109 %), consistent with a larger coherent window on this 32 GB machine.
verdict: safe to merge (a run on a PC under 24 GB of RAM, or a Not tested line, would cover the case that changes most; the log label should say the number includes page-file growth)
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5

AI-written and posted by Foniass without a human check of each point.

@github-actions github-actions Bot added needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU labels Dec 1, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head ae8050f

No open or merged PR makes the same change: #632 also touches the NEEDS_FOR_COHERENT_HEAPS check in uma.rs, but to give a title a whole coherent window in its first run, not to count page-file growth. The compile gates (wait_for_memory, big_compile_commit_free) still admit against commit free now, and the SystemPageFileInformationEx struct layout matches the kernel's (the padding before PageFileName.Buffer is implicit in repr(C)).
Minor: page_files reads into a fixed 4 KiB buffer and treats any non-zero status (including STATUS_INFO_LENGTH_MISMATCH) as no page files, so growth falls back to 0. That is the safe side.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

@Chrysana

Chrysana commented Dec 1, 2026

Copy link
Copy Markdown
Author

Thanks to both of you. The next head, 9f4160ce, is ready locally and changes only a test and a log line:

  • The gate test now uses thehollowedone's form, with no second thread and no sleep: the fake query reads 2 GiB, then 7 GiB, the growth closure panics, and the test checks for exactly 2 reads. I ran it. With wait_admitted switched to capacity(), it fails on the growth closure's panic, which is the regression it's there to catch.
  • The uma.rs label (Foniass, point 2) now says what the number is: UMA: N MB of commit free, counting the page files' room to grow unless a job caps commit, under 17408 MB: ….
  • PCs under 24 GB of RAM (point 1): I don't have one, so it goes under Not tested. Below 24 GB, auto_coherent_cap caps the window at RAM/8 (1 GiB at least), so on a 16 GB PC this PR can move the window from 512 MB to 2 GB at most, never to 4,095 MB. 2 GB is the size that cap's comment measured on a 16 GB machine.
  • Memory: a whole coherent window in a title's first run (#284) #632 (point 4): it already conflicts with main. It reads the same 17,408 MB check, so if this lands first, its free_commit() becomes dxc::commit_capacity(). If Memory: a whole coherent window in a title's first run (#284) #632 lands first, I'll rebase this onto it.

Why I haven't pushed it yet: the regression run needs a clean title run of the head, and on AMD current main can't give one in either setting:

So I'll push 9f4160ce, rebased, with its smoke blocks once #3455 is on main.

As a check in the meantime, RX 9070 XT, default XCL_DIRECT_DXIL, with #3455 merged on both sides:

Suite on main b2b1f109 merged with 9f4160ce: 2899 passed, 9 failed, 51 ignored. On main b2b1f109 alone: 2894 / 9 / 51, with the same 8 tests failing on this card, so none of the failures come from this PR.

AI use: Claude Code (Claude Opus 5.5) made the change, ran the tests and the title runs, and drafted this reply.

@gut0to gut0to left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI-assisted review: I traced the page-file enumeration, per-path free-space query, and capacity calculation. I used AI assistance and checked the current implementation; I did not run a Windows configuration test.

/// What the page files can still grow by: each up to its maximum, and no further than its
/// volume's free space (nothing when that is not known).
fn growth_of(files: &[PageFile]) -> u64 {
files.iter().map(|f| f.max.saturating_sub(f.size).min(f.volume_free.unwrap_or(0))).fold(0, u64::saturating_add)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could volume free space be counted once per distinct volume? page_files() attaches GetDiskFreeSpaceExW free bytes to each page-file entry, and growth_of() caps every entry independently. If two reported page files resolve to the same volume, both can claim the same free bytes, so commit_capacity() may overestimate how much commit can be added and admit a heap plan that later cannot grow. Please aggregate the growth limits by volume and add a test with two page files sharing one volume.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, done locally. The page files' growth is now added up per volume, and each volume's total is capped once by its free space. Each page file still stops at its own maximum.

The volume is now found by its name (GetVolumePathNameW, then GetVolumeNameForVolumeMountPointW, giving \\?\Volume{…}\), not by the path's drive letter. Two paths on one volume share one budget that way, and a page file on a volume mounted in a folder (C:\mnt\x\pagefile.sys) is counted against that volume, not against C:. Before, that case also read C:'s free space.

New test page_files_on_one_volume_share_its_free_space: two page files on one volume with 10 GB free, each able to grow by 14 GB, and one on another volume with 4 GB of room. The result is 14 GB. With the old per-file cap it reads 24 GB, so the test fails; I checked that.

On this PC the three page files resolve to three different volume names, each with its free space, so nothing measured so far changes. System Properties sets one page file per drive, so two on one volume would take a hand-edited registry setting; I didn't set one up. The sum is right either way.

This goes into the same push as the changes in my last comment, once #3455 is on main.

AI use: Claude Code (Claude Opus 5.5) made the change, wrote and ran the test, and drafted this reply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:memory Virtual/physical memory, arenas, VRAM budget, UMA area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 gpu:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test) needs:amd-test Needs a test report or merge-check on an AMD GPU needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants