diff options
author | Qi Wang <interwq@gwu.edu> | 2017-02-03 01:02:05 (GMT) |
---|---|---|
committer | Qi Wang <interwq@gmail.com> | 2017-03-09 07:19:01 (GMT) |
commit | ec532e2c5c0b25fb7ab09383fe5a274583a90def (patch) | |
tree | b3306921b534baa43b1bb698d086041226d64d6e /test/integration | |
parent | 8721e19c0414dce0f47a627ff948130d4294b4d7 (diff) | |
download | jemalloc-ec532e2c5c0b25fb7ab09383fe5a274583a90def.zip jemalloc-ec532e2c5c0b25fb7ab09383fe5a274583a90def.tar.gz jemalloc-ec532e2c5c0b25fb7ab09383fe5a274583a90def.tar.bz2 |
Implement per-CPU arena.
The new feature, opt.percpu_arena, determines thread-arena association
dynamically based CPU id. Three modes are supported: "percpu", "phycpu"
and disabled.
"percpu" uses the current core id (with help from sched_getcpu())
directly as the arena index, while "phycpu" will assign threads on the
same physical CPU to the same arena. In other words, "percpu" means # of
arenas == # of CPUs, while "phycpu" has # of arenas == 1/2 * (# of
CPUs). Note that no runtime check on whether hyper threading is enabled
is added yet.
When enabled, threads will be migrated between arenas when a CPU change
is detected. In the current design, to reduce overhead from reading CPU
id, each arena tracks the thread accessed most recently. When a new
thread comes in, we will read CPU id and update arena if necessary.
Diffstat (limited to 'test/integration')
-rw-r--r-- | test/integration/thread_arena.c | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/test/integration/thread_arena.c b/test/integration/thread_arena.c index 9991a42..1e5ec05 100644 --- a/test/integration/thread_arena.c +++ b/test/integration/thread_arena.c @@ -37,10 +37,16 @@ thd_start(void *arg) { return NULL; } +static void +mallctl_failure(int err) { + char buf[BUFERROR_BUF]; + + buferror(err, buf, sizeof(buf)); + test_fail("Error in mallctl(): %s", buf); +} + TEST_BEGIN(test_thread_arena) { void *p; - unsigned arena_ind; - size_t size; int err; thd_t thds[NTHREADS]; unsigned i; @@ -48,13 +54,15 @@ TEST_BEGIN(test_thread_arena) { p = malloc(1); assert_ptr_not_null(p, "Error in malloc()"); - size = sizeof(arena_ind); - if ((err = mallctl("thread.arena", (void *)&arena_ind, &size, NULL, - 0))) { - char buf[BUFERROR_BUF]; + unsigned arena_ind, old_arena_ind; + size_t sz = sizeof(unsigned); + assert_d_eq(mallctl("arenas.create", (void *)&arena_ind, &sz, NULL, 0), + 0, "Arena creation failure"); - buferror(err, buf, sizeof(buf)); - test_fail("Error in mallctl(): %s", buf); + size_t size = sizeof(arena_ind); + if ((err = mallctl("thread.arena", (void *)&old_arena_ind, &size, + (void *)&arena_ind, sizeof(arena_ind))) != 0) { + mallctl_failure(err); } for (i = 0; i < NTHREADS; i++) { @@ -67,6 +75,7 @@ TEST_BEGIN(test_thread_arena) { thd_join(thds[i], (void *)&join_ret); assert_zd_eq(join_ret, 0, "Unexpected thread join error"); } + free(p); } TEST_END |