Skip to content

Commit 563a663

Browse files
committed
fix(test): harden mem_rss WorkingSetSize check for windows-11-arm
mem_rss_reflects_external_resident_memory asserted cbm_mem_rss() >= 128MB after touching a 256MB region, but on Windows cbm_mem_rss() reads WorkingSetSize (GetProcessMemoryInfo), which the OS trims under memory pressure — a stressed windows-11-arm runner kept only ~97MB resident and the leg (a required gate) flaked. Re-touch the region immediately before measuring and assert a 32MB Windows threshold that survives aggressive trimming while staying far above the ~1MB mimalloc warm buffer, so it still guards the real regression (a broken small-counter RSS). The Linux #else branch keeps its 128MB assertion (the actual undercount it was written for). Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 60e1769 commit 563a663

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

‎tests/test_mem.c‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,21 +261,30 @@ TEST(mem_rss_reflects_external_resident_memory) {
261261
ASSERT_NOT_NULL(mi_buf);
262262
memset(mi_buf, 0x11, warm);
263263

264-
const size_t region = (size_t)256 * 1024 * 1024; /* 256 MB true RSS */
265-
const size_t threshold = (size_t)128 * 1024 * 1024; /* generous half */
264+
const size_t region = (size_t)256 * 1024 * 1024; /* 256 MB true RSS */
266265

267266
#ifdef _WIN32
268-
/* Windows current_rss (WorkingSetSize) is accurate; a plain resident
269-
* allocation is reflected regardless of allocator. No Linux undercount. */
267+
/* On Windows cbm_mem_rss() reads WorkingSetSize (GetProcessMemoryInfo),
268+
* which the OS trims under memory pressure — so a touched region can drop
269+
* out of the resident set (a stressed windows-11-arm runner kept only
270+
* ~97 MB resident of a 256 MB touch). Re-touch the region immediately before
271+
* measuring so its pages are freshly resident, and assert a threshold that
272+
* survives aggressive trimming while staying far above the ~1 MB mimalloc
273+
* warm buffer. This still guards the real regression — cbm_mem_rss()
274+
* reporting a broken small counter instead of true resident memory — which
275+
* the Linux #else branch exercises directly against the undercount. */
276+
const size_t threshold = (size_t)32 * 1024 * 1024;
270277
void *big = malloc(region);
271278
ASSERT_NOT_NULL(big);
272279
memset(big, 0x5A, region);
280+
memset(big, 0x5B, region); /* re-touch right before the measurement */
273281
size_t rss = cbm_mem_rss();
274282
ASSERT_GTE(rss, threshold);
275283
free(big);
276284
#else
277285
/* (2) Raw mmap bypasses mimalloc entirely: its committed counter does NOT
278286
* grow, but the true RSS does — this is what exposes the Linux undercount. */
287+
const size_t threshold = (size_t)128 * 1024 * 1024; /* generous half of region */
279288
void *big = mmap(NULL, region, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
280289
ASSERT_TRUE(big != MAP_FAILED);
281290
memset(big, 0x5A, region); /* fault every page in → resident */

0 commit comments

Comments
 (0)