Add an opt-in RAM throttle for low-RAM PCs #96
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!96
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-96"
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?
@nidscode on GitHub · 2026-11-27 00:37 UTC · original
nidscode:perf/ram-throttle→main· +385 −1 · 3 files · 2 commits · openWhat
An opt-in RAM throttle for PCs whose physical RAM runs out before the card's memory does (16 GB and a 6 GB card here). Everything is off by default; with none of the new variables set, nothing changes.
VICTORY_RAM_FLOOR_MBupload_buffer,shared_buffer: upload heaps and memory shared with the card, both held in RAM while alive) waits while less than the floor would be left free. Waits run in 10 ms steps. It only slows the making; it never refuses a buffer.VICTORY_RAM_WAIT_MSVICTORY_RAM_WAIT_SHARE_MSVICTORY_RAM_FRAME_WAIT_MSVICTORY_WINDOWS_BAR_PERCENTVICTORY_WINDOWS_BAR_MB), 50–95. A byte of a window there is a byte of RAM not locked for the card.Free RAM is read with
available_physical_ram()and cached for 20 ms, since the buffer gate is asked thousands of times a second while the world streams in. The memory line reports what the throttle did: buffers that waited and for how long, waits cut short, buffers made at once, the least free RAM seen, submissions held back, and the windows on the card. While it holds things back it also reports every 5 s, because a world load can go many seconds without a frame report.Why
On a 16 GB laptop, physical RAM runs out while the world streams in, not during play. Within about 20 s, the memory shared with the card goes from under 1 GB to 4–5 GB, faster than Windows writes other processes' pages to the page file, and free RAM drops to a few MB. After the load, free RAM holds at 0.5–1.2 GB. Each buffer that waits gives the system time to write those pages out. Holding the title's submissions back slows its own streaming the same way. This is the same family as the memory exhaustion in #36, but that report is about later in a session on 32 GB, and this PR doesn't claim to fix it.
Measurements
Machine: i7-13700H, RTX 3050 6 GB Laptop (budget 5,233 MB, Resizable BAR), 16 GB RAM, NVMe, Windows 11. Vice-Tay
cc9ed86, diag build, Series S, windowed, shaders translated ahead.Each run is 240 s, under an external guard that stops the game below 400 MB of free RAM (so the laptop never hard-pages) and caps its working set at 4.5 GB. Scripted Enter presses reach the story load in 60–100 s. "World" counts frame reports with 300 or more draws.
All runs below use this base set:
VICTORY_DSTORAGE_IO=direct VICTORY_INPLACE=2 VICTORY_WINDOW_KB=64 VICTORY_WINDOW_TAILS=1 VICTORY_WINDOWS_BAR_MB=3072 VICTORY_CARD_BUFFERS_MB=256 VICTORY_LEVELS_ON_DEMAND=1 VICTORY_UPSCALER=6 VICTORY_RENDER_SCALE=0.5 VICTORY_OUTPUT=1920x1080 VICTORY_POKE=71B6330:1. The poke pauses the heartbeat watchdog for the slower throttled load. With the plain auto (4090) preset, the guard stopped the run at the world load with 3 MB free."On" means
VICTORY_RAM_FLOOR_MB=1500 VICTORY_RAM_WAIT_MS=500 VICTORY_RAM_WAIT_SHARE_MS=900 VICTORY_RAM_FRAME_WAIT_MS=1000 VICTORY_WINDOWS_BAR_PERCENT=92.Tests
the_ram_throttle_holds_a_buffer_only_below_its_floorandwindows_on_the_card_go_to_the_percent_asked_for_within_bounds.cargo test --locked --profile diag -p victory-gpu --features diagnostics: 471 passed, 0 failed. One earlier run of the same suite hung in the test binary and passed on rerun; it looks like the timing-sensitive kind of test from #55, but I didn't pin it down.cargo clippy --locked --profile diag -p victory-gpu --features diagnostics: no warnings.cargo check --locked -p victory(no diagnostics) builds.cargo fmt --checkreports nothing new in the changed code (the files already had differences onmain, and their count is unchanged).Not in this PR
shadow.rslet_go_idle), so this throttle buys time but doesn't stop that growth.Update after review (
d5c5d61)fetch_update. Before, a reset could erase another thread's charge. A concurrency test covers the turn of a second, with late callers.🤖 Generated with Claude Code
@TaynanGT on GitHub · 2026-11-27 01:28 UTC · original · requested changes
Thanks for the paired runs on the 16 GB laptop. The load survival and frame-time measurements make the trade-off clear. I started CI on
0addae35. Please fix the shared wait budget before we rely on the throttle in #100.@ -157,0 +283,4 @@// The second's share, for all threads together.let second = now / 1000;if RAM_SHARE[0].swap(second, Ordering::Relaxed) != second {RAM_SHARE[1].store(0, Ordering::Relaxed);@TaynanGT on GitHub · 2026-11-27 01:28 UTC · original
The reset can drop a reservation made by another thread. A can publish the new second, B can charge its 10 ms and start sleeping, and A can then erase that charge with
store(0). Please update the second and its spent time in one operation, and cover a rollover with concurrent callers.@nidscode on GitHub · 2026-11-27 02:03 UTC · original
On
crates/victory-gpu/src/host.rsline 286 (outdated):Fixed in
fc74f10. The second and its spent milliseconds are now oneAtomicU64(the second above bit 20, the milliseconds below), charged withfetch_updateintake_share, so a new second and a charge to it are one operation. A caller that read the clock before another thread moved the word on is charged to the word's own second, so the word never goes back.the_ram_throttle_share_holds_across_a_second_with_concurrent_callersruns 8 threads × 400 tries over two seconds against a 900 ms share. In the second half, half the threads keep asking for the earlier second. Each second gives exactly 90 charges of 10 ms, and the word ends at the later second, full. One more change: a charge the share has no room for is no longer recorded, where the old code added it and then gave up.@TaynanGT on GitHub · 2026-11-27 02:06 UTC · original
On
crates/victory-gpu/src/host.rsline 286 (outdated):Thanks, @nidscode. Packing the time window and charge into one atomic update addresses the race I raised. The rollover test also covers callers that arrive with an older timestamp. I’ve started the fresh CI run for
fc74f10.Could you keep #96 focused on the RAM throttle and move
VICTORY_RAM_KEEP_ALIVEto a separate PR? That change borrows the entire mapped image as a Rust slice, including ranges that could be unreadable, and writes to an address supplied through a safe public API. The heartbeat can also be accessed by the title and multiple host threads. That needs its own checks for readable and writable ranges, pointer lifetime and concurrent access.fc74f101f2tod5c5d61f4d@TaynanGT on GitHub · 2026-11-27 02:59 UTC · original · edited 2026-11-27 03:03 UTC
Thanks, @nidscode. I checked
d5c5d61and confirmed that the heartbeat changes are out. The two throttle tests and the window-budget test passed locally, and Windows CI passed on that head.I found one more input-handling issue before this is ready. The RAM floor still shifts a parsed
u64by 20, which can truncate it, and both waits add an unrestricted duration tobegun. Please check the MiB conversion and validate the wait values before using them in deadline arithmetic. Could you also update the PR description and the submission-wait comment for the current head? The 16 GB runs in #100 show that individually bounded waits can still delay a world load long enough to trip the watchdog.@TaynanGT on GitHub · 2026-11-27 04:18 UTC · original
Thanks for the watchdog-on load counts, @nidscode. Draft #147 carries your throttle with the checked MiB conversion and bounded elapsed-time waits. Four targeted tests and Clippy passed. I’m keeping the guarded 0-of-6 result visible as the baseline for any future hardware retest.
View 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.