xref: /netbsd-src/external/bsd/jemalloc.old/dist/test/unit/stats.c (revision 8e33eff89e26cf71871ead62f0d5063e1313c33a)
1*8e33eff8Schristos #include "test/jemalloc_test.h"
2*8e33eff8Schristos 
3*8e33eff8Schristos TEST_BEGIN(test_stats_summary) {
4*8e33eff8Schristos 	size_t sz, allocated, active, resident, mapped;
5*8e33eff8Schristos 	int expected = config_stats ? 0 : ENOENT;
6*8e33eff8Schristos 
7*8e33eff8Schristos 	sz = sizeof(size_t);
8*8e33eff8Schristos 	assert_d_eq(mallctl("stats.allocated", (void *)&allocated, &sz, NULL,
9*8e33eff8Schristos 	    0), expected, "Unexpected mallctl() result");
10*8e33eff8Schristos 	assert_d_eq(mallctl("stats.active", (void *)&active, &sz, NULL, 0),
11*8e33eff8Schristos 	    expected, "Unexpected mallctl() result");
12*8e33eff8Schristos 	assert_d_eq(mallctl("stats.resident", (void *)&resident, &sz, NULL, 0),
13*8e33eff8Schristos 	    expected, "Unexpected mallctl() result");
14*8e33eff8Schristos 	assert_d_eq(mallctl("stats.mapped", (void *)&mapped, &sz, NULL, 0),
15*8e33eff8Schristos 	    expected, "Unexpected mallctl() result");
16*8e33eff8Schristos 
17*8e33eff8Schristos 	if (config_stats) {
18*8e33eff8Schristos 		assert_zu_le(allocated, active,
19*8e33eff8Schristos 		    "allocated should be no larger than active");
20*8e33eff8Schristos 		assert_zu_lt(active, resident,
21*8e33eff8Schristos 		    "active should be less than resident");
22*8e33eff8Schristos 		assert_zu_lt(active, mapped,
23*8e33eff8Schristos 		    "active should be less than mapped");
24*8e33eff8Schristos 	}
25*8e33eff8Schristos }
26*8e33eff8Schristos TEST_END
27*8e33eff8Schristos 
28*8e33eff8Schristos TEST_BEGIN(test_stats_large) {
29*8e33eff8Schristos 	void *p;
30*8e33eff8Schristos 	uint64_t epoch;
31*8e33eff8Schristos 	size_t allocated;
32*8e33eff8Schristos 	uint64_t nmalloc, ndalloc, nrequests;
33*8e33eff8Schristos 	size_t sz;
34*8e33eff8Schristos 	int expected = config_stats ? 0 : ENOENT;
35*8e33eff8Schristos 
36*8e33eff8Schristos 	p = mallocx(SMALL_MAXCLASS+1, MALLOCX_ARENA(0));
37*8e33eff8Schristos 	assert_ptr_not_null(p, "Unexpected mallocx() failure");
38*8e33eff8Schristos 
39*8e33eff8Schristos 	assert_d_eq(mallctl("epoch", NULL, NULL, (void *)&epoch, sizeof(epoch)),
40*8e33eff8Schristos 	    0, "Unexpected mallctl() failure");
41*8e33eff8Schristos 
42*8e33eff8Schristos 	sz = sizeof(size_t);
43*8e33eff8Schristos 	assert_d_eq(mallctl("stats.arenas.0.large.allocated",
44*8e33eff8Schristos 	    (void *)&allocated, &sz, NULL, 0), expected,
45*8e33eff8Schristos 	    "Unexpected mallctl() result");
46*8e33eff8Schristos 	sz = sizeof(uint64_t);
47*8e33eff8Schristos 	assert_d_eq(mallctl("stats.arenas.0.large.nmalloc", (void *)&nmalloc,
48*8e33eff8Schristos 	    &sz, NULL, 0), expected, "Unexpected mallctl() result");
49*8e33eff8Schristos 	assert_d_eq(mallctl("stats.arenas.0.large.ndalloc", (void *)&ndalloc,
50*8e33eff8Schristos 	    &sz, NULL, 0), expected, "Unexpected mallctl() result");
51*8e33eff8Schristos 	assert_d_eq(mallctl("stats.arenas.0.large.nrequests",
52*8e33eff8Schristos 	    (void *)&nrequests, &sz, NULL, 0), expected,
53*8e33eff8Schristos 	    "Unexpected mallctl() result");
54*8e33eff8Schristos 
55*8e33eff8Schristos 	if (config_stats) {
56*8e33eff8Schristos 		assert_zu_gt(allocated, 0,
57*8e33eff8Schristos 		    "allocated should be greater than zero");
58*8e33eff8Schristos 		assert_u64_ge(nmalloc, ndalloc,
59*8e33eff8Schristos 		    "nmalloc should be at least as large as ndalloc");
60*8e33eff8Schristos 		assert_u64_le(nmalloc, nrequests,
61*8e33eff8Schristos 		    "nmalloc should no larger than nrequests");
62*8e33eff8Schristos 	}
63*8e33eff8Schristos 
64*8e33eff8Schristos 	dallocx(p, 0);
65*8e33eff8Schristos }
66*8e33eff8Schristos TEST_END
67*8e33eff8Schristos 
68*8e33eff8Schristos TEST_BEGIN(test_stats_arenas_summary) {
69*8e33eff8Schristos 	void *little, *large;
70*8e33eff8Schristos 	uint64_t epoch;
71*8e33eff8Schristos 	size_t sz;
72*8e33eff8Schristos 	int expected = config_stats ? 0 : ENOENT;
73*8e33eff8Schristos 	size_t mapped;
74*8e33eff8Schristos 	uint64_t dirty_npurge, dirty_nmadvise, dirty_purged;
75*8e33eff8Schristos 	uint64_t muzzy_npurge, muzzy_nmadvise, muzzy_purged;
76*8e33eff8Schristos 
77*8e33eff8Schristos 	little = mallocx(SMALL_MAXCLASS, MALLOCX_ARENA(0));
78*8e33eff8Schristos 	assert_ptr_not_null(little, "Unexpected mallocx() failure");
79*8e33eff8Schristos 	large = mallocx((1U << LG_LARGE_MINCLASS), MALLOCX_ARENA(0));
80*8e33eff8Schristos 	assert_ptr_not_null(large, "Unexpected mallocx() failure");
81*8e33eff8Schristos 
82*8e33eff8Schristos 	dallocx(little, 0);
83*8e33eff8Schristos 	dallocx(large, 0);
84*8e33eff8Schristos 
85*8e33eff8Schristos 	assert_d_eq(mallctl("thread.tcache.flush", NULL, NULL, NULL, 0),
86*8e33eff8Schristos 	    opt_tcache ? 0 : EFAULT, "Unexpected mallctl() result");
87*8e33eff8Schristos 	assert_d_eq(mallctl("arena.0.purge", NULL, NULL, NULL, 0), 0,
88*8e33eff8Schristos 	    "Unexpected mallctl() failure");
89*8e33eff8Schristos 
90*8e33eff8Schristos 	assert_d_eq(mallctl("epoch", NULL, NULL, (void *)&epoch, sizeof(epoch)),
91*8e33eff8Schristos 	    0, "Unexpected mallctl() failure");
92*8e33eff8Schristos 
93*8e33eff8Schristos 	sz = sizeof(size_t);
94*8e33eff8Schristos 	assert_d_eq(mallctl("stats.arenas.0.mapped", (void *)&mapped, &sz, NULL,
95*8e33eff8Schristos 	    0), expected, "Unexepected mallctl() result");
96*8e33eff8Schristos 
97*8e33eff8Schristos 	sz = sizeof(uint64_t);
98*8e33eff8Schristos 	assert_d_eq(mallctl("stats.arenas.0.dirty_npurge",
99*8e33eff8Schristos 	    (void *)&dirty_npurge, &sz, NULL, 0), expected,
100*8e33eff8Schristos 	    "Unexepected mallctl() result");
101*8e33eff8Schristos 	assert_d_eq(mallctl("stats.arenas.0.dirty_nmadvise",
102*8e33eff8Schristos 	    (void *)&dirty_nmadvise, &sz, NULL, 0), expected,
103*8e33eff8Schristos 	    "Unexepected mallctl() result");
104*8e33eff8Schristos 	assert_d_eq(mallctl("stats.arenas.0.dirty_purged",
105*8e33eff8Schristos 	    (void *)&dirty_purged, &sz, NULL, 0), expected,
106*8e33eff8Schristos 	    "Unexepected mallctl() result");
107*8e33eff8Schristos 	assert_d_eq(mallctl("stats.arenas.0.muzzy_npurge",
108*8e33eff8Schristos 	    (void *)&muzzy_npurge, &sz, NULL, 0), expected,
109*8e33eff8Schristos 	    "Unexepected mallctl() result");
110*8e33eff8Schristos 	assert_d_eq(mallctl("stats.arenas.0.muzzy_nmadvise",
111*8e33eff8Schristos 	    (void *)&muzzy_nmadvise, &sz, NULL, 0), expected,
112*8e33eff8Schristos 	    "Unexepected mallctl() result");
113*8e33eff8Schristos 	assert_d_eq(mallctl("stats.arenas.0.muzzy_purged",
114*8e33eff8Schristos 	    (void *)&muzzy_purged, &sz, NULL, 0), expected,
115*8e33eff8Schristos 	    "Unexepected mallctl() result");
116*8e33eff8Schristos 
117*8e33eff8Schristos 	if (config_stats) {
118*8e33eff8Schristos 		if (!background_thread_enabled()) {
119*8e33eff8Schristos 			assert_u64_gt(dirty_npurge + muzzy_npurge, 0,
120*8e33eff8Schristos 			    "At least one purge should have occurred");
121*8e33eff8Schristos 		}
122*8e33eff8Schristos 		assert_u64_le(dirty_nmadvise, dirty_purged,
123*8e33eff8Schristos 		    "dirty_nmadvise should be no greater than dirty_purged");
124*8e33eff8Schristos 		assert_u64_le(muzzy_nmadvise, muzzy_purged,
125*8e33eff8Schristos 		    "muzzy_nmadvise should be no greater than muzzy_purged");
126*8e33eff8Schristos 	}
127*8e33eff8Schristos }
128*8e33eff8Schristos TEST_END
129*8e33eff8Schristos 
130*8e33eff8Schristos void *
131*8e33eff8Schristos thd_start(void *arg) {
132*8e33eff8Schristos 	return NULL;
133*8e33eff8Schristos }
134*8e33eff8Schristos 
135*8e33eff8Schristos static void
136*8e33eff8Schristos no_lazy_lock(void) {
137*8e33eff8Schristos 	thd_t thd;
138*8e33eff8Schristos 
139*8e33eff8Schristos 	thd_create(&thd, thd_start, NULL);
140*8e33eff8Schristos 	thd_join(thd, NULL);
141*8e33eff8Schristos }
142*8e33eff8Schristos 
143*8e33eff8Schristos TEST_BEGIN(test_stats_arenas_small) {
144*8e33eff8Schristos 	void *p;
145*8e33eff8Schristos 	size_t sz, allocated;
146*8e33eff8Schristos 	uint64_t epoch, nmalloc, ndalloc, nrequests;
147*8e33eff8Schristos 	int expected = config_stats ? 0 : ENOENT;
148*8e33eff8Schristos 
149*8e33eff8Schristos 	no_lazy_lock(); /* Lazy locking would dodge tcache testing. */
150*8e33eff8Schristos 
151*8e33eff8Schristos 	p = mallocx(SMALL_MAXCLASS, MALLOCX_ARENA(0));
152*8e33eff8Schristos 	assert_ptr_not_null(p, "Unexpected mallocx() failure");
153*8e33eff8Schristos 
154*8e33eff8Schristos 	assert_d_eq(mallctl("thread.tcache.flush", NULL, NULL, NULL, 0),
155*8e33eff8Schristos 	    opt_tcache ? 0 : EFAULT, "Unexpected mallctl() result");
156*8e33eff8Schristos 
157*8e33eff8Schristos 	assert_d_eq(mallctl("epoch", NULL, NULL, (void *)&epoch, sizeof(epoch)),
158*8e33eff8Schristos 	    0, "Unexpected mallctl() failure");
159*8e33eff8Schristos 
160*8e33eff8Schristos 	sz = sizeof(size_t);
161*8e33eff8Schristos 	assert_d_eq(mallctl("stats.arenas.0.small.allocated",
162*8e33eff8Schristos 	    (void *)&allocated, &sz, NULL, 0), expected,
163*8e33eff8Schristos 	    "Unexpected mallctl() result");
164*8e33eff8Schristos 	sz = sizeof(uint64_t);
165*8e33eff8Schristos 	assert_d_eq(mallctl("stats.arenas.0.small.nmalloc", (void *)&nmalloc,
166*8e33eff8Schristos 	    &sz, NULL, 0), expected, "Unexpected mallctl() result");
167*8e33eff8Schristos 	assert_d_eq(mallctl("stats.arenas.0.small.ndalloc", (void *)&ndalloc,
168*8e33eff8Schristos 	    &sz, NULL, 0), expected, "Unexpected mallctl() result");
169*8e33eff8Schristos 	assert_d_eq(mallctl("stats.arenas.0.small.nrequests",
170*8e33eff8Schristos 	    (void *)&nrequests, &sz, NULL, 0), expected,
171*8e33eff8Schristos 	    "Unexpected mallctl() result");
172*8e33eff8Schristos 
173*8e33eff8Schristos 	if (config_stats) {
174*8e33eff8Schristos 		assert_zu_gt(allocated, 0,
175*8e33eff8Schristos 		    "allocated should be greater than zero");
176*8e33eff8Schristos 		assert_u64_gt(nmalloc, 0,
177*8e33eff8Schristos 		    "nmalloc should be no greater than zero");
178*8e33eff8Schristos 		assert_u64_ge(nmalloc, ndalloc,
179*8e33eff8Schristos 		    "nmalloc should be at least as large as ndalloc");
180*8e33eff8Schristos 		assert_u64_gt(nrequests, 0,
181*8e33eff8Schristos 		    "nrequests should be greater than zero");
182*8e33eff8Schristos 	}
183*8e33eff8Schristos 
184*8e33eff8Schristos 	dallocx(p, 0);
185*8e33eff8Schristos }
186*8e33eff8Schristos TEST_END
187*8e33eff8Schristos 
188*8e33eff8Schristos TEST_BEGIN(test_stats_arenas_large) {
189*8e33eff8Schristos 	void *p;
190*8e33eff8Schristos 	size_t sz, allocated;
191*8e33eff8Schristos 	uint64_t epoch, nmalloc, ndalloc;
192*8e33eff8Schristos 	int expected = config_stats ? 0 : ENOENT;
193*8e33eff8Schristos 
194*8e33eff8Schristos 	p = mallocx((1U << LG_LARGE_MINCLASS), MALLOCX_ARENA(0));
195*8e33eff8Schristos 	assert_ptr_not_null(p, "Unexpected mallocx() failure");
196*8e33eff8Schristos 
197*8e33eff8Schristos 	assert_d_eq(mallctl("epoch", NULL, NULL, (void *)&epoch, sizeof(epoch)),
198*8e33eff8Schristos 	    0, "Unexpected mallctl() failure");
199*8e33eff8Schristos 
200*8e33eff8Schristos 	sz = sizeof(size_t);
201*8e33eff8Schristos 	assert_d_eq(mallctl("stats.arenas.0.large.allocated",
202*8e33eff8Schristos 	    (void *)&allocated, &sz, NULL, 0), expected,
203*8e33eff8Schristos 	    "Unexpected mallctl() result");
204*8e33eff8Schristos 	sz = sizeof(uint64_t);
205*8e33eff8Schristos 	assert_d_eq(mallctl("stats.arenas.0.large.nmalloc", (void *)&nmalloc,
206*8e33eff8Schristos 	    &sz, NULL, 0), expected, "Unexpected mallctl() result");
207*8e33eff8Schristos 	assert_d_eq(mallctl("stats.arenas.0.large.ndalloc", (void *)&ndalloc,
208*8e33eff8Schristos 	    &sz, NULL, 0), expected, "Unexpected mallctl() result");
209*8e33eff8Schristos 
210*8e33eff8Schristos 	if (config_stats) {
211*8e33eff8Schristos 		assert_zu_gt(allocated, 0,
212*8e33eff8Schristos 		    "allocated should be greater than zero");
213*8e33eff8Schristos 		assert_u64_gt(nmalloc, 0,
214*8e33eff8Schristos 		    "nmalloc should be greater than zero");
215*8e33eff8Schristos 		assert_u64_ge(nmalloc, ndalloc,
216*8e33eff8Schristos 		    "nmalloc should be at least as large as ndalloc");
217*8e33eff8Schristos 	}
218*8e33eff8Schristos 
219*8e33eff8Schristos 	dallocx(p, 0);
220*8e33eff8Schristos }
221*8e33eff8Schristos TEST_END
222*8e33eff8Schristos 
223*8e33eff8Schristos static void
224*8e33eff8Schristos gen_mallctl_str(char *cmd, char *name, unsigned arena_ind) {
225*8e33eff8Schristos 	sprintf(cmd, "stats.arenas.%u.bins.0.%s", arena_ind, name);
226*8e33eff8Schristos }
227*8e33eff8Schristos 
228*8e33eff8Schristos TEST_BEGIN(test_stats_arenas_bins) {
229*8e33eff8Schristos 	void *p;
230*8e33eff8Schristos 	size_t sz, curslabs, curregs;
231*8e33eff8Schristos 	uint64_t epoch, nmalloc, ndalloc, nrequests, nfills, nflushes;
232*8e33eff8Schristos 	uint64_t nslabs, nreslabs;
233*8e33eff8Schristos 	int expected = config_stats ? 0 : ENOENT;
234*8e33eff8Schristos 
235*8e33eff8Schristos 	/* Make sure allocation below isn't satisfied by tcache. */
236*8e33eff8Schristos 	assert_d_eq(mallctl("thread.tcache.flush", NULL, NULL, NULL, 0),
237*8e33eff8Schristos 	    opt_tcache ? 0 : EFAULT, "Unexpected mallctl() result");
238*8e33eff8Schristos 
239*8e33eff8Schristos 	unsigned arena_ind, old_arena_ind;
240*8e33eff8Schristos 	sz = sizeof(unsigned);
241*8e33eff8Schristos 	assert_d_eq(mallctl("arenas.create", (void *)&arena_ind, &sz, NULL, 0),
242*8e33eff8Schristos 	    0, "Arena creation failure");
243*8e33eff8Schristos 	sz = sizeof(arena_ind);
244*8e33eff8Schristos 	assert_d_eq(mallctl("thread.arena", (void *)&old_arena_ind, &sz,
245*8e33eff8Schristos 	    (void *)&arena_ind, sizeof(arena_ind)), 0,
246*8e33eff8Schristos 	    "Unexpected mallctl() failure");
247*8e33eff8Schristos 
248*8e33eff8Schristos 	p = malloc(bin_infos[0].reg_size);
249*8e33eff8Schristos 	assert_ptr_not_null(p, "Unexpected malloc() failure");
250*8e33eff8Schristos 
251*8e33eff8Schristos 	assert_d_eq(mallctl("thread.tcache.flush", NULL, NULL, NULL, 0),
252*8e33eff8Schristos 	    opt_tcache ? 0 : EFAULT, "Unexpected mallctl() result");
253*8e33eff8Schristos 
254*8e33eff8Schristos 	assert_d_eq(mallctl("epoch", NULL, NULL, (void *)&epoch, sizeof(epoch)),
255*8e33eff8Schristos 	    0, "Unexpected mallctl() failure");
256*8e33eff8Schristos 
257*8e33eff8Schristos 	char cmd[128];
258*8e33eff8Schristos 	sz = sizeof(uint64_t);
259*8e33eff8Schristos 	gen_mallctl_str(cmd, "nmalloc", arena_ind);
260*8e33eff8Schristos 	assert_d_eq(mallctl(cmd, (void *)&nmalloc, &sz, NULL, 0), expected,
261*8e33eff8Schristos 	    "Unexpected mallctl() result");
262*8e33eff8Schristos 	gen_mallctl_str(cmd, "ndalloc", arena_ind);
263*8e33eff8Schristos 	assert_d_eq(mallctl(cmd, (void *)&ndalloc, &sz, NULL, 0), expected,
264*8e33eff8Schristos 	    "Unexpected mallctl() result");
265*8e33eff8Schristos 	gen_mallctl_str(cmd, "nrequests", arena_ind);
266*8e33eff8Schristos 	assert_d_eq(mallctl(cmd, (void *)&nrequests, &sz, NULL, 0), expected,
267*8e33eff8Schristos 	    "Unexpected mallctl() result");
268*8e33eff8Schristos 	sz = sizeof(size_t);
269*8e33eff8Schristos 	gen_mallctl_str(cmd, "curregs", arena_ind);
270*8e33eff8Schristos 	assert_d_eq(mallctl(cmd, (void *)&curregs, &sz, NULL, 0), expected,
271*8e33eff8Schristos 	    "Unexpected mallctl() result");
272*8e33eff8Schristos 
273*8e33eff8Schristos 	sz = sizeof(uint64_t);
274*8e33eff8Schristos 	gen_mallctl_str(cmd, "nfills", arena_ind);
275*8e33eff8Schristos 	assert_d_eq(mallctl(cmd, (void *)&nfills, &sz, NULL, 0), expected,
276*8e33eff8Schristos 	    "Unexpected mallctl() result");
277*8e33eff8Schristos 	gen_mallctl_str(cmd, "nflushes", arena_ind);
278*8e33eff8Schristos 	assert_d_eq(mallctl(cmd, (void *)&nflushes, &sz, NULL, 0), expected,
279*8e33eff8Schristos 	    "Unexpected mallctl() result");
280*8e33eff8Schristos 
281*8e33eff8Schristos 	gen_mallctl_str(cmd, "nslabs", arena_ind);
282*8e33eff8Schristos 	assert_d_eq(mallctl(cmd, (void *)&nslabs, &sz, NULL, 0), expected,
283*8e33eff8Schristos 	    "Unexpected mallctl() result");
284*8e33eff8Schristos 	gen_mallctl_str(cmd, "nreslabs", arena_ind);
285*8e33eff8Schristos 	assert_d_eq(mallctl(cmd, (void *)&nreslabs, &sz, NULL, 0), expected,
286*8e33eff8Schristos 	    "Unexpected mallctl() result");
287*8e33eff8Schristos 	sz = sizeof(size_t);
288*8e33eff8Schristos 	gen_mallctl_str(cmd, "curslabs", arena_ind);
289*8e33eff8Schristos 	assert_d_eq(mallctl(cmd, (void *)&curslabs, &sz, NULL, 0), expected,
290*8e33eff8Schristos 	    "Unexpected mallctl() result");
291*8e33eff8Schristos 
292*8e33eff8Schristos 	if (config_stats) {
293*8e33eff8Schristos 		assert_u64_gt(nmalloc, 0,
294*8e33eff8Schristos 		    "nmalloc should be greater than zero");
295*8e33eff8Schristos 		assert_u64_ge(nmalloc, ndalloc,
296*8e33eff8Schristos 		    "nmalloc should be at least as large as ndalloc");
297*8e33eff8Schristos 		assert_u64_gt(nrequests, 0,
298*8e33eff8Schristos 		    "nrequests should be greater than zero");
299*8e33eff8Schristos 		assert_zu_gt(curregs, 0,
300*8e33eff8Schristos 		    "allocated should be greater than zero");
301*8e33eff8Schristos 		if (opt_tcache) {
302*8e33eff8Schristos 			assert_u64_gt(nfills, 0,
303*8e33eff8Schristos 			    "At least one fill should have occurred");
304*8e33eff8Schristos 			assert_u64_gt(nflushes, 0,
305*8e33eff8Schristos 			    "At least one flush should have occurred");
306*8e33eff8Schristos 		}
307*8e33eff8Schristos 		assert_u64_gt(nslabs, 0,
308*8e33eff8Schristos 		    "At least one slab should have been allocated");
309*8e33eff8Schristos 		assert_zu_gt(curslabs, 0,
310*8e33eff8Schristos 		    "At least one slab should be currently allocated");
311*8e33eff8Schristos 	}
312*8e33eff8Schristos 
313*8e33eff8Schristos 	dallocx(p, 0);
314*8e33eff8Schristos }
315*8e33eff8Schristos TEST_END
316*8e33eff8Schristos 
317*8e33eff8Schristos TEST_BEGIN(test_stats_arenas_lextents) {
318*8e33eff8Schristos 	void *p;
319*8e33eff8Schristos 	uint64_t epoch, nmalloc, ndalloc;
320*8e33eff8Schristos 	size_t curlextents, sz, hsize;
321*8e33eff8Schristos 	int expected = config_stats ? 0 : ENOENT;
322*8e33eff8Schristos 
323*8e33eff8Schristos 	sz = sizeof(size_t);
324*8e33eff8Schristos 	assert_d_eq(mallctl("arenas.lextent.0.size", (void *)&hsize, &sz, NULL,
325*8e33eff8Schristos 	    0), 0, "Unexpected mallctl() failure");
326*8e33eff8Schristos 
327*8e33eff8Schristos 	p = mallocx(hsize, MALLOCX_ARENA(0));
328*8e33eff8Schristos 	assert_ptr_not_null(p, "Unexpected mallocx() failure");
329*8e33eff8Schristos 
330*8e33eff8Schristos 	assert_d_eq(mallctl("epoch", NULL, NULL, (void *)&epoch, sizeof(epoch)),
331*8e33eff8Schristos 	    0, "Unexpected mallctl() failure");
332*8e33eff8Schristos 
333*8e33eff8Schristos 	sz = sizeof(uint64_t);
334*8e33eff8Schristos 	assert_d_eq(mallctl("stats.arenas.0.lextents.0.nmalloc",
335*8e33eff8Schristos 	    (void *)&nmalloc, &sz, NULL, 0), expected,
336*8e33eff8Schristos 	    "Unexpected mallctl() result");
337*8e33eff8Schristos 	assert_d_eq(mallctl("stats.arenas.0.lextents.0.ndalloc",
338*8e33eff8Schristos 	    (void *)&ndalloc, &sz, NULL, 0), expected,
339*8e33eff8Schristos 	    "Unexpected mallctl() result");
340*8e33eff8Schristos 	sz = sizeof(size_t);
341*8e33eff8Schristos 	assert_d_eq(mallctl("stats.arenas.0.lextents.0.curlextents",
342*8e33eff8Schristos 	    (void *)&curlextents, &sz, NULL, 0), expected,
343*8e33eff8Schristos 	    "Unexpected mallctl() result");
344*8e33eff8Schristos 
345*8e33eff8Schristos 	if (config_stats) {
346*8e33eff8Schristos 		assert_u64_gt(nmalloc, 0,
347*8e33eff8Schristos 		    "nmalloc should be greater than zero");
348*8e33eff8Schristos 		assert_u64_ge(nmalloc, ndalloc,
349*8e33eff8Schristos 		    "nmalloc should be at least as large as ndalloc");
350*8e33eff8Schristos 		assert_u64_gt(curlextents, 0,
351*8e33eff8Schristos 		    "At least one extent should be currently allocated");
352*8e33eff8Schristos 	}
353*8e33eff8Schristos 
354*8e33eff8Schristos 	dallocx(p, 0);
355*8e33eff8Schristos }
356*8e33eff8Schristos TEST_END
357*8e33eff8Schristos 
358*8e33eff8Schristos int
359*8e33eff8Schristos main(void) {
360*8e33eff8Schristos 	return test_no_reentrancy(
361*8e33eff8Schristos 	    test_stats_summary,
362*8e33eff8Schristos 	    test_stats_large,
363*8e33eff8Schristos 	    test_stats_arenas_summary,
364*8e33eff8Schristos 	    test_stats_arenas_small,
365*8e33eff8Schristos 	    test_stats_arenas_large,
366*8e33eff8Schristos 	    test_stats_arenas_bins,
367*8e33eff8Schristos 	    test_stats_arenas_lextents);
368*8e33eff8Schristos }
369