diff options
author | Qi Wang <interwq@gwu.edu> | 2021-05-12 23:00:38 (GMT) |
---|---|---|
committer | Qi Wang <interwq@gmail.com> | 2021-05-13 23:19:14 (GMT) |
commit | 08089589f74ac23268791be18742d031cc5dd041 (patch) | |
tree | afcbb364e8d73e8129a3f909d70fba4a984ef7a1 | |
parent | 5417938215384d9373d290ba30d5dcccc5db5c80 (diff) | |
download | jemalloc-08089589f74ac23268791be18742d031cc5dd041.zip jemalloc-08089589f74ac23268791be18742d031cc5dd041.tar.gz jemalloc-08089589f74ac23268791be18742d031cc5dd041.tar.bz2 |
Fix an interaction between the oversize_threshold test and bgthds.
Also added the shared utility to check if background_thread is enabled.
-rw-r--r-- | test/include/test/bgthd.h | 17 | ||||
-rw-r--r-- | test/include/test/jemalloc_test.h.in | 1 | ||||
-rw-r--r-- | test/integration/extent.c | 16 | ||||
-rw-r--r-- | test/unit/arena_decay.c | 22 | ||||
-rw-r--r-- | test/unit/oversize_threshold.c | 6 | ||||
-rw-r--r-- | test/unit/stats.c | 2 |
6 files changed, 30 insertions, 34 deletions
diff --git a/test/include/test/bgthd.h b/test/include/test/bgthd.h new file mode 100644 index 0000000..4fa2395 --- /dev/null +++ b/test/include/test/bgthd.h @@ -0,0 +1,17 @@ +/* + * Shared utility for checking if background_thread is enabled, which affects + * the purging behavior and assumptions in some tests. + */ + +static inline bool +is_background_thread_enabled(void) { + bool enabled; + size_t sz = sizeof(bool); + int ret = mallctl("background_thread", (void *)&enabled, &sz, NULL,0); + if (ret == ENOENT) { + return false; + } + assert_d_eq(ret, 0, "Unexpected mallctl error"); + + return enabled; +} diff --git a/test/include/test/jemalloc_test.h.in b/test/include/test/jemalloc_test.h.in index ae67574..0e33216 100644 --- a/test/include/test/jemalloc_test.h.in +++ b/test/include/test/jemalloc_test.h.in @@ -128,6 +128,7 @@ static const bool config_debug = #include "test/test.h" #include "test/timer.h" #include "test/thd.h" +#include "test/bgthd.h" #define MEXP 19937 #include "test/SFMT.h" diff --git a/test/integration/extent.c b/test/integration/extent.c index ccc314d..831ef63 100644 --- a/test/integration/extent.c +++ b/test/integration/extent.c @@ -2,18 +2,6 @@ #include "test/extent_hooks.h" -static bool -check_background_thread_enabled(void) { - bool enabled; - size_t sz = sizeof(bool); - int ret = mallctl("background_thread", (void *)&enabled, &sz, NULL,0); - if (ret == ENOENT) { - return false; - } - expect_d_eq(ret, 0, "Unexpected mallctl error"); - return enabled; -} - static void test_extent_body(unsigned arena_ind) { void *p; @@ -177,7 +165,7 @@ test_manual_hook_body(void) { expect_ptr_ne(old_hooks->merge, extent_merge_hook, "Unexpected extent_hooks error"); - if (!check_background_thread_enabled()) { + if (!is_background_thread_enabled()) { test_extent_body(arena_ind); } @@ -235,7 +223,7 @@ TEST_BEGIN(test_extent_auto_hook) { expect_d_eq(mallctl("arenas.create", (void *)&arena_ind, &sz, (void *)&new_hooks, new_size), 0, "Unexpected mallctl() failure"); - test_skip_if(check_background_thread_enabled()); + test_skip_if(is_background_thread_enabled()); test_extent_body(arena_ind); } TEST_END diff --git a/test/unit/arena_decay.c b/test/unit/arena_decay.c index cea39e0..9fca538 100644 --- a/test/unit/arena_decay.c +++ b/test/unit/arena_decay.c @@ -10,18 +10,6 @@ static nstime_t time_mock; static bool monotonic_mock; static bool -check_background_thread_enabled(void) { - bool enabled; - size_t sz = sizeof(bool); - int ret = mallctl("background_thread", (void *)&enabled, &sz, NULL,0); - if (ret == ENOENT) { - return false; - } - expect_d_eq(ret, 0, "Unexpected mallctl error"); - return enabled; -} - -static bool nstime_monotonic_mock(void) { return monotonic_mock; } @@ -184,7 +172,7 @@ generate_dirty(unsigned arena_ind, size_t size) { } TEST_BEGIN(test_decay_ticks) { - test_skip_if(check_background_thread_enabled()); + test_skip_if(is_background_thread_enabled()); test_skip_if(opt_hpa); ticker_geom_t *decay_ticker; @@ -417,7 +405,7 @@ decay_ticker_helper(unsigned arena_ind, int flags, bool dirty, ssize_t dt, } TEST_BEGIN(test_decay_ticker) { - test_skip_if(check_background_thread_enabled()); + test_skip_if(is_background_thread_enabled()); test_skip_if(opt_hpa); #define NPS 2048 ssize_t ddt = opt_dirty_decay_ms; @@ -476,7 +464,7 @@ TEST_BEGIN(test_decay_ticker) { TEST_END TEST_BEGIN(test_decay_nonmonotonic) { - test_skip_if(check_background_thread_enabled()); + test_skip_if(is_background_thread_enabled()); test_skip_if(opt_hpa); #define NPS (SMOOTHSTEP_NSTEPS + 1) int flags = (MALLOCX_ARENA(0) | MALLOCX_TCACHE_NONE); @@ -534,7 +522,7 @@ TEST_BEGIN(test_decay_nonmonotonic) { TEST_END TEST_BEGIN(test_decay_now) { - test_skip_if(check_background_thread_enabled()); + test_skip_if(is_background_thread_enabled()); test_skip_if(opt_hpa); unsigned arena_ind = do_arena_create(0, 0); @@ -555,7 +543,7 @@ TEST_BEGIN(test_decay_now) { TEST_END TEST_BEGIN(test_decay_never) { - test_skip_if(check_background_thread_enabled() || !config_stats); + test_skip_if(is_background_thread_enabled() || !config_stats); test_skip_if(opt_hpa); unsigned arena_ind = do_arena_create(-1, -1); diff --git a/test/unit/oversize_threshold.c b/test/unit/oversize_threshold.c index e374b14..44a8f76 100644 --- a/test/unit/oversize_threshold.c +++ b/test/unit/oversize_threshold.c @@ -106,14 +106,16 @@ TEST_BEGIN(test_oversize_threshold) { /* Allocating and freeing half a megabyte should leave them dirty. */ void *ptr = mallocx(512 * 1024, MALLOCX_ARENA(arena)); dallocx(ptr, MALLOCX_TCACHE_NONE); - expect_zu_lt(max_purged, 512 * 1024, "Expected no 512k purge"); + if (!is_background_thread_enabled()) { + expect_zu_lt(max_purged, 512 * 1024, "Expected no 512k purge"); + } /* Purge again to reset everything out. */ arena_mallctl("arena.%u.purge", arena, NULL, NULL, NULL, 0); max_purged = 0; /* - * Allocating and freeing 2 megabytes should leave them dirty because of + * Allocating and freeing 2 megabytes should have them purged because of * the oversize threshold. */ ptr = mallocx(2 * 1024 * 1024, MALLOCX_ARENA(arena)); diff --git a/test/unit/stats.c b/test/unit/stats.c index 6b6594d..cb99b09 100644 --- a/test/unit/stats.c +++ b/test/unit/stats.c @@ -119,7 +119,7 @@ TEST_BEGIN(test_stats_arenas_summary) { "Unexepected mallctl() result"); if (config_stats) { - if (!background_thread_enabled() && !opt_hpa) { + if (!is_background_thread_enabled() && !opt_hpa) { expect_u64_gt(dirty_npurge + muzzy_npurge, 0, "At least one purge should have occurred"); } |