From 6e9ca1ebfd1332cb5ab7c0db28322e05977fa849 Mon Sep 17 00:00:00 2001 From: Valiantsin Dzerakh Date: Mon, 9 Nov 2026 08:53:57 +0300 Subject: [PATCH] Log the process commit in crash reports and in the memory census A driver that runs out of memory faults or throws std::bad_alloc instead of returning an error: #285's log shows bad_alloc inside amdvlk64.dll under gpl_link, and nothing in the report told that apart from a driver bug. The crash report now prints the process and system commit, as rt_fatal does for our own failed allocations; --probe-kernel checks the line. The census at frames 600 and 1800 logs the commit as a baseline and, per heap, VMA's blocks and allocations beside the driver's usage and budget, so a report shows whose memory grew. Co-Authored-By: Claude Opus 5.5 --- runtime/kernel_probe.c | 4 +++- runtime/main.c | 5 +++++ runtime/vk_memory.c | 17 +++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/runtime/kernel_probe.c b/runtime/kernel_probe.c index 6ee32e2b..cbbc9297 100644 --- a/runtime/kernel_probe.c +++ b/runtime/kernel_probe.c @@ -756,7 +756,9 @@ static void test_crash_report(void) { const char *g = report_line(out, "*5ca1ab1e0c0de002", line, sizeof line); CHECK(g && strstr(g, "x19"), "crash report: no memory line for x19 (%s)", g ? g : "none"); CHECK(strstr(out, "guest stack sp+0x00:"), "crash report: no guest stack words"); - printf("crash report: exit code %d, host registers, code bytes, memory at rbx and x19, guest stack %s\n", code, + CHECK(report_line(out, " memory commit: this process ", line, sizeof line) && !strstr(line, "process -1 MB"), + "crash report: no memory commit line"); + printf("crash report: exit code %d, host registers, code bytes, memory at rbx and x19, guest stack, commit %s\n", code, failures ? "checked with failures" : "present"); } diff --git a/runtime/main.c b/runtime/main.c index b8ff1132..a0e05c80 100644 --- a/runtime/main.c +++ b/runtime/main.c @@ -298,6 +298,11 @@ static void crash_handler(const PlatCrash *x) { rt_log_raw("\n", 1); if (x->cxx_type) rt_logf(" C++ type %s%s%s\n", x->cxx_type, x->cxx_what ? ", what(): " : "", x->cxx_what ? x->cxx_what : ""); + // A driver that runs out of memory faults or throws (std::bad_alloc) instead of returning an error: the commit + // tells that apart from a driver bug, as rt_fatal's line does for our own failed allocations. + double proc, used, limit; + plat_commit_info(&proc, &used, &limit); + rt_logf(" memory commit: this process %.0f MB, the system %.0f of %.0f MB\n", proc, used, limit); uintptr_t fstart = 0; uint64_t f = x->module ? 0 : lifted_function_at(rip, &fstart); if (f) diff --git a/runtime/vk_memory.c b/runtime/vk_memory.c index 98f0aefc..34e3df56 100644 --- a/runtime/vk_memory.c +++ b/runtime/vk_memory.c @@ -571,6 +571,23 @@ void vk_mem_census(uint64_t frame) { n_import_failures, (unsigned long long)count[POOL_PHYS], total[POOL_PHYS] / 1048576.0, (unsigned long long)count[POOL_VIRT], total[POOL_VIRT] / 1048576.0, (unsigned long long)__atomic_load_n(&n_cross_defer, __ATOMIC_RELAXED)); + // The baseline for the commit a crash report prints: a crash far above it points at growth during play. + double proc, used, limit; + plat_commit_info(&proc, &used, &limit); + rt_log("mem: commit at frame %llu: this process %.0f MB, the system %.0f of %.0f MB", (unsigned long long)frame, proc, + used, limit); + // Per heap, what VMA holds (blocks, and the allocations inside them) beside what the driver counts for the process: + // usage above VMA's blocks is the driver's own memory (pipelines, command buffers, descriptor pools). + VkCtx *vc = vk_ctx(); + if (vc && vc->vma) { + VmaBudget vb[VK_MAX_MEMORY_HEAPS]; + vmaGetHeapBudgets(vc->vma, vb); + for (uint32_t h = 0; h < vc->mem_props.memoryHeapCount && h < VK_MAX_MEMORY_HEAPS; h++) + rt_log("mem: heap %u (flags %#x) at frame %llu: vma %u blocks %.0f MiB, %u allocations %.0f MiB; driver usage " + "%.0f of %.0f MiB", h, vc->mem_props.memoryHeaps[h].flags, (unsigned long long)frame, + vb[h].statistics.blockCount, vb[h].statistics.blockBytes / 1048576.0, vb[h].statistics.allocationCount, + vb[h].statistics.allocationBytes / 1048576.0, vb[h].usage / 1048576.0, vb[h].budget / 1048576.0); + } static const char *const kinds[] = {"", "import", "physical", "virtual"}; for (int j = 0; j < ng; j++) { char f[160];