perf(residency): incremental background working-set trim with hysteresis and sustained-pressure gating #6
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/MahanYTT--VIctory-MA!6
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-6"
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?
@MahanYTT on GitHub · 2026-12-04 17:40 UTC · original
MahanYTT:perf/memory-trim-freeze→mega-upgrade-v3· +539 −131 · 1 files · 1 commits · merged 2026-12-04 20:18 UTCRoot Cause Analysis
Analysis of the 170-second gameplay log (
RTX 5070 Ti 16 GB,32,403 MBRAM,49 GBpagefile) andcrates/victory-gpu/src/residency.rs(mod trim) identified three compounding causes behind the 699–1,282 ms working-set trim stalls and cascading working-set re-faulting:K32EmptyWorkingSetkernel lock contention & full working-set wipe:K32EmptyWorkingSet(GetCurrentProcess())sweeps the entire process working set (7.7–13.0 GB, up to ~3.3M pages) in a single syscall, holding the Windows kernel working-set lock for 699–1,282 ms (L26033: 1,282 ms,13,028 -> 2,019 MB;L31901: 1,120 ms,10,440 -> 1,465 MB;L36541: 699 ms,7,748 -> 1,421 MB), stalling active render/title threads (L26047:p95/longest 258.1 ms) and evicting the active working set down to ~1.4 GB so the next frames immediately soft/hard-fault it back in.L36541, evicting 6,327 MB of working set only freed 509 MB of physical RAM (3,205 -> 3,714 MB).autosize threshold (40%of RAM):set_line("auto")was(total / 5 * 2).clamp(6 GiB, 20 GiB)= 12,961 MB on 32 GB RAM, triggeringL26033at13,028 MBeven with ~5.8 GB free.L31901(3,183 MBfree) andL36541(3,205 MBfree) fired on single-sample dips just 35–57 MB below the3,240 MBline, repeating 55 seconds apart because the 30 s cooldown re-armed after freeing 892 MB (>= 512 MB).Summary of Changes (
crates/victory-gpu/src/residency.rs)TrimWorker): Replaced per-trim thread spawning with a single lazily-initialized persistent"victory-trim"thread (OnceLock+Mutex/Condvarmailbox +AtomicBoolin-flight guard) sotrim::lookis strictly non-blocking and coalesces concurrent triggers; short-circuits before callingK32GetProcessMemoryInfowhen trimming is disabled.trim_regions): Replaced monolithicK32EmptyWorkingSetwith a 2-phase incrementalVirtualUnlockpass in32 MiBchunks with2 msyields between chunks — clean file-mappedMEM_MAPPEDregions (>= 1 MiB) first, then largeMEM_PRIVATEregions (>= 4 MiB), stopping early viatrim_goal_metonce eithertarget_working_set(75% of size line or 50% of WS floored at4 GiB/min_ws) orrecovery_free_target(line + 512 MiB) is reached. RetainedK32EmptyWorkingSetstrictly as a last-resort fallback during genuine emergency OOM (physical < line / 3) when incremental trimming cannot recoverline / 2.TrimGate):autosize line from 40% ([6, 20]GiB) to 50% ([8, 24]GiB) (16 GiB on 32 GB RAM).linefor non-emergency low-memory trims (emergency< line / 3still fires immediately).linecannot thrash unless free RAM genuinely recovers aboveline + 512 MiBor drops> 512 MiBdeeper.Verification
mod trimand all trim unit tests withclippy-driver --edition 2024 -D warnings(unsafe_op_in_unsafe_fn,unused_must_use,clippy::all,clippy::undocumented_unsafe_blocks): 0 warnings.crates/victory-gpu/src/residency.rs:memory_is_short_below_a_tenth_of_the_pc_within_three_and_eight_gib(updated for 50%[8, 24]GiBautoline & 90s/180s cooldowns)trim_gate_requires_sustained_shortage_and_hysteresis_before_retriggeringtrim_gate_emergency_bypasses_streak_and_uses_short_cooldowntrim_targets_preserve_active_working_set_and_stop_on_recoverytrim_gate_enforces_size_cooldown_min_ws_hysteresis_and_deep_shortage_override0.00s). Windows CI will run the full workspace build/test suite.