Implementing opt.background_thread.
Added opt.background_thread to enable background threads, which handles purging currently. When enabled, decay ticks will not trigger purging (which will be left to the background threads). We limit the max number of threads to NCPUs. When percpu arena is enabled, set CPU affinity for the background threads as well. The sleep interval of background threads is dynamic and determined by computing number of pages to purge in the future (based on backlog).
This commit is contained in:
@@ -9,6 +9,18 @@ static unsigned nupdates_mock;
|
||||
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;
|
||||
}
|
||||
assert_d_eq(ret, 0, "Unexpected mallctl error");
|
||||
return enabled;
|
||||
}
|
||||
|
||||
static bool
|
||||
nstime_monotonic_mock(void) {
|
||||
return monotonic_mock;
|
||||
@@ -167,6 +179,8 @@ generate_dirty(unsigned arena_ind, size_t size) {
|
||||
}
|
||||
|
||||
TEST_BEGIN(test_decay_ticks) {
|
||||
test_skip_if(check_background_thread_enabled());
|
||||
|
||||
ticker_t *decay_ticker;
|
||||
unsigned tick0, tick1, arena_ind;
|
||||
size_t sz, large0;
|
||||
@@ -405,6 +419,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());
|
||||
#define NPS 2048
|
||||
ssize_t ddt = opt_dirty_decay_ms;
|
||||
ssize_t mdt = opt_muzzy_decay_ms;
|
||||
@@ -466,6 +481,7 @@ TEST_BEGIN(test_decay_ticker) {
|
||||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_decay_nonmonotonic) {
|
||||
test_skip_if(check_background_thread_enabled());
|
||||
#define NPS (SMOOTHSTEP_NSTEPS + 1)
|
||||
int flags = (MALLOCX_ARENA(0) | MALLOCX_TCACHE_NONE);
|
||||
void *ps[NPS];
|
||||
@@ -523,6 +539,8 @@ TEST_BEGIN(test_decay_nonmonotonic) {
|
||||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_decay_now) {
|
||||
test_skip_if(check_background_thread_enabled());
|
||||
|
||||
unsigned arena_ind = do_arena_create(0, 0);
|
||||
assert_zu_eq(get_arena_pdirty(arena_ind), 0, "Unexpected dirty pages");
|
||||
assert_zu_eq(get_arena_pmuzzy(arena_ind), 0, "Unexpected muzzy pages");
|
||||
@@ -541,6 +559,8 @@ TEST_BEGIN(test_decay_now) {
|
||||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_decay_never) {
|
||||
test_skip_if(check_background_thread_enabled());
|
||||
|
||||
unsigned arena_ind = do_arena_create(-1, -1);
|
||||
int flags = MALLOCX_ARENA(arena_ind) | MALLOCX_TCACHE_NONE;
|
||||
assert_zu_eq(get_arena_pdirty(arena_ind), 0, "Unexpected dirty pages");
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#include "test/jemalloc_test.h"
|
||||
|
||||
static const uint64_t smoothstep_tab[] = {
|
||||
#define STEP(step, h, x, y) \
|
||||
#define STEP(step, h, x, y, h_sum) \
|
||||
h,
|
||||
SMOOTHSTEP
|
||||
#undef STEP
|
||||
|
@@ -115,8 +115,10 @@ TEST_BEGIN(test_stats_arenas_summary) {
|
||||
"Unexepected mallctl() result");
|
||||
|
||||
if (config_stats) {
|
||||
assert_u64_gt(dirty_npurge + muzzy_npurge, 0,
|
||||
"At least one purge should have occurred");
|
||||
if (!background_thread_enabled()) {
|
||||
assert_u64_gt(dirty_npurge + muzzy_npurge, 0,
|
||||
"At least one purge should have occurred");
|
||||
}
|
||||
assert_u64_le(dirty_nmadvise, dirty_purged,
|
||||
"dirty_nmadvise should be no greater than dirty_purged");
|
||||
assert_u64_le(muzzy_nmadvise, muzzy_purged,
|
||||
|
Reference in New Issue
Block a user