gpu: reclaim dead shadow pages, idle staging blocks, and post-PSO DXIL commit #263
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/TaynanGT--Vice-Tay!263
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-263"
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?
@Vladimir-Human on GitHub · 2026-11-27 12:49 UTC · original
Vladimir-Human:perf/ram-trim-reclamation→main· +4014 −281 · 13 files · 1 commits · openAddresses #212 (sustained host RAM and Windows commit growth during long sessions while GPU VRAM remains available).
Adapted for
Vice-Tay's residency, pool, shadow, and pipeline architecture (building on theram_trimreclamation pattern fromfxceless/victory-fork#1286and integrating cleanly withVice-Tay'spool.rs64 MiBSTAGINGblocks,residency.rs,VICTORY_SNAPSHOT_POOL/VICTORY_WINDOW_BUDGET_MB,Shadow::{placed_copy, land_back, merge_under_writes},#238'sEXACT: RwLock+EXACT_TICK, andpipeline/{known,make}.rs).Summary of Changes
OS-backed RAM policy & safe
MEM_DECOMMITfoundation (crates/victory-gpu/src/ram_trim.rs)HostTier/HostRamStatus(GlobalMemoryStatusEx+K32GetProcessMemoryInfo, 250 ms TTL cache) andTrimPolicyscaling by host RAM tier and memory pressure (< 4 GiBlow,< 2 GiBpanic).verify_safe_for_decommit(VirtualQueryrequiringMEM_PRIVATE && MEM_COMMIT+ non-resettingGetWriteWatch(0, ...)probe rejectingMEM_WRITE_WATCH,MEM_MAPPED, andMEM_IMAGEwithout disturbing dirty bits) andsafe_decommit.VmBlock(MEM_RESERVE+ 64 KiBMEM_DECOMMIT/MEM_COMMIT) andSnapshotBuffer(Small(Vec<u8>)< 256 KiB/Large(VmBlock)>= 256 KiB) so idle physical commit returns to the OS while preserving virtual address reservations across reuse.MEM_DECOMMITof live retained snapshots is strictly opt-in behindVICTORY_RAM_TRIM=1(decommit_cold_reference_ms: Noneby default).Dead shadow page reclamation, promoted snapshot release &
ensure_commitsafety (shadow.rs,watch.rs)Shadow::beforeandSnapshotPoolwithSnapshotBufferwhile preservingSnapshotPool's descending capacity ordering,VICTORY_SNAPSHOT_POOL,VICTORY_WINDOW_BUDGET_MB, andRamBandbehavior.Shadow::beforeread/write path withensure_commit()(find_all,writing,copy_back_with,relay_merge,merge_under_writes,placed_copy,land_back).beforesnapshots immediately when a shadow is promoted to GPU card memory (card_make_beforeandcopy_back_done).shadow::title_memory_remapped(at, len)fromwatch::title_memory_changed(remapped/unmapping) andwatch::title_memory_freed(outsideGUARDS) to retire wholly contained single-owner idleLOOSE/EXACTshadows (preservingEXACT_TICKmonotonicity) andMEM_DECOMMIToverlapping dead snapshot pages under strictpending -> before -> keptlock ordering.trim_cold_references_at(VICTORY_RAM_TRIM=1only), pruning deadCARDEDentries and guarding against active flights (pending.is_empty() && !snap_pending).Idle staging, command list, host cache & DXIL/container trimming (
pool.rs,host.rs,list.rs,texture.rs,pipeline.rs,pipeline/{host,known,make}.rs,copystat.rs)emptied_mson 64 MiBSTAGINGupload blocks (pool::room_with) and reclaims aged empty blocks abovestaging_pool_warm_blocksoutside theSTAGINGlock while preservingTEXTURESVRAM logic.TrimPolicy::cached()throughhost::sweep()(idle-ageSpare::trim,CardWork::fetched_ms+trim_card_work_with,HostList::resetshrink +take_idle_cachesfor oversizedindirect_args/ idlebatch_args, aged idle list eviction inlist::let_go_idle_with, oversizedtexture::READscratch spike shrink, out-of-lock drops).DxilPin, transparently reloading on demand viashader_cache::host_shader), zlib-compresses cold shader container copies (ContainerBlobvia existingzlib-rs), cachesfull_hashandbuilder_spilled, and logsram_trim::diagnostics_line()incopystat::log.Verification (
rustc 1.98.1,VICTORY_D3D12_DEBUG=1,--test-threads=1)cargo clippy -p victory-gpu --all-targets --locked -- -D warnings(default &--all-features): 0 warningscargo run -p xtask --locked -- policy:asset policy: 314 files ok;cargo test -p xtask --locked: 11/11 passedK32GetProcessMemoryInfo):ram_trim::tests::stress_decommit_recommit_reuse_no_corruption_and_os_commit_drops— 3 consecutive rounds of 256 MiB snapshot decommit/recommit reuse:private commit before=357.8 MiB, after=101.3 MiB, delta=-256.5 MiBevery round, 0 byte corruption, 0 D3D12 debug errors.safety_guard_rejects_write_watch_and_mapped_viewsverifies non-resettingGetWriteWatch(0, ...)preserves dirty pages and rejectsMEM_WRITE_WATCH/MEM_MAPPED;ensure_commit_recommits_across_all_shadow_snapshot_pathsexercisesplaced_copy,find_all,copy_back_with,relay_merge,land_back,writing,merge_under_writes, andcopy_back_doneafterMEM_DECOMMIT.VICTORY_D3D12_DEBUG=1,--features diagnostics):ram_trim: 13/13 passedshadow::: 66/66 passed (4 ignored)pool::tests(+prelude_pool): 10/10 passedlist::tests: 3/3 passedhost::spare: 2/2 passedpipeline::: 38/38 passed (1 ignored)texture::: 8/8 passed (3 ignored)watch::: 52/52 passed (1 ignored)ram_trim13/13 passed,shadow::66/66 passed (4 ignored)VICTORY_D3D12_WARP=1,VICTORY_D3D12_DEBUG=1,--features diagnostics):ram_trim13/13 passed,pool::tests10/10 passed,list::tests3/3 passed@TaynanGT on GitHub · 2026-11-27 12:53 UTC · original
@Vladimir-Human The snapshot commit, staging blocks and retained DXIL have different lifetimes. I’d measure those three paths independently with the same route. For snapshot trimming, the required check is that a live copy still has its bytes when the next refresh or copy-back uses it.
a1d09e3290toe6aaa43a51@Vladimir-Human on GitHub · 2026-11-27 13:25 UTC · original
@TaynanGT Updated
e6aaa43awith independent per-path toggles so each lifetime can be isolated on the same route, plus a dedicated live-copy preservation check:1. Independent Per-Path Switches (
ram_trim.rs::TrimSwitches)Each path defaults to following
VICTORY_RAM_TRIM(on in default-safe /VICTORY_RAM_TRIM=1, off whenVICTORY_RAM_TRIM=0), and explicit0/1on any per-path variable overrides the master switch:VICTORY_RAM_TRIM_SNAPSHOTS— snapshotVmBlockMEM_DECOMMIT/MEM_RESERVEpool,title_memory_remappeddead-snapshot reclamation, card-promotion CPUbeforerelease, and (withVICTORY_RAM_TRIM=1) opt-in cold-reference decommit. When0, restores baselineVec<u8>snapshots andkeep_largest/keep_smallestpool retention.VICTORY_RAM_TRIM_STAGING— aged empty 64 MiBSTAGINGupload block reclamation (pool::room_with), idleSpare/CardWork/command-list cache trimming, and oversizedtexture::READshrink. When0, restores baselinepool::room/host::sweepretention.VICTORY_RAM_TRIM_SHADERS— post-PSO DXIL release (DxilPin, disk-cache reload on demand) and cold container zlib compression (pipeline::trim_shaders_with). When0, both are no-ops.Same-route A/B isolation examples:
VICTORY_RAM_TRIM=0VICTORY_RAM_TRIM=0 VICTORY_RAM_TRIM_SNAPSHOTS=1VICTORY_RAM_TRIM=1 VICTORY_RAM_TRIM_STAGING=0 VICTORY_RAM_TRIM_SHADERS=0VICTORY_RAM_TRIM=0 VICTORY_RAM_TRIM_STAGING=1VICTORY_RAM_TRIM=0 VICTORY_RAM_TRIM_SHADERS=1copystat::lognow prints active path states (snapshots=on/off, staging=on/off, shaders=on/off) alongside the per-path counters.2. Live-Copy Byte Preservation Check
Added
shadow::ram_trim_tests::live_copy_retains_exact_bytes_across_snapshot_trim_refresh_and_copy_back(verified on both D3D12 HW and WARP underVICTORY_D3D12_DEBUG=1):beforesnapshot before 3-waycopy_back_with+relay_merge; (b) after settling and full cold-ref + poolMEM_DECOMMITto0committed bytes, all 4 MiB of the live copy (shadow.data) remain byte-exact; (c) the next write-watchShadow::updatecopies only the dirty 4 KiB OS pages (12,288 B, leaving 99.7% unrefreshed bytes intact from the live copy); and (d) the nextShadow::writing+ fullcopy_back_withproduces byte-exact 3-way merges with zero false diffs.Card::stagingretains exact bytes across CPUbeforesnapshot reclamation into the next selective 4 KiB write-watchShadow::updateandcard_dirty_now().Also added
per_path_switches_isolate_each_lifetime_independently,snapshots_toggle_off_restores_baseline_pool_without_decommit, and disabled-path no-op assertions fortrim_staging=false(list::tests) andtrim_shaders=false(pipeline::ram_trim_tests).Re-verified (
rustc 1.98.1,VICTORY_D3D12_DEBUG=1,--test-threads=1)clippy -p victory-gpu --all-targets --locked -- -D warnings(default &--all-features): 0 warningsxtask policy(314 files ok) &cargo test -p xtask --locked(11/11)--features diagnostics:ram_trim16/16,shadow::68/68 (4 ignored),pool::tests10/10,pipeline::38/38 (1 ignored),list::tests3/3,host::spare2/2,texture::8/8 (3 ignored)ram_trim16/16,shadow::68/68 (4 ignored)VICTORY_D3D12_WARP=1,--features diagnostics):ram_trim16/16,pool::tests10/10,pipeline::38/38 (1 ignored),list::tests3/3@TaynanGT on GitHub · 2026-11-27 13:37 UTC · original
@Vladimir-Human The per-path switches and the live-copy byte check cover the split we needed. For the same-route comparison, record the active path line alongside private bytes and system commit. That will distinguish the snapshot result from staging blocks or retained shaders.
e6aaa43a51toe7a320163aView command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.