RAM throttle: keep the title's heartbeat during its own waits (opt-in, stacked on #96) #126
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!126
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-126"
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 03:09 UTC · original
nidscode:perf/ram-keep-alive→main· +616 −1 · 8 files · 3 commits · openWhat
VICTORY_RAM_KEEP_ALIVE=1, off by default and split out of #96 as you asked: while the RAM throttle from #96 holds a buffer or a submission back, it sets the title's heartbeat flag the way the title's own tick function does. Stacked on #96: the first two commits are #96's, and only the last one (RAM throttle: keep the title's heartbeat during its own waits) is new here.Why
The throttle holds the title's submissions back (
VICTORY_RAM_FRAME_WAIT_MS), and the main loop waits for them, so a world load it slows can go more than 30 s without a frame. The title's watchdog then ends it with a write to address 0 at +0x23cf683. On the 16 GB laptop that happened to 2 of 2-Machine laptoploads (first-chance exception 0xc0000005 at …+0x23cf683 (write 0x0), with 588–679 MB of RAM free).How it's bounded and checked
Only during the throttle's own waits. The two 10 ms wait loops in
ram_gateandram_gate_submissioneach set the flag once per step. Each wait is bounded byVICTORY_RAM_WAIT_MSorVICTORY_RAM_FRAME_WAIT_MS, so a hang anywhere else still meets the watchdog.Build-checked, without borrowing the image.
victory_loader::heartbeat::asked:VirtualQuery; no guard page, noPAGE_NOACCESS);read_volatileand compares them with 1.0.2.1'sC6 05 99 18 FA 04 01 C3(mov byte [rip+disp32], 1; ret);Another build, or memory that doesn't allow it, leaves the watchdog alone and logs why.
No safe API takes an address.
victory_gpu::ram_keep_alive_atisunsafe fn(flag: *const AtomicU8), with the contract that the byte stays valid for writes for the rest of the process.run.rscalls it only with whataskedreturns. The title image is the prepared DLL, which is never unloaded.Concurrent access. The throttle's threads store to the flag through an
AtomicU8, so they never race each other. The title's own stores and its watchdog's read-and-clear are single-byte operations, which x86 doesn't tear. Whichever store lands last, the flag reads "ticked", or the watchdog clears it as on the console.Tests
heartbeat::tests::the_heartbeat_flag_is_found_only_behind_the_known_tick_functionheartbeat::tests::a_region_is_checked_for_commit_access_and_bounds: committed read-write, read-only, a range across two regions, reserved but uncommitted, and an end past the address space.watch::tests::what_the_kernel_writes_through_is_not_guarded_for_another_viewfail, which looks timing-sensitive and is in code this doesn't touch.Measurements
Laptop: i7-13700H, RTX 3050 6 GB, 16 GB,
-Machine laptop(#100), Series S, 240 s runs under a guard that stops the game below 400 MB of free RAM.VICTORY_RAM_KEEP_ALIVE=1(the first version,fc74f10)VICTORY_RAM_KEEP_ALIVE=1, this version (5fca9d5, onmain+ #96 + #100)🤖 Generated with Claude Code
@TaynanGT on GitHub · 2026-11-27 03:14 UTC · original
Thanks for splitting this out, @nidscode. Both heartbeat loader tests passed on
5fca9d5. The signature and page checks cover the address lookup. There's still a timing case to cover before we can rely on the watchdog: one buffer waiter can finish as another starts, and each can set the flag while the title's render path has stopped making progress. A limit per wait still allows an extension across successive waits.Could you cap the extension across waiters and renew it only when the submission the title is waiting for makes real progress? A test with staggered waiters and no progress should show that the heartbeat writes stop. This also needs the duration checks from #96.
One build fix: restore
#[cfg(windows)]on the existinginplacere-export invictory-gpuand add it to the newram_keep_alive_atre-export invictory-hle. Both source symbols are Windows-only.@TaynanGT on GitHub · 2026-11-27 04:01 UTC · original
Thanks for reporting the load results, @nidscode. I approved CI for
5fca9d5. Clippy caught the constant-onlyassert!inheartbeat.rs:146under-D warnings; the invariant can be checked at compile time. The open behavior check is still the staggered waiters: the heartbeat should stop when there’s no submission progress, even if another waiter starts. CI run@TaynanGT on GitHub · 2026-11-27 04:18 UTC · original
I verified the Windows-only re-exports and compile-time range check in a local follow-up, @nidscode. Both heartbeat tests and Clippy passed. For the runtime side, the current frame counter measures frame waits, so a useful next version needs a shared deadline tied to progress on the submission the title is waiting for. The staggered-waiter test remains the check for that behavior.
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.