Repository navigation
kernelx: physical page homes in window 0 first, from the top, keeping 64 MB free (#2867) - #2905
grahamster2 wants to merge 4 commits into
Conversation
Build 16 (3292b09) took homes from windows 1+ first-fit, beside the title's own reservations, which `sparse_reserve` also places first-fit from window 1 up. A home that no longer fits the rest of window 1 goes to the start of window 2 (homes never straddle a window), and a reservation of nearly a window then has room on neither side. the retail title's page pool for CopyPageMappingsBatchX (63632 pages of 64 KiB, 3977 MB) was at 0x11f9d00000 in Build 15 (window 1 + 3997 MB, across into window 2; homes then went to window 0), and plain write-watched memory at 0xa4a690000 in Build 16 (sparse use 7630 MB instead of 11607 MB); about 45 s into the world its threads faulted on garbage pointers. Homes now come from the top of the last sparse window down (still within one window, still window 0 only when windows 1+ have no room), so the title's reservations from window 1 up keep one free run between. Above a window nothing changes. A large GPU-visible reservation (256 MB or more, no more than the sparse windows hold for the title) that goes to plain write-watched memory is now warned of once, with the free space of each sparse window.
… 256 MB Run 49 (Build 16 + 0637612) warned that the retail title's page pool (63632 pages of 64 KiB, 3977 MB) found no room in the sparse windows: window 0 874 MB free, window 1 99 MB, window 2 3394 MB at most in one run. The pool needs the rest of window 1 and 3878 MB of window 2 from its start, and ~600 MB of homes sat at the top of window 2. In Build 15 the homes went first-fit into window 0 and the pool was at 0x11f9d00000, across windows 1 and 2. 3292b09 moved homes out of window 0 for the title's 32-bit memory there: a Series S run's 38 MB view heap (1245184 slots) found no room in window 0 after 2.9 GB of sparse GPU heaps and 664 MB of first-fit homes, went to window 1, which descriptor tables cannot reach, and the title stopped on its own check. It names no headroom figure. Homes now come from the top of window 0 down while it keeps a free run of XCL_HOME_W0_KEEP_MB (default 256 MB) after them (`Uma::sparse_alloc_home`), otherwise from the top of windows 1+ down as in 0637612. From the top, so the title's first-fit allocations at the low end of window 0 keep one run. With the retail title's figures window 0 has 1144 MB after its GPU heaps and takes all the homes; in the Series S case the 664 MB home would leave 28 MB and goes above. Tests: run 49's figures place the pool across windows 1 and 2 with the homes in window 0, and window 0 keeps its margin while homes spill to window 2.
256 MB left the title's 3977 MB page pool 66 MB short of one free run in the sparse windows (window 0 kept 357 MB, largest run 3911 MB), so it fell to plain memory and the title faulted about 45 s into the world. With 64 MB the pool lands in window 1 (0x1101400000) and a 15-minute world run had no fault. 64 MB still covers the 38 MB view heap 3292b09 protects on the Series S profile. XCL_HOME_W0_KEEP_MB still overrides it.
…N per size Review fixes for the homes placement: - The last resort of `Uma::sparse_alloc_above` (windows 1+ full) took window 0 first-fit from the bottom, where the title's 32-bit memory goes. It now takes window 0 from its top down too. - The large plain-fallback WARN fired once per process, so an earlier fallback that is by design hid a later one. It now fires once for each of the first 4 distinct sizes. - An `XCL_HOME_W0_KEEP_MB` that does not parse is warned of instead of silently using the default, and the tests use the default margin whatever the shell sets. - A test of `take_sparse_top_in` with a free range across `lo_bound`. - The WARN on the 64 KiB-page fallback only for reservations that tried the sparse windows, not committed GPU heaps that never did. - Comments name no title.
|
Tested Setup: retail title of #505, Series S profile, RTX 5070 Ti 16 GB (driver 617.42), Ryzen 7 9800X3D, 32 GB RAM, Windows 11 Pro 26300, release, shaders precompiled, 300 s limit per run. Tree:
So on a 3-window layout without Not tested: the PR on its exact base AI use: Claude Code with Claude Fable 5.2 ran the builds and runs, read the logs and wrote this; I checked it. |
|
Found a fragmented-window case on head I reproduced this with only XCL's synthetic UMA reservations: window 0 has a lower 32 MB hole and an upper 80 MB hole; window 1 is occupied, and window 2 has 4000 MB free. A 32 MB home placed in the lower hole leaves the upper 80 MB intact, so a subsequent 3977 MB pool fits in window 2. On the unmodified PR head, the home instead goes into window 2 and the pool has only 3968 MB there. The new regression fails on that head (0 passed, 1 failed, 0 ignored, 0 skipped). A local change that retries lower free runs after a margin rejection makes it pass. The relevant physical-home tests then pass 8/8, and Commands: Candidate fix and regression testdiff --git a/crates/xcl/src/gpu/uma.rs b/crates/xcl/src/gpu/uma.rs
--- a/crates/xcl/src/gpu/uma.rs
+++ b/crates/xcl/src/gpu/uma.rs
@@
- if let Some(at) = take_sparse_top_in(&mut g, lo, hi, size, align) {
+ let mut search_hi = hi;
+ while let Some(at) = take_sparse_top_in(&mut g, lo, search_hi, size, align) {
if free_runs_in(&g, lo, hi).1 >= w0_keep {
return Some((at, size));
}
give_back(&mut g, at);
+ // Moving within this free run cannot leave a larger remainder; try the
+ // next lower run before giving up on window 0.
+ search_hi = *g.0.range(..=at).next_back().unwrap().0;
}
@@
fn take_sparse_top_in_a_free_range_across_lo_bound() {
@@
}
+ #[test]
+ fn physical_home_uses_lower_hole_when_it_preserves_window_0_margin() {
+ let u = Uma::for_runtime(16 << 20).unwrap();
+ let (free0, _) = u.sparse_free_in(0);
+ let low = u.sparse_alloc(32 << 20, GRAIN).unwrap().0;
+ let middle = u.sparse_alloc(free0 - (112 << 20), GRAIN).unwrap().0;
+ assert_eq!(u.sparse_release(low), Some(32 << 20));
+ assert_eq!(u.sparse_free_in(0), (112 << 20, 80 << 20));
+
+ let w1 = u.sparse_reserve(WINDOW).unwrap();
+ let w2_start = u.sparse_reserve(WINDOW - (4000 << 20)).unwrap();
+ assert_eq!(u.window_of(w2_start), Some(2));
+
+ let home = u.sparse_alloc_home(32 << 20, GRAIN, 64 << 20).unwrap().0;
+ assert_eq!(home, low, "lower hole leaves the 80 MB run intact");
+ assert_eq!(u.sparse_free_in(0).1, 80 << 20);
+ let pool = u.sparse_reserve(3977 << 20).expect("page pool still fits window 2");
+ assert_eq!(u.window_of(pool), Some(2));
+
+ for p in [home, middle, w1, w2_start, pool] {
+ assert!(u.sparse_release(p).is_some());
+ }
+ assert_eq!(u.sparse_used(), 0);
+ }AI use: Codex (GPT-6.2 Sol) investigated, wrote and ran the regression, tested the candidate change, and drafted this report; Codex (GPT-6.2 Astra) assisted with the initial static review. |
…SKIP, probe past xcl-dev#2891)
|
Correction to my comment above: the "3 of 4 runs reached 300 s with I went back through the logs of those runs. The three reverted runs that reached 300 s were the ones where the driver's shader cache was cold for that build:
So the survivors spent 130 to 190 of their 300 s blocked on compute PSO compiles, with no submits and no streaming, and did far less work than the runs that crashed. The one reverted run without that blocking crashed like the others. The PR runs came later, when the cache was warm. Since then I ran 13 more reverted runs with a warm cache (same profile, same cap, four base commits from The part about the PR itself stands: the pool goes back into the sparse windows and the warning is not logged. AI use: Claude Code with Claude Fable 5.2 read the logs and wrote this; I checked it. |
|
Independent paired verification on an 8 GB RTX 3060 Ti ( Setup
Results (250 s paired runs)
Not tested: |
|
Test of Setup: RTX 3070 8 GB, driver 621.40, 64 GB RAM, Windows 11 26300, release build. Tree:
Not tested: more than one run per row; this PR on AI use: Claude Code (Claude Fable 5.2) ran the runs, read the logs and wrote this under my direction; I reviewed it. |
Fixes #2867.
On the Series S profile with GPU heaps in the sparse windows, Build 16 crashes about 45 s into the world. Build 15 does not. The cause is 3292b09, which moved physical page homes out of window 0 and into windows 1+ (first fit). The retail title then reserves a pool of 63632 pages of 64 KiB (3977 MB). That pool needs nearly all of windows 1 and 2, and it no longer fits:
0x11f9d00000, in the sparse windows. Build 16 put it in plain write-watched memory (0xa4a690000,0x94b290000,0x98cd70000in three runs).New placement of physical page homes (
Uma::sparse_alloc_home,kernelx::alloc_physical_home)sparse_reserve, first fit from window 1 up) keep one free run between them and the homes.3292b09 was protecting a 38 MB view heap that had to fit in window 0 after the homes. The 64 MB margin covers that case, and the tests check that a 38 MB view heap still fits in window 0 after the homes. The figure is empirical: 256 MB left this title's pool 66 MB short, and 64 MB fits it. It was fitted to one title, so
XCL_HOME_W0_KEEP_MBoverrides it. A value that does not parse logs a warning and uses the default.What is in it
kernelx: physical page homes come from the top of windows 1+ down(gpu/uma.rs,hle/kernelx.rs):take_sparse_top_in(top-down, never straddles a 4 GiB boundary) and a WARN when a GPU-visible reservation of 256 MB or more, small enough to fit the sparse windows, goes to plain memory. The WARN gives the free bytes and the largest run of each window, so this failure shows in a log.kernelx: physical page homes go to the top of window 0 while it keeps 256 MB(gpu/uma.rs,hle/kernelx.rs):Uma::sparse_alloc_home, window 0 first, with a margin.kernelx: physical page homes keep 64 MB of window 0 free, not 256(hle/kernelx.rs): sets the default margin and addsXCL_HOME_W0_KEEP_MB. Its test rebuilds the failing layout: 256 MB gives the 99 / 3911 MB split above and no room for the pool, and 64 MB puts the pool at window 1 + 20 MB.gpu/uma.rs,hle/kernelx.rs): the last-resort fallback takes window 0 from its top, not first fit from the bottom. The WARN fires for the first 4 distinct sizes instead of once per process, so an earlier fallback that is by design no longer hides a later one. On the 64 KiB-page fallback path it fires only for reservations that tried the sparse windows, not for committed GPU heaps that never did. The tests use the default margin whateverXCL_HOME_W0_KEEP_MBthe shell has. There is a new test for a free range that crosseslo_boundin the top-down search. Code comments and commit messages name no title.Tested
cargo build --release -p xcl: OK.cargo test -p xcl --lib hle::kernelx: 67 passed, 0 failed, 1 ignored (also all passing together withgpu::umawithXCL_HOME_W0_KEEP_MB=300set in the shell)cargo test -p xcl --lib gpu::uma: 20 passed, 0 failed, 0 ignoredXCL_UMA_WINDOWS=16,XCL_HEAP_WINDOWS=1,XCL_COHERENT_MB=1024, on the first three commits: the pool is at0x1101400000(window 1 + 20 MB, in the sparse windows). A 15-minute world run had no fault (2.1M draws, 0 skipped).Regression run
Not run yet. There are no
xcl-smokeblocks for this head, and I will add them.main:
PR:
Not tested
cargo test --workspacesuite. Only thehle::kernelxandgpu::umaunit tests ran.Interaction with #2886
The two are complementary: #2886 keeps single-window
sparse_reservereservations inside one window. #2886 alone does not fit this case, though. Window 2 had 3911 MB free and the pool needs 3977 MB, so the pool has to cross windows 1 and 2, and that only works if the homes leave that run free. Both PRs change the same tests ingpu/uma.rs, so they will conflict. I'll rebase onto whichever lands first.AI use