/*
* Size class that is a divisor of the page size, ideally 4+ regions per run.
*/
#if LG_PAGE <= 14
#define SZ (ZU(1) << (LG_PAGE - 2))
#else
#define SZ ZU(4096)
#endif
/*
* Number of slabs to consume at high water mark. Should be at least 2 so that
* if mmap()ed memory grows downward, downward growth of mmap()ed memory is
* tested.
*/
#define NSLABS 8
/* Fill matrix. */
for (i = offset = 0; i < NSLABS; i++) {
for (j = 0; j < nregs_per_run; j++) {
void *p = mallocx(SZ, MALLOCX_ARENA(arena_ind) |
MALLOCX_TCACHE_NONE);
expect_ptr_not_null(p,
"Unexpected mallocx(%zu, MALLOCX_ARENA(%u) |"
" MALLOCX_TCACHE_NONE) failure, run=%zu, reg=%zu",
SZ, arena_ind, i, j);
ptrs[(i * nregs_per_run) + j] = p;
}
}
/*
* Free all but one region of each run, but rotate which region is
* preserved, so that subsequent allocations exercise the within-run
* layout policy.
*/
offset = 0;
for (i = offset = 0;
i < NSLABS;
i++, offset = (offset + 1) % nregs_per_run) {
for (j = 0; j < nregs_per_run; j++) {
void *p = ptrs[(i * nregs_per_run) + j];
if (offset == j) {
continue;
}
dallocx(p, MALLOCX_ARENA(arena_ind) |
MALLOCX_TCACHE_NONE);
}
}
/*
* Logically refill matrix, skipping preserved regions and verifying
* that the matrix is unmodified.
*/
offset = 0;
for (i = offset = 0;
i < NSLABS;
i++, offset = (offset + 1) % nregs_per_run) {
for (j = 0; j < nregs_per_run; j++) {
void *p;
if (offset == j) {
continue;
}
p = mallocx(SZ, MALLOCX_ARENA(arena_ind) |
MALLOCX_TCACHE_NONE);
expect_ptr_eq(p, ptrs[(i * nregs_per_run) + j],
"Unexpected refill discrepancy, run=%zu, reg=%zu\n",
i, j);
}
}