Break the memory report down past VMA, by owner in system memory, and by growth over a session.

Every report adds a line for video memory outside VMA (the driver's usage and budget per heap against VMA's blocks, and counts of pipelines by kind and by last use, stage libraries, compute pipelines, layouts and descriptor pools, with the swapchain, DLSS and FSR sizes), a line that splits the process's commit by owner (the game's heap and maps, device-local memory, VMA's host blocks, the C runtime heap with the shader caches, pipeline tables, texture cache, log queue and flight recorder in it, the driver's pipeline cache data and the rest), and a line naming what grew by more than 64 MiB since the report before and since play began. Every ten minutes of play and at exit a ranking line orders the categories by growth and marks those that only climbed; tests/mem_growth_check.py checks that bookkeeping.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-13 06:46:00 -05:00
parent a74503cd86
commit d9429b0c00
28 changed files with 926 additions and 13 deletions

View File

@@ -6,6 +6,7 @@
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <malloc.h>
#include <linux/fs.h>
#include <linux/futex.h>
#include <linux/userfaultfd.h>
@@ -2241,6 +2242,17 @@ void plat_process_memory(uint64_t *resident, uint64_t *private_bytes) {
fclose(f);
}
// glibc's mallinfo2 (2.33 and later) sums every arena: arena is what the arenas took with brk and mmap, hblkhd the
// blocks mmapped one by one, uordblks what the arenas handed out. Other C libraries leave the figures unknown.
void plat_heap_info(PlatHeapInfo *h) {
memset(h, 0, sizeof *h);
#if defined(__GLIBC__) && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 33))
struct mallinfo2 m = mallinfo2();
h->committed = (uint64_t)m.arena + m.hblkhd;
h->used = (uint64_t)m.uordblks + m.hblkhd;
#endif
}
// ---- memory limits
//
// Linux overcommits, so memory that runs short does not fail an allocation: the OOM killer ends the process, when it

View File

@@ -526,6 +526,13 @@ int plat_page_file_managed(void);
// This process's memory in bytes: resident (the working set) and private (Windows: committed private bytes; Linux: the
// resident anonymous pages). 0 when unknown.
void plat_process_memory(uint64_t *resident, uint64_t *private_bytes);
// The C runtime's malloc heap in bytes, for the memory report (vk_memory.c system_log): what it took from the system
// (committed) and what of that it handed out (used), and how many other heaps the process has (Windows: those DLLs made
// with HeapCreate, the graphics driver's among them; their sizes are not asked, as a heap made without serialization
// cannot be read while its owner uses it). 0 when unknown. Holds the heap's lock while it adds up, so it is called at
// report time only. Windows: HeapSummary of the heap malloc uses; Linux: glibc's mallinfo2 over every arena.
typedef struct { uint64_t committed, used; uint32_t other_heaps; } PlatHeapInfo;
void plat_heap_info(PlatHeapInfo *h);
// ---- child processes: a program with stdin and stdout piped to us (stderr discarded), no console window.
typedef struct PlatChild PlatChild;

View File

@@ -2,6 +2,7 @@
// SRW locks and condition variables.
#include <io.h>
#include <limits.h>
#include <malloc.h> // _get_heap_handle (plat_heap_info)
#include <stdio.h>
#include <winsock2.h> // before windows.h, which would otherwise pull in the old winsock.h
#include <ws2tcpip.h>
@@ -2067,6 +2068,18 @@ void plat_process_memory(uint64_t *resident, uint64_t *private_bytes) {
*resident = pm.WorkingSetSize, *private_bytes = pm.PrivateUsage;
}
// The UCRT's malloc takes its memory from the heap _get_heap_handle names (the process heap); HeapSummary sums it. The
// other heaps are only counted: one made with HEAP_NO_SERIALIZE has no lock to take.
void plat_heap_info(PlatHeapInfo *h) {
memset(h, 0, sizeof *h);
HANDLE crt = (HANDLE)_get_heap_handle();
HEAP_SUMMARY s = {.cb = sizeof s};
if (crt && HeapSummary(crt, 0, &s)) h->committed = s.cbCommitted, h->used = s.cbAllocated;
HANDLE hs[256];
DWORD n = GetProcessHeaps(256, hs);
for (DWORD i = 0; i < n && i < 256; i++) h->other_heaps += hs[i] != crt;
}
// ---- child processes
struct PlatChild {