2016-05-18 05:58:56 +08:00
|
|
|
#include "test/jemalloc_test.h"
|
|
|
|
|
|
|
|
TEST_BEGIN(test_small_extent_size)
|
|
|
|
{
|
|
|
|
unsigned nbins, i;
|
|
|
|
size_t sz, extent_size;
|
|
|
|
size_t mib[4];
|
|
|
|
size_t miblen = sizeof(mib) / sizeof(size_t);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Iterate over all small size classes, get their extent sizes, and
|
|
|
|
* verify that the quantized size is the same as the extent size.
|
|
|
|
*/
|
|
|
|
|
|
|
|
sz = sizeof(unsigned);
|
2016-10-28 12:31:25 +08:00
|
|
|
assert_d_eq(mallctl("arenas.nbins", (void *)&nbins, &sz, NULL, 0), 0,
|
2016-05-18 05:58:56 +08:00
|
|
|
"Unexpected mallctl failure");
|
|
|
|
|
2016-05-30 09:34:50 +08:00
|
|
|
assert_d_eq(mallctlnametomib("arenas.bin.0.slab_size", mib, &miblen), 0,
|
2016-05-18 05:58:56 +08:00
|
|
|
"Unexpected mallctlnametomib failure");
|
|
|
|
for (i = 0; i < nbins; i++) {
|
|
|
|
mib[2] = i;
|
|
|
|
sz = sizeof(size_t);
|
2016-10-28 12:31:25 +08:00
|
|
|
assert_d_eq(mallctlbymib(mib, miblen, (void *)&extent_size, &sz,
|
|
|
|
NULL, 0), 0, "Unexpected mallctlbymib failure");
|
2016-05-18 05:58:56 +08:00
|
|
|
assert_zu_eq(extent_size,
|
|
|
|
extent_size_quantize_floor(extent_size),
|
|
|
|
"Small extent quantization should be a no-op "
|
|
|
|
"(extent_size=%zu)", extent_size);
|
|
|
|
assert_zu_eq(extent_size,
|
|
|
|
extent_size_quantize_ceil(extent_size),
|
|
|
|
"Small extent quantization should be a no-op "
|
|
|
|
"(extent_size=%zu)", extent_size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TEST_END
|
|
|
|
|
2016-06-01 05:50:21 +08:00
|
|
|
TEST_BEGIN(test_large_extent_size)
|
2016-05-18 05:58:56 +08:00
|
|
|
{
|
|
|
|
bool cache_oblivious;
|
2016-06-01 05:50:21 +08:00
|
|
|
unsigned nlextents, i;
|
2016-05-18 05:58:56 +08:00
|
|
|
size_t sz, extent_size_prev, ceil_prev;
|
|
|
|
size_t mib[4];
|
|
|
|
size_t miblen = sizeof(mib) / sizeof(size_t);
|
|
|
|
|
|
|
|
/*
|
2016-06-01 05:50:21 +08:00
|
|
|
* Iterate over all large size classes, get their extent sizes, and
|
2016-05-18 05:58:56 +08:00
|
|
|
* verify that the quantized size is the same as the extent size.
|
|
|
|
*/
|
|
|
|
|
|
|
|
sz = sizeof(bool);
|
2016-10-28 12:31:25 +08:00
|
|
|
assert_d_eq(mallctl("config.cache_oblivious", (void *)&cache_oblivious,
|
|
|
|
&sz, NULL, 0), 0, "Unexpected mallctl failure");
|
2016-05-18 05:58:56 +08:00
|
|
|
|
|
|
|
sz = sizeof(unsigned);
|
2016-10-28 12:31:25 +08:00
|
|
|
assert_d_eq(mallctl("arenas.nlextents", (void *)&nlextents, &sz, NULL,
|
|
|
|
0), 0, "Unexpected mallctl failure");
|
2016-05-18 05:58:56 +08:00
|
|
|
|
2016-06-01 05:50:21 +08:00
|
|
|
assert_d_eq(mallctlnametomib("arenas.lextent.0.size", mib, &miblen), 0,
|
2016-05-18 05:58:56 +08:00
|
|
|
"Unexpected mallctlnametomib failure");
|
2016-06-01 05:50:21 +08:00
|
|
|
for (i = 0; i < nlextents; i++) {
|
2016-05-18 05:58:56 +08:00
|
|
|
size_t lextent_size, extent_size, floor, ceil;
|
|
|
|
|
|
|
|
mib[2] = i;
|
|
|
|
sz = sizeof(size_t);
|
2016-10-28 12:31:25 +08:00
|
|
|
assert_d_eq(mallctlbymib(mib, miblen, (void *)&lextent_size,
|
|
|
|
&sz, NULL, 0), 0, "Unexpected mallctlbymib failure");
|
2016-05-18 05:58:56 +08:00
|
|
|
extent_size = cache_oblivious ? lextent_size + PAGE :
|
|
|
|
lextent_size;
|
|
|
|
floor = extent_size_quantize_floor(extent_size);
|
|
|
|
ceil = extent_size_quantize_ceil(extent_size);
|
|
|
|
|
|
|
|
assert_zu_eq(extent_size, floor,
|
2016-05-30 09:34:50 +08:00
|
|
|
"Extent quantization should be a no-op for precise size "
|
|
|
|
"(lextent_size=%zu, extent_size=%zu)", lextent_size,
|
2016-05-18 05:58:56 +08:00
|
|
|
extent_size);
|
|
|
|
assert_zu_eq(extent_size, ceil,
|
2016-05-30 09:34:50 +08:00
|
|
|
"Extent quantization should be a no-op for precise size "
|
|
|
|
"(lextent_size=%zu, extent_size=%zu)", lextent_size,
|
2016-05-18 05:58:56 +08:00
|
|
|
extent_size);
|
|
|
|
|
|
|
|
if (i > 0) {
|
|
|
|
assert_zu_eq(extent_size_prev,
|
|
|
|
extent_size_quantize_floor(extent_size - PAGE),
|
|
|
|
"Floor should be a precise size");
|
|
|
|
if (extent_size_prev < ceil_prev) {
|
|
|
|
assert_zu_eq(ceil_prev, extent_size,
|
|
|
|
"Ceiling should be a precise size "
|
|
|
|
"(extent_size_prev=%zu, ceil_prev=%zu, "
|
|
|
|
"extent_size=%zu)", extent_size_prev,
|
|
|
|
ceil_prev, extent_size);
|
|
|
|
}
|
|
|
|
}
|
2016-06-01 05:50:21 +08:00
|
|
|
if (i + 1 < nlextents) {
|
2016-05-28 15:17:28 +08:00
|
|
|
extent_size_prev = floor;
|
|
|
|
ceil_prev = extent_size_quantize_ceil(extent_size +
|
|
|
|
PAGE);
|
|
|
|
}
|
2016-05-18 05:58:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
TEST_END
|
|
|
|
|
|
|
|
TEST_BEGIN(test_monotonic)
|
|
|
|
{
|
2016-05-28 15:17:28 +08:00
|
|
|
#define SZ_MAX ZU(4 * 1024 * 1024)
|
|
|
|
unsigned i;
|
|
|
|
size_t floor_prev, ceil_prev;
|
2016-05-18 05:58:56 +08:00
|
|
|
|
|
|
|
floor_prev = 0;
|
|
|
|
ceil_prev = 0;
|
2016-05-28 15:17:28 +08:00
|
|
|
for (i = 1; i <= SZ_MAX >> LG_PAGE; i++) {
|
2016-05-18 05:58:56 +08:00
|
|
|
size_t extent_size, floor, ceil;
|
|
|
|
|
|
|
|
extent_size = i << LG_PAGE;
|
|
|
|
floor = extent_size_quantize_floor(extent_size);
|
|
|
|
ceil = extent_size_quantize_ceil(extent_size);
|
|
|
|
|
|
|
|
assert_zu_le(floor, extent_size,
|
|
|
|
"Floor should be <= (floor=%zu, extent_size=%zu, ceil=%zu)",
|
|
|
|
floor, extent_size, ceil);
|
|
|
|
assert_zu_ge(ceil, extent_size,
|
|
|
|
"Ceiling should be >= (floor=%zu, extent_size=%zu, "
|
|
|
|
"ceil=%zu)", floor, extent_size, ceil);
|
|
|
|
|
|
|
|
assert_zu_le(floor_prev, floor, "Floor should be monotonic "
|
|
|
|
"(floor_prev=%zu, floor=%zu, extent_size=%zu, ceil=%zu)",
|
|
|
|
floor_prev, floor, extent_size, ceil);
|
|
|
|
assert_zu_le(ceil_prev, ceil, "Ceiling should be monotonic "
|
|
|
|
"(floor=%zu, extent_size=%zu, ceil_prev=%zu, ceil=%zu)",
|
|
|
|
floor, extent_size, ceil_prev, ceil);
|
|
|
|
|
|
|
|
floor_prev = floor;
|
|
|
|
ceil_prev = ceil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TEST_END
|
|
|
|
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
return (test(
|
|
|
|
test_small_extent_size,
|
2016-06-01 05:50:21 +08:00
|
|
|
test_large_extent_size,
|
2016-05-18 05:58:56 +08:00
|
|
|
test_monotonic));
|
|
|
|
}
|