xmem: coalesce low-4 GiB guards on retry when no single guard fits #3131
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3133"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T09:33:55Z.
Problem
low_guards::retryincrates/victory-hle/src/modules/xmem.rsreleases one guard at a time, invokesallocate(), and immediately re-guards that range on failure before trying the next guard.When a 32-bit
XMemVirtualAllocrequest needs a contiguous span that crosses two or more guards, every single-guard attempt fails and returnsERROR_NOT_ENOUGH_MEMORYeven though the combined address range is unused:MEM_FREE, yet neither guard alone exposes the combined contiguous span.PAGES_2M) straddling a guard boundary: a 2 MiB-alignedVirtualAlloc2window whose start falls in one guard and whose end falls in the next cannot succeed while either guard stays reserved.Fix
MEM_FREEspace (VirtualQueryacross each gap). Single-guard clusters (and guards separated by an active host/title allocation) are skipped.allocate().MEM_FREEportions inside our released guard intervals, merging strictly adjacent released intervals without claiming unguarded free gaps between non-adjacent guards, and preserveGetLastErroracross queries and re-guarding.Verification
Added four targeted regression tests in
modules::xmem::low_guards::tests(confirmed failing onmain63bcca43before the fix and passing after):retry_coalesces_guards_separated_by_a_free_gap(also verifies a refused retry leaves the unguardedMEM_FREEgap free and both guards restored)retry_coalesces_adjacent_guards_and_restores_on_refusal(also verifiesGetLastErrorpreservation)retry_coalesces_guards_straddling_two_mib_alignment(usingVirtualAlloc2withAlignment = 2 * MIB)retry_does_not_coalesce_guards_separated_by_an_allocationFull validation passed:
cargo test -p victory-hle --lockedandVICTORY_D3D12_WARP=1 cargo test -p victory-hle --locked --features diagnostics(156 unit + 2 integration tests passed)cargo clippy --workspace --all-targets --locked -- -D warningsand--all-features(0 warnings)rustfmt --edition 2024 --check(0 diffs on all modified/added lines)cargo test -p xtask --locked policy::tests::repository_passes_policy(asset policy: 191 files ok)Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-26T10:23:09Z.
Independent local verification of head
c283299on Windows 11, Rust 1.100.0/MSVC:cargo test --locked -p victory-hle --lib modules::xmem::low_guards::tests— 6 passed, 0 failed (including all four newretry_coalesces_*tests).git diff --check origin/main HEAD— clean.One deprecation warning appears during compilation, but it is pre-existing in
victory-gpu/src/object.rs(Atomic::fetch_update), unrelated to this diff. SyntheticVirtualAlloc2/VirtualQueryfixtures only; no game assets or DRM material used. AI-assisted (Hy4 flash).Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T13:30:21Z.
Review: APPROVED
Verified against
origin/main(63bcca4):cargo test -p victory-hle --lib modules::xmem:: -- --test-threads=1: 18/18 passed (includingretry_coalesces_adjacent_guards_and_restores_on_refusal,retry_coalesces_guards_separated_by_a_free_gap,retry_coalesces_guards_straddling_two_mib_alignment, andretry_does_not_coalesce_guards_separated_by_an_allocation).cargo clippy -p victory-hle --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Cleanly coalesces low-4 GiB guards on retry when no single guard fits while preserving intervening allocations.
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-27T11:53:10Z.
NVIDIA full-suite run, to go with the reports above by Dukestar69, cloph-dsp, since none of them names a GPU run. Tested exact head
c283299(on its base63bcca4).Tested
dxil.dllfrom Windows SDK 10.0.26100 (the loader's default), debug.cargo build --workspace --locked, thencargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 870 passed, 0 failed, 10 ignored.retry_coalesces_guards_separated_by_a_free_gap,retry_coalesces_adjacent_guards_and_restores_on_refusal,retry_coalesces_guards_straddling_two_mib_alignment,retry_does_not_coalesce_guards_separated_by_an_allocation.--skipleaves out tests that fail on main63bcca4on this card too, not because of this PR:heap_direct_texture_reads_mark_their_heap_indexends thevictory-shadertest process with0xc0000005(#2571), so without the skip the rest of that crate never reports;dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_viewsand the twostride_testshit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317);gathers_at_a_level_match_the_hardwarefails on lane 0 (#1744).Not tested
AI use
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.