Warn in the log at the start when the machine has less memory free than the game takes in play.

The game held 23.9 to 24.4 GB of commit in three sessions on an RTX 5090 at 3840x2160, flat over the session, on a
machine whose commit stood at 66 of 73 GB with it. A machine that cannot give it that much pages, drops textures or
loses the device, and its log said nothing about memory until then.

mem_start_note reads the system's commit when a game starts and writes one warning line when what is free, plus what
the process already holds, is below mem_need_mb (24576 by default, 0 for no warning). The menu has no place for a
start-up notice (its only toasts are the co-op page's), so the line is in the log alone.

tests/mem_need_check.py checks the rule and, through --probe-memneed, the answer and the warning line with the
machine's own commit.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-11 04:48:36 -05:00
parent 39fa0be78c
commit 147e8a02e3
9 changed files with 177 additions and 4 deletions

View File

@@ -14,6 +14,7 @@
#include "cfg.h"
#include "host.h"
#include "layout.h"
#include "mem_need.h"
#include "platform/platform.h"
#define PAGE 0x1000ull
@@ -951,6 +952,29 @@ void mem_init(void) {
const RtGuestLayout *mem_layout(void) { return &L; }
// The start of a game (main.c, before the boot): one line when the machine's free commit is below what the game takes
// in play (mem_need.h; NX2NAVI_MEM_NEED_MB, 0 no check), so a log that ends in a failed allocation, dropped textures
// or a lost device says at its top that the machine was short before the game took anything. 1 when it was.
// probe: --probe-memneed, which prints the numbers either way.
int mem_start_note(int probe) {
double proc, used, limit, need = strtod(cfg_value("NX2NAVI_MEM_NEED_MB"), NULL);
plat_commit_info(&proc, &used, &limit);
int is_short = mem_need_short(proc, used, limit, need);
if (probe)
printf("probe-memneed: system commit %.0f of %.0f MB in use, this process %.0f MB, the game needs %.0f MB "
"(NX2NAVI_MEM_NEED_MB): %s\n", used, limit, proc, need,
need <= 0 ? "not checked" : limit < 0 ? "no limit known" : is_short ? "short" : "enough");
if (!is_short) return 0;
char note[400] = "";
plat_commit_note(note, sizeof note);
rt_log("mem: WARNING: this machine has %.0f MB of memory left for the game and the game takes about %.0f MB in play "
"(system commit: %.0f of %.0f MB in use; the limit is RAM plus page file%s%s). Short of memory the game "
"stutters, loses textures or stops with an out-of-memory or lost-device error. Closing other programs or a "
"larger page file gives it room (mem_need_mb = 0 in nx2navi.ini turns this warning off)",
mem_need_room(proc, used, limit), need, used, limit, note[0] ? "; " : "", note);
return 1;
}
// A range inside one watched reservation (stack and heap block, or alias region) only.
static uint64_t written_pages(uint64_t addr, uint64_t size, uint64_t *pages, uint64_t max, int reset) {
if (!max || !size) return 0;