From 59069502f34e38a19b03d64f3031efb02c83b260 Mon Sep 17 00:00:00 2001 From: Sebastian Choperena <64750853+schoperena@users.noreply.github.com> Date: Mon, 9 Nov 2026 12:33:10 -0500 Subject: [PATCH] Stop a second copy of the game before the shader prewarm, not after it. The one-game-per-profile lock was taken at the first storage use, after the boot prewarm. A second copy started while the game ran (a second Play, a shortcut) spent 14 to 30 s translating and building on every core and committed about 10.9 GB before it ended with "another copy of the game is running", enough to bring a 48 GB machine to its commit limit and stall the copy being played. rt_boot now takes the lock first; storage_init takes it again, which plat_lock_file answers from the handle it already holds. A restart from the settings menu is unaffected: main waits for the previous process to exit before rt_boot. --- runtime/boot.c | 1 + runtime/fs.h | 2 ++ runtime/fs_host.c | 18 +++++++++++++----- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/runtime/boot.c b/runtime/boot.c index 97d4736a..e3ab9415 100644 --- a/runtime/boot.c +++ b/runtime/boot.c @@ -395,6 +395,7 @@ static void boot_wait(PlatThread *warm, uint64_t cap_ms) { void rt_boot(void) { check_npdm(); + fs_host_lock_profile(); // a second copy of the game stops here, before the prewarm below if (!rt_config()->shot) vk_pipeline_async_enable(); // a --shot image must not depend on build timing // Shaders and pipelines recorded in earlier runs are made ready while the modules load; the guest waits for them. PlatThread *warm = plat_thread_new(prewarm_main, NULL, "prewarm"); diff --git a/runtime/fs.h b/runtime/fs.h index b8846c07..57ba0711 100644 --- a/runtime/fs.h +++ b/runtime/fs.h @@ -57,6 +57,8 @@ void fs_trace(const char *what, const char *path); // NX2NAVI_TRACE=fs: // ---- fs_host.c void fs_host_set_profile(const char *dir); // profile directory; before the first storage mount only // (default rt_config()->profile) +void fs_host_lock_profile(void); // the one-game-per-profile lock; fatal when another copy + // holds it (rt_boot, before the prewarm; storage_init) int fs_save_busy(void); // a save is being written: a save file open for writing, // or save data changed in the last 3 s and not committed void fs_save_flush(void); // wait for a save Commit still running in the background; diff --git a/runtime/fs_host.c b/runtime/fs_host.c index cd3e095b..d0aafc05 100644 --- a/runtime/fs_host.c +++ b/runtime/fs_host.c @@ -619,19 +619,27 @@ static uint32_t save_commit(void) { } // ---- storage roots -static void storage_init(void *param) { - (void)param; +// One game per profile: a second one's start would take the first one's commit in progress for an interrupted one +// and delete it, and both would write into one working copy (save-tx/work), losing or mixing their saves. rt_boot +// takes the lock before the shader prewarm, so a second copy ends at once instead of after the prewarm's seconds of +// work on every core and the gigabytes of memory it commits; storage_init takes it again (plat_lock_file keeps one +// handle per path, so the second call holds it already). +void fs_host_lock_profile(void) { if (!*profile) need(snprintf(profile, sizeof profile, "%s", rt_config()->profile) < (int)sizeof profile, "profile path"); - uint64_t uid[2]; char p[PATH_CAP]; make_dirs(profile); - // One game per profile: a second one's start would take the first one's commit in progress for an interrupted - // one and delete it, and both would write into one working copy (save-tx/work), losing or mixing their saves. snprintf(p, sizeof p, "%s/instance.lock", profile); int held = plat_lock_file(p); if (!held) rt_fatal("fs: another copy of the game is running with the profile %s; close it first", profile); if (held < 0) rt_log("fs: cannot make %s; a second copy of the game would not be stopped", p); +} + +static void storage_init(void *param) { + (void)param; + uint64_t uid[2]; + char p[PATH_CAP]; + fs_host_lock_profile(); account_uid(uid); snprintf(p, sizeof p, "%s/save", profile); make_dirs(p);