Walk the process's address space for the memory census only when mem_census asks for it.

With trace = perf, every 600 frames heap_log started a thread that walks the whole address space with VirtualQuery
(plat_mem_census) for the "mem: process" line. The walk takes 100-240 ms, and though it runs on its own thread it
holds the process's address-space lock, which the game's threads take at every page fault and VirtualAlloc: the
present after each walk arrived 65-120 ms late, a hitch every ten seconds in every run with the trace on, and the
runs people attach to issues carried it. The walk now runs only with mem_census = 1 (NX2NAVI_MEM_CENSUS); the rest of
the memory lines stay.

Kokiri Forest, trace = perf: before, "slow frame" lines at 601, 1201, 1801, 2401 and 3002 of 65-120 ms with nothing
of it in the pipeline, texture or fence columns; after, none at those frames.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
itaskaev2
2026-11-09 12:50:19 +01:00
committed by chrg6
parent 03e6dac0be
commit 553067ea0b
3 changed files with 13 additions and 4 deletions

View File

@@ -2498,7 +2498,12 @@ static void heap_log(VkCtx *c, uint64_t frame, const VmaBudget *vb) {
d->statistics.allocationBytes / M, d->allocationSizeMax / M);
}
rt_log("%s", line);
if (plat_xchg32(&census_busy, 1)) return;
// The address-space walk of the census (plat_mem_census, 100-240 ms of VirtualQuery) runs on its own thread, but
// it holds the process's address-space lock, which the game's threads take at every page fault and every
// VirtualAlloc: the present after each walk arrived 65-120 ms late. NX2NAVI_MEM_CENSUS=1 asks for it.
static int census_on = -1;
if (census_on < 0) census_on = cfg_bool("NX2NAVI_MEM_CENSUS");
if (!census_on || plat_xchg32(&census_busy, 1)) return;
CensusJob *j = malloc(sizeof *j);
if (j) *j = (CensusJob){c, frame};
if (!j || !plat_thread_spawn(census_main, j, "mem census", 0)) free(j), plat_xchg32(&census_busy, 0);