mirror of
https://github.com/valentderah/totk-pc-recomp.git
synced 2026-11-20 12:45:57 +00:00
Wait out a short out-of-memory spell instead of ending the game
Crash logs ended in fatal errors when the system's commit ran out for a moment: a staging buffer (-2), a guest commit with the system at 24442 of 24447 MB, image creation (-2). Windows grows a system-managed page file and some drivers charge device memory to the process commit, so the same request often succeeds a moment later. oom.c holds the wait nvn_api_cmd.c realloc_wait already used: it requests a release, retries every 10 ms for up to 30 s, logs the first 8 with the commit numbers. rt_oom_request sets a flag that vk_texture_new_submit takes (one atomic load per submit): it drops up to 256 released textures of the two kinds sweep_pressure drops (overwritten, clean mirrored), never GPU-written content, and frees the headroom blocks. vk_oom_release does at once what needs no submit: headroom blocks, finished upload batches and deferred objects. - memory.c commit: waits and retries without frz_lock between tries; every caller waits, boot ones too. - vk_staging and the draw-data chunks (vk_exec_draw.c scratch): release, then wait; the open upload batch is not submitted, its caller still records into it. - create_tex: release and one retry; no wait under the texture lock, the texture is asked for again at its next use. - the texture write-back buffer: release, then wait. - the headroom thread keeps no spare block for 30 s after a failure. TOTK_TEST_OOM=<site>:<n> (commit, staging, image, chunk) fails the first n attempts; probe-kernel forces 3 refused commits, probe-vkexec 2 staging buffers, 1 image and 1 chunk, and both pass through them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5e479f593b
commit
213bc6af6a
13 files changed
+323
-32
No files matched your search
+21
-4
@@ -175,12 +175,29 @@ static int thaw_fault(uint64_t a) {
|
||||
}
|
||||
|
||||
// Mapping changes thaw the regions they touch and run under frz_lock, so no freeze sees them half done.
|
||||
static void commit(uint64_t a, uint64_t n, const char *what) {
|
||||
typedef struct { uint64_t a, n; } CommitTry;
|
||||
static int commit_try(void *arg) {
|
||||
const CommitTry *t = arg;
|
||||
if (rt_oom_forced(RT_OOM_COMMIT)) return 0;
|
||||
plat_mutex_lock(&frz_lock);
|
||||
thaw_range_locked(a, n, 3);
|
||||
int ok = !n || plat_mem_commit(a, n);
|
||||
thaw_range_locked(t->a, t->n, 3);
|
||||
int ok = !t->n || plat_mem_commit(t->a, t->n);
|
||||
plat_mutex_unlock(&frz_lock);
|
||||
if (!ok) rt_fatal("memory: commit %s %#llx+%#llx failed", what, (unsigned long long)a, (unsigned long long)n);
|
||||
return ok;
|
||||
}
|
||||
|
||||
// A refused commit waits for memory (rt_oom_wait): the system's commit ran out for a moment (a page file growing, the
|
||||
// driver's device memory charged to this process), and the Vulkan back end gives memory back at its next submit. The
|
||||
// wait holds the caller's lock (lock or klock: only memory SVCs and kernel-region allocations wait behind it) but not
|
||||
// frz_lock, which write faults on frozen regions need. Every caller waits, the boot's ones too: there a refusal has the
|
||||
// same cause, and the wait only delays an end the game would reach anyway.
|
||||
static void commit(uint64_t a, uint64_t n, const char *what) {
|
||||
CommitTry t = {a, n};
|
||||
if (commit_try(&t)) return;
|
||||
char w[64];
|
||||
snprintf(w, sizeof w, "memory: commit of %s at %#llx", what, (unsigned long long)a);
|
||||
if (!rt_oom_wait(w, n, commit_try, &t))
|
||||
rt_fatal("memory: commit %s %#llx+%#llx failed", what, (unsigned long long)a, (unsigned long long)n);
|
||||
}
|
||||
|
||||
static void decommit(uint64_t a, uint64_t n, const char *what) {
|
||||
|
||||
Reference in new issue
Block a user