mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-05-14 00:46:21 +03:00
Cleanup cache_bin_info_t* info input args
This commit is contained in:
parent
3025b021b9
commit
e4817c8d89
8 changed files with 175 additions and 207 deletions
|
|
@ -1,19 +1,18 @@
|
|||
#include "test/jemalloc_test.h"
|
||||
|
||||
static void
|
||||
do_fill_test(cache_bin_t *bin, cache_bin_info_t *info, void **ptrs,
|
||||
cache_bin_sz_t ncached_max, cache_bin_sz_t nfill_attempt,
|
||||
cache_bin_sz_t nfill_succeed) {
|
||||
do_fill_test(cache_bin_t *bin, void **ptrs, cache_bin_sz_t ncached_max,
|
||||
cache_bin_sz_t nfill_attempt, cache_bin_sz_t nfill_succeed) {
|
||||
bool success;
|
||||
void *ptr;
|
||||
assert_true(cache_bin_ncached_get_local(bin, info) == 0, "");
|
||||
assert_true(cache_bin_ncached_get_local(bin) == 0, "");
|
||||
CACHE_BIN_PTR_ARRAY_DECLARE(arr, nfill_attempt);
|
||||
cache_bin_init_ptr_array_for_fill(bin, info, &arr, nfill_attempt);
|
||||
cache_bin_init_ptr_array_for_fill(bin, &arr, nfill_attempt);
|
||||
for (cache_bin_sz_t i = 0; i < nfill_succeed; i++) {
|
||||
arr.ptr[i] = &ptrs[i];
|
||||
}
|
||||
cache_bin_finish_fill(bin, info, &arr, nfill_succeed);
|
||||
expect_true(cache_bin_ncached_get_local(bin, info) == nfill_succeed,
|
||||
cache_bin_finish_fill(bin, &arr, nfill_succeed);
|
||||
expect_true(cache_bin_ncached_get_local(bin) == nfill_succeed,
|
||||
"");
|
||||
cache_bin_low_water_set(bin);
|
||||
|
||||
|
|
@ -22,18 +21,18 @@ do_fill_test(cache_bin_t *bin, cache_bin_info_t *info, void **ptrs,
|
|||
expect_true(success, "");
|
||||
expect_ptr_eq(ptr, (void *)&ptrs[i],
|
||||
"Should pop in order filled");
|
||||
expect_true(cache_bin_low_water_get(bin, info)
|
||||
expect_true(cache_bin_low_water_get(bin)
|
||||
== nfill_succeed - i - 1, "");
|
||||
}
|
||||
expect_true(cache_bin_ncached_get_local(bin, info) == 0, "");
|
||||
expect_true(cache_bin_low_water_get(bin, info) == 0, "");
|
||||
expect_true(cache_bin_ncached_get_local(bin) == 0, "");
|
||||
expect_true(cache_bin_low_water_get(bin) == 0, "");
|
||||
}
|
||||
|
||||
static void
|
||||
do_flush_test(cache_bin_t *bin, cache_bin_info_t *info, void **ptrs,
|
||||
cache_bin_sz_t nfill, cache_bin_sz_t nflush) {
|
||||
do_flush_test(cache_bin_t *bin, void **ptrs, cache_bin_sz_t nfill,
|
||||
cache_bin_sz_t nflush) {
|
||||
bool success;
|
||||
assert_true(cache_bin_ncached_get_local(bin, info) == 0, "");
|
||||
assert_true(cache_bin_ncached_get_local(bin) == 0, "");
|
||||
|
||||
for (cache_bin_sz_t i = 0; i < nfill; i++) {
|
||||
success = cache_bin_dalloc_easy(bin, &ptrs[i]);
|
||||
|
|
@ -41,30 +40,30 @@ do_flush_test(cache_bin_t *bin, cache_bin_info_t *info, void **ptrs,
|
|||
}
|
||||
|
||||
CACHE_BIN_PTR_ARRAY_DECLARE(arr, nflush);
|
||||
cache_bin_init_ptr_array_for_flush(bin, info, &arr, nflush);
|
||||
cache_bin_init_ptr_array_for_flush(bin, &arr, nflush);
|
||||
for (cache_bin_sz_t i = 0; i < nflush; i++) {
|
||||
expect_ptr_eq(arr.ptr[i], &ptrs[nflush - i - 1], "");
|
||||
}
|
||||
cache_bin_finish_flush(bin, info, &arr, nflush);
|
||||
cache_bin_finish_flush(bin, &arr, nflush);
|
||||
|
||||
expect_true(cache_bin_ncached_get_local(bin, info) == nfill - nflush,
|
||||
expect_true(cache_bin_ncached_get_local(bin) == nfill - nflush,
|
||||
"");
|
||||
while (cache_bin_ncached_get_local(bin, info) > 0) {
|
||||
while (cache_bin_ncached_get_local(bin) > 0) {
|
||||
cache_bin_alloc(bin, &success);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
do_batch_alloc_test(cache_bin_t *bin, cache_bin_info_t *info, void **ptrs,
|
||||
cache_bin_sz_t nfill, size_t batch) {
|
||||
assert_true(cache_bin_ncached_get_local(bin, info) == 0, "");
|
||||
do_batch_alloc_test(cache_bin_t *bin, void **ptrs, cache_bin_sz_t nfill,
|
||||
size_t batch) {
|
||||
assert_true(cache_bin_ncached_get_local(bin) == 0, "");
|
||||
CACHE_BIN_PTR_ARRAY_DECLARE(arr, nfill);
|
||||
cache_bin_init_ptr_array_for_fill(bin, info, &arr, nfill);
|
||||
cache_bin_init_ptr_array_for_fill(bin, &arr, nfill);
|
||||
for (cache_bin_sz_t i = 0; i < nfill; i++) {
|
||||
arr.ptr[i] = &ptrs[i];
|
||||
}
|
||||
cache_bin_finish_fill(bin, info, &arr, nfill);
|
||||
assert_true(cache_bin_ncached_get_local(bin, info) == nfill, "");
|
||||
cache_bin_finish_fill(bin, &arr, nfill);
|
||||
assert_true(cache_bin_ncached_get_local(bin) == nfill, "");
|
||||
cache_bin_low_water_set(bin);
|
||||
|
||||
void **out = malloc((batch + 1) * sizeof(void *));
|
||||
|
|
@ -73,9 +72,9 @@ do_batch_alloc_test(cache_bin_t *bin, cache_bin_info_t *info, void **ptrs,
|
|||
for (cache_bin_sz_t i = 0; i < (cache_bin_sz_t)n; i++) {
|
||||
expect_ptr_eq(out[i], &ptrs[i], "");
|
||||
}
|
||||
expect_true(cache_bin_low_water_get(bin, info) == nfill -
|
||||
expect_true(cache_bin_low_water_get(bin) == nfill -
|
||||
(cache_bin_sz_t)n, "");
|
||||
while (cache_bin_ncached_get_local(bin, info) > 0) {
|
||||
while (cache_bin_ncached_get_local(bin) > 0) {
|
||||
bool success;
|
||||
cache_bin_alloc(bin, &success);
|
||||
}
|
||||
|
|
@ -106,13 +105,11 @@ TEST_BEGIN(test_cache_bin) {
|
|||
cache_bin_info_init(&info, ncached_max);
|
||||
cache_bin_t bin;
|
||||
test_bin_init(&bin, &info);
|
||||
cache_bin_info_t *bin_info = &bin.bin_info;
|
||||
|
||||
/* Initialize to empty; should then have 0 elements. */
|
||||
expect_d_eq(ncached_max, cache_bin_info_ncached_max_get(&bin,
|
||||
&bin.bin_info), "");
|
||||
expect_true(cache_bin_ncached_get_local(&bin, bin_info) == 0, "");
|
||||
expect_true(cache_bin_low_water_get(&bin, bin_info) == 0, "");
|
||||
expect_d_eq(ncached_max, cache_bin_ncached_max_get(&bin), "");
|
||||
expect_true(cache_bin_ncached_get_local(&bin) == 0, "");
|
||||
expect_true(cache_bin_low_water_get(&bin) == 0, "");
|
||||
|
||||
ptr = cache_bin_alloc_easy(&bin, &success);
|
||||
expect_false(success, "Shouldn't successfully allocate when empty");
|
||||
|
|
@ -129,14 +126,14 @@ TEST_BEGIN(test_cache_bin) {
|
|||
void **ptrs = mallocx(sizeof(void *) * (ncached_max + 1), 0);
|
||||
assert_ptr_not_null(ptrs, "Unexpected mallocx failure");
|
||||
for (cache_bin_sz_t i = 0; i < ncached_max; i++) {
|
||||
expect_true(cache_bin_ncached_get_local(&bin, bin_info) == i, "");
|
||||
expect_true(cache_bin_ncached_get_local(&bin) == i, "");
|
||||
success = cache_bin_dalloc_easy(&bin, &ptrs[i]);
|
||||
expect_true(success,
|
||||
"Should be able to dalloc into a non-full cache bin.");
|
||||
expect_true(cache_bin_low_water_get(&bin, bin_info) == 0,
|
||||
expect_true(cache_bin_low_water_get(&bin) == 0,
|
||||
"Pushes and pops shouldn't change low water of zero.");
|
||||
}
|
||||
expect_true(cache_bin_ncached_get_local(&bin, bin_info) == ncached_max,
|
||||
expect_true(cache_bin_ncached_get_local(&bin) == ncached_max,
|
||||
"");
|
||||
success = cache_bin_dalloc_easy(&bin, &ptrs[ncached_max]);
|
||||
expect_false(success, "Shouldn't be able to dalloc into a full bin.");
|
||||
|
|
@ -144,9 +141,9 @@ TEST_BEGIN(test_cache_bin) {
|
|||
cache_bin_low_water_set(&bin);
|
||||
|
||||
for (cache_bin_sz_t i = 0; i < ncached_max; i++) {
|
||||
expect_true(cache_bin_low_water_get(&bin, bin_info)
|
||||
expect_true(cache_bin_low_water_get(&bin)
|
||||
== ncached_max - i, "");
|
||||
expect_true(cache_bin_ncached_get_local(&bin, bin_info)
|
||||
expect_true(cache_bin_ncached_get_local(&bin)
|
||||
== ncached_max - i, "");
|
||||
/*
|
||||
* This should fail -- the easy variant can't change the low
|
||||
|
|
@ -155,9 +152,9 @@ TEST_BEGIN(test_cache_bin) {
|
|||
ptr = cache_bin_alloc_easy(&bin, &success);
|
||||
expect_ptr_null(ptr, "");
|
||||
expect_false(success, "");
|
||||
expect_true(cache_bin_low_water_get(&bin, bin_info)
|
||||
expect_true(cache_bin_low_water_get(&bin)
|
||||
== ncached_max - i, "");
|
||||
expect_true(cache_bin_ncached_get_local(&bin, bin_info)
|
||||
expect_true(cache_bin_ncached_get_local(&bin)
|
||||
== ncached_max - i, "");
|
||||
|
||||
/* This should succeed, though. */
|
||||
|
|
@ -165,13 +162,13 @@ TEST_BEGIN(test_cache_bin) {
|
|||
expect_true(success, "");
|
||||
expect_ptr_eq(ptr, &ptrs[ncached_max - i - 1],
|
||||
"Alloc should pop in stack order");
|
||||
expect_true(cache_bin_low_water_get(&bin, bin_info)
|
||||
expect_true(cache_bin_low_water_get(&bin)
|
||||
== ncached_max - i - 1, "");
|
||||
expect_true(cache_bin_ncached_get_local(&bin, bin_info)
|
||||
expect_true(cache_bin_ncached_get_local(&bin)
|
||||
== ncached_max - i - 1, "");
|
||||
}
|
||||
/* Now we're empty -- all alloc attempts should fail. */
|
||||
expect_true(cache_bin_ncached_get_local(&bin, bin_info) == 0, "");
|
||||
expect_true(cache_bin_ncached_get_local(&bin) == 0, "");
|
||||
ptr = cache_bin_alloc_easy(&bin, &success);
|
||||
expect_ptr_null(ptr, "");
|
||||
expect_false(success, "");
|
||||
|
|
@ -187,7 +184,7 @@ TEST_BEGIN(test_cache_bin) {
|
|||
for (cache_bin_sz_t i = ncached_max / 2; i < ncached_max; i++) {
|
||||
cache_bin_dalloc_easy(&bin, &ptrs[i]);
|
||||
}
|
||||
expect_true(cache_bin_ncached_get_local(&bin, bin_info) == ncached_max,
|
||||
expect_true(cache_bin_ncached_get_local(&bin) == ncached_max,
|
||||
"");
|
||||
for (cache_bin_sz_t i = ncached_max - 1; i >= ncached_max / 2; i--) {
|
||||
/*
|
||||
|
|
@ -204,77 +201,72 @@ TEST_BEGIN(test_cache_bin) {
|
|||
expect_ptr_null(ptr, "");
|
||||
|
||||
/* We're going to test filling -- we must be empty to start. */
|
||||
while (cache_bin_ncached_get_local(&bin, bin_info)) {
|
||||
while (cache_bin_ncached_get_local(&bin)) {
|
||||
cache_bin_alloc(&bin, &success);
|
||||
expect_true(success, "");
|
||||
}
|
||||
|
||||
/* Test fill. */
|
||||
/* Try to fill all, succeed fully. */
|
||||
do_fill_test(&bin, bin_info, ptrs, ncached_max, ncached_max,
|
||||
do_fill_test(&bin, ptrs, ncached_max, ncached_max,
|
||||
ncached_max);
|
||||
/* Try to fill all, succeed partially. */
|
||||
do_fill_test(&bin, bin_info, ptrs, ncached_max, ncached_max,
|
||||
do_fill_test(&bin, ptrs, ncached_max, ncached_max,
|
||||
ncached_max / 2);
|
||||
/* Try to fill all, fail completely. */
|
||||
do_fill_test(&bin, bin_info, ptrs, ncached_max, ncached_max, 0);
|
||||
do_fill_test(&bin, ptrs, ncached_max, ncached_max, 0);
|
||||
|
||||
/* Try to fill some, succeed fully. */
|
||||
do_fill_test(&bin, bin_info, ptrs, ncached_max, ncached_max / 2,
|
||||
do_fill_test(&bin, ptrs, ncached_max, ncached_max / 2,
|
||||
ncached_max / 2);
|
||||
/* Try to fill some, succeed partially. */
|
||||
do_fill_test(&bin, bin_info, ptrs, ncached_max, ncached_max / 2,
|
||||
do_fill_test(&bin, ptrs, ncached_max, ncached_max / 2,
|
||||
ncached_max / 4);
|
||||
/* Try to fill some, fail completely. */
|
||||
do_fill_test(&bin, bin_info, ptrs, ncached_max, ncached_max / 2, 0);
|
||||
do_fill_test(&bin, ptrs, ncached_max, ncached_max / 2, 0);
|
||||
|
||||
do_flush_test(&bin, bin_info, ptrs, ncached_max, ncached_max);
|
||||
do_flush_test(&bin, bin_info, ptrs, ncached_max, ncached_max / 2);
|
||||
do_flush_test(&bin, bin_info, ptrs, ncached_max, 0);
|
||||
do_flush_test(&bin, bin_info, ptrs, ncached_max / 2, ncached_max / 2);
|
||||
do_flush_test(&bin, bin_info, ptrs, ncached_max / 2, ncached_max / 4);
|
||||
do_flush_test(&bin, bin_info, ptrs, ncached_max / 2, 0);
|
||||
do_flush_test(&bin, ptrs, ncached_max, ncached_max);
|
||||
do_flush_test(&bin, ptrs, ncached_max, ncached_max / 2);
|
||||
do_flush_test(&bin, ptrs, ncached_max, 0);
|
||||
do_flush_test(&bin, ptrs, ncached_max / 2, ncached_max / 2);
|
||||
do_flush_test(&bin, ptrs, ncached_max / 2, ncached_max / 4);
|
||||
do_flush_test(&bin, ptrs, ncached_max / 2, 0);
|
||||
|
||||
do_batch_alloc_test(&bin, bin_info, ptrs, ncached_max, ncached_max);
|
||||
do_batch_alloc_test(&bin, bin_info, ptrs, ncached_max,
|
||||
ncached_max * 2);
|
||||
do_batch_alloc_test(&bin, bin_info, ptrs, ncached_max,
|
||||
ncached_max / 2);
|
||||
do_batch_alloc_test(&bin, bin_info, ptrs, ncached_max, 2);
|
||||
do_batch_alloc_test(&bin, bin_info, ptrs, ncached_max, 1);
|
||||
do_batch_alloc_test(&bin, bin_info, ptrs, ncached_max, 0);
|
||||
do_batch_alloc_test(&bin, bin_info, ptrs, ncached_max / 2,
|
||||
ncached_max / 2);
|
||||
do_batch_alloc_test(&bin, bin_info, ptrs, ncached_max / 2,
|
||||
ncached_max);
|
||||
do_batch_alloc_test(&bin, bin_info, ptrs, ncached_max / 2,
|
||||
ncached_max / 4);
|
||||
do_batch_alloc_test(&bin, bin_info, ptrs, ncached_max / 2, 2);
|
||||
do_batch_alloc_test(&bin, bin_info, ptrs, ncached_max / 2, 1);
|
||||
do_batch_alloc_test(&bin, bin_info, ptrs, ncached_max / 2, 0);
|
||||
do_batch_alloc_test(&bin, bin_info, ptrs, 2, ncached_max);
|
||||
do_batch_alloc_test(&bin, bin_info, ptrs, 2, 2);
|
||||
do_batch_alloc_test(&bin, bin_info, ptrs, 2, 1);
|
||||
do_batch_alloc_test(&bin, bin_info, ptrs, 2, 0);
|
||||
do_batch_alloc_test(&bin, bin_info, ptrs, 1, 2);
|
||||
do_batch_alloc_test(&bin, bin_info, ptrs, 1, 1);
|
||||
do_batch_alloc_test(&bin, bin_info, ptrs, 1, 0);
|
||||
do_batch_alloc_test(&bin, bin_info, ptrs, 0, 2);
|
||||
do_batch_alloc_test(&bin, bin_info, ptrs, 0, 1);
|
||||
do_batch_alloc_test(&bin, bin_info, ptrs, 0, 0);
|
||||
do_batch_alloc_test(&bin, ptrs, ncached_max, ncached_max);
|
||||
do_batch_alloc_test(&bin, ptrs, ncached_max, ncached_max * 2);
|
||||
do_batch_alloc_test(&bin, ptrs, ncached_max, ncached_max / 2);
|
||||
do_batch_alloc_test(&bin, ptrs, ncached_max, 2);
|
||||
do_batch_alloc_test(&bin, ptrs, ncached_max, 1);
|
||||
do_batch_alloc_test(&bin, ptrs, ncached_max, 0);
|
||||
do_batch_alloc_test(&bin, ptrs, ncached_max / 2, ncached_max / 2);
|
||||
do_batch_alloc_test(&bin, ptrs, ncached_max / 2, ncached_max);
|
||||
do_batch_alloc_test(&bin, ptrs, ncached_max / 2, ncached_max / 4);
|
||||
do_batch_alloc_test(&bin, ptrs, ncached_max / 2, 2);
|
||||
do_batch_alloc_test(&bin, ptrs, ncached_max / 2, 1);
|
||||
do_batch_alloc_test(&bin, ptrs, ncached_max / 2, 0);
|
||||
do_batch_alloc_test(&bin, ptrs, 2, ncached_max);
|
||||
do_batch_alloc_test(&bin, ptrs, 2, 2);
|
||||
do_batch_alloc_test(&bin, ptrs, 2, 1);
|
||||
do_batch_alloc_test(&bin, ptrs, 2, 0);
|
||||
do_batch_alloc_test(&bin, ptrs, 1, 2);
|
||||
do_batch_alloc_test(&bin, ptrs, 1, 1);
|
||||
do_batch_alloc_test(&bin, ptrs, 1, 0);
|
||||
do_batch_alloc_test(&bin, ptrs, 0, 2);
|
||||
do_batch_alloc_test(&bin, ptrs, 0, 1);
|
||||
do_batch_alloc_test(&bin, ptrs, 0, 0);
|
||||
|
||||
free(ptrs);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
static void
|
||||
do_flush_stashed_test(cache_bin_t *bin, cache_bin_info_t *info, void **ptrs,
|
||||
cache_bin_sz_t nfill, cache_bin_sz_t nstash) {
|
||||
expect_true(cache_bin_ncached_get_local(bin, info) == 0,
|
||||
do_flush_stashed_test(cache_bin_t *bin, void **ptrs, cache_bin_sz_t nfill,
|
||||
cache_bin_sz_t nstash) {
|
||||
expect_true(cache_bin_ncached_get_local(bin) == 0,
|
||||
"Bin not empty");
|
||||
expect_true(cache_bin_nstashed_get_local(bin, info) == 0,
|
||||
expect_true(cache_bin_nstashed_get_local(bin) == 0,
|
||||
"Bin not empty");
|
||||
expect_true(nfill + nstash <= info->ncached_max, "Exceeded max");
|
||||
expect_true(nfill + nstash <= bin->bin_info.ncached_max, "Exceeded max");
|
||||
|
||||
bool ret;
|
||||
/* Fill */
|
||||
|
|
@ -282,7 +274,7 @@ do_flush_stashed_test(cache_bin_t *bin, cache_bin_info_t *info, void **ptrs,
|
|||
ret = cache_bin_dalloc_easy(bin, &ptrs[i]);
|
||||
expect_true(ret, "Unexpected fill failure");
|
||||
}
|
||||
expect_true(cache_bin_ncached_get_local(bin, info) == nfill,
|
||||
expect_true(cache_bin_ncached_get_local(bin) == nfill,
|
||||
"Wrong cached count");
|
||||
|
||||
/* Stash */
|
||||
|
|
@ -290,10 +282,10 @@ do_flush_stashed_test(cache_bin_t *bin, cache_bin_info_t *info, void **ptrs,
|
|||
ret = cache_bin_stash(bin, &ptrs[i + nfill]);
|
||||
expect_true(ret, "Unexpected stash failure");
|
||||
}
|
||||
expect_true(cache_bin_nstashed_get_local(bin, info) == nstash,
|
||||
expect_true(cache_bin_nstashed_get_local(bin) == nstash,
|
||||
"Wrong stashed count");
|
||||
|
||||
if (nfill + nstash == info->ncached_max) {
|
||||
if (nfill + nstash == bin->bin_info.ncached_max) {
|
||||
ret = cache_bin_dalloc_easy(bin, &ptrs[0]);
|
||||
expect_false(ret, "Should not dalloc into a full bin");
|
||||
ret = cache_bin_stash(bin, &ptrs[0]);
|
||||
|
|
@ -308,19 +300,19 @@ do_flush_stashed_test(cache_bin_t *bin, cache_bin_info_t *info, void **ptrs,
|
|||
expect_true((uintptr_t)ptr < (uintptr_t)&ptrs[nfill],
|
||||
"Should not alloc stashed ptrs");
|
||||
}
|
||||
expect_true(cache_bin_ncached_get_local(bin, info) == 0,
|
||||
expect_true(cache_bin_ncached_get_local(bin) == 0,
|
||||
"Wrong cached count");
|
||||
expect_true(cache_bin_nstashed_get_local(bin, info) == nstash,
|
||||
expect_true(cache_bin_nstashed_get_local(bin) == nstash,
|
||||
"Wrong stashed count");
|
||||
|
||||
cache_bin_alloc(bin, &ret);
|
||||
expect_false(ret, "Should not alloc stashed");
|
||||
|
||||
/* Clear stashed ones */
|
||||
cache_bin_finish_flush_stashed(bin, info);
|
||||
expect_true(cache_bin_ncached_get_local(bin, info) == 0,
|
||||
cache_bin_finish_flush_stashed(bin);
|
||||
expect_true(cache_bin_ncached_get_local(bin) == 0,
|
||||
"Wrong cached count");
|
||||
expect_true(cache_bin_nstashed_get_local(bin, info) == 0,
|
||||
expect_true(cache_bin_nstashed_get_local(bin) == 0,
|
||||
"Wrong stashed count");
|
||||
|
||||
cache_bin_alloc(bin, &ret);
|
||||
|
|
@ -334,7 +326,6 @@ TEST_BEGIN(test_cache_bin_stash) {
|
|||
cache_bin_info_t info;
|
||||
cache_bin_info_init(&info, ncached_max);
|
||||
test_bin_init(&bin, &info);
|
||||
cache_bin_info_t *bin_info = &bin.bin_info;
|
||||
|
||||
/*
|
||||
* The content of this array is not accessed; instead the interior
|
||||
|
|
@ -344,9 +335,9 @@ TEST_BEGIN(test_cache_bin_stash) {
|
|||
assert_ptr_not_null(ptrs, "Unexpected mallocx failure");
|
||||
bool ret;
|
||||
for (cache_bin_sz_t i = 0; i < ncached_max; i++) {
|
||||
expect_true(cache_bin_ncached_get_local(&bin, bin_info) ==
|
||||
expect_true(cache_bin_ncached_get_local(&bin) ==
|
||||
(i / 2 + i % 2), "Wrong ncached value");
|
||||
expect_true(cache_bin_nstashed_get_local(&bin, bin_info) ==
|
||||
expect_true(cache_bin_nstashed_get_local(&bin) ==
|
||||
i / 2, "Wrong nstashed value");
|
||||
if (i % 2 == 0) {
|
||||
cache_bin_dalloc_easy(&bin, &ptrs[i]);
|
||||
|
|
@ -369,22 +360,21 @@ TEST_BEGIN(test_cache_bin_stash) {
|
|||
expect_true(diff % 2 == 0, "Should be able to alloc");
|
||||
} else {
|
||||
expect_false(ret, "Should not alloc stashed");
|
||||
expect_true(cache_bin_nstashed_get_local(&bin,
|
||||
bin_info) == ncached_max / 2,
|
||||
expect_true(cache_bin_nstashed_get_local(&bin) == ncached_max / 2,
|
||||
"Wrong nstashed value");
|
||||
}
|
||||
}
|
||||
|
||||
test_bin_init(&bin, &info);
|
||||
do_flush_stashed_test(&bin, bin_info, ptrs, ncached_max, 0);
|
||||
do_flush_stashed_test(&bin, bin_info, ptrs, 0, ncached_max);
|
||||
do_flush_stashed_test(&bin, bin_info, ptrs, ncached_max / 2,
|
||||
do_flush_stashed_test(&bin, ptrs, ncached_max, 0);
|
||||
do_flush_stashed_test(&bin, ptrs, 0, ncached_max);
|
||||
do_flush_stashed_test(&bin, ptrs, ncached_max / 2,
|
||||
ncached_max / 2);
|
||||
do_flush_stashed_test(&bin, bin_info, ptrs, ncached_max / 4,
|
||||
do_flush_stashed_test(&bin, ptrs, ncached_max / 4,
|
||||
ncached_max / 2);
|
||||
do_flush_stashed_test(&bin, bin_info, ptrs, ncached_max / 2,
|
||||
do_flush_stashed_test(&bin, ptrs, ncached_max / 2,
|
||||
ncached_max / 4);
|
||||
do_flush_stashed_test(&bin, bin_info, ptrs, ncached_max / 4,
|
||||
do_flush_stashed_test(&bin, ptrs, ncached_max / 4,
|
||||
ncached_max / 4);
|
||||
}
|
||||
TEST_END
|
||||
|
|
|
|||
|
|
@ -81,8 +81,7 @@ tcache_bytes_read_local(void) {
|
|||
if (tcache_bin_disabled(i, cache_bin, tcache->tcache_slow)) {
|
||||
continue;
|
||||
}
|
||||
cache_bin_sz_t ncached = cache_bin_ncached_get_local(cache_bin,
|
||||
&cache_bin->bin_info);
|
||||
cache_bin_sz_t ncached = cache_bin_ncached_get_local(cache_bin);
|
||||
tcache_bytes += ncached * sz_index2size(i);
|
||||
}
|
||||
return tcache_bytes;
|
||||
|
|
@ -370,4 +369,3 @@ main(void) {
|
|||
test_tcache_max,
|
||||
test_thread_tcache_max);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue