summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJason Evans <je@fb.com>2012-10-11 20:53:15 (GMT)
committerJason Evans <je@fb.com>2012-10-13 01:26:16 (GMT)
commit609ae595f0358157b19311b0f9f9591db7cee705 (patch)
tree2a51758c6218f26167eb8ad2155ccc925c898c3b /test
parentd0ffd8ed4f6aa4cf7248028eddfcb35f93247fe4 (diff)
downloadjemalloc-609ae595f0358157b19311b0f9f9591db7cee705.zip
jemalloc-609ae595f0358157b19311b0f9f9591db7cee705.tar.gz
jemalloc-609ae595f0358157b19311b0f9f9591db7cee705.tar.bz2
Add arena-specific and selective dss allocation.
Add the "arenas.extend" mallctl, so that it is possible to create new arenas that are outside the set that jemalloc automatically multiplexes threads onto. Add the ALLOCM_ARENA() flag for {,r,d}allocm(), so that it is possible to explicitly allocate from a particular arena. Add the "opt.dss" mallctl, which controls the default precedence of dss allocation relative to mmap allocation. Add the "arena.<i>.dss" mallctl, which makes it possible to set the default dss precedence on a per arena or global basis. Add the "arena.<i>.purge" mallctl, which obsoletes "arenas.purge". Add the "stats.arenas.<i>.dss" mallctl.
Diffstat (limited to 'test')
-rw-r--r--test/ALLOCM_ARENA.c66
-rw-r--r--test/ALLOCM_ARENA.exp2
-rw-r--r--test/thread_arena.c8
3 files changed, 73 insertions, 3 deletions
diff --git a/test/ALLOCM_ARENA.c b/test/ALLOCM_ARENA.c
new file mode 100644
index 0000000..1585690
--- /dev/null
+++ b/test/ALLOCM_ARENA.c
@@ -0,0 +1,66 @@
+#define JEMALLOC_MANGLE
+#include "jemalloc_test.h"
+
+#define NTHREADS 10
+
+void *
+je_thread_start(void *arg)
+{
+ unsigned thread_ind = (unsigned)(uintptr_t)arg;
+ unsigned arena_ind;
+ int r;
+ void *p;
+ size_t rsz, sz;
+
+ sz = sizeof(arena_ind);
+ if (mallctl("arenas.extend", &arena_ind, &sz, NULL, 0)
+ != 0) {
+ malloc_printf("Error in arenas.extend\n");
+ abort();
+ }
+
+ if (thread_ind % 4 != 3) {
+ size_t mib[3];
+ size_t miblen = sizeof(mib) / sizeof(size_t);
+ const char *dss_precs[] = {"disabled", "primary", "secondary"};
+ const char *dss = dss_precs[thread_ind % 4];
+ if (mallctlnametomib("arena.0.dss", mib, &miblen) != 0) {
+ malloc_printf("Error in mallctlnametomib()\n");
+ abort();
+ }
+ mib[1] = arena_ind;
+ if (mallctlbymib(mib, miblen, NULL, NULL, (void *)&dss,
+ sizeof(const char *))) {
+ malloc_printf("Error in mallctlbymib()\n");
+ abort();
+ }
+ }
+
+ r = allocm(&p, &rsz, 1, ALLOCM_ARENA(arena_ind));
+ if (r != ALLOCM_SUCCESS) {
+ malloc_printf("Unexpected allocm() error\n");
+ abort();
+ }
+
+ return (NULL);
+}
+
+int
+main(void)
+{
+ je_thread_t threads[NTHREADS];
+ unsigned i;
+
+ malloc_printf("Test begin\n");
+
+ for (i = 0; i < NTHREADS; i++) {
+ je_thread_create(&threads[i], je_thread_start,
+ (void *)(uintptr_t)i);
+ }
+
+ for (i = 0; i < NTHREADS; i++)
+ je_thread_join(threads[i], NULL);
+
+ malloc_printf("Test end\n");
+ return (0);
+}
diff --git a/test/ALLOCM_ARENA.exp b/test/ALLOCM_ARENA.exp
new file mode 100644
index 0000000..369a88d
--- /dev/null
+++ b/test/ALLOCM_ARENA.exp
@@ -0,0 +1,2 @@
+Test begin
+Test end
diff --git a/test/thread_arena.c b/test/thread_arena.c
index 2020d99..2ffdb5e 100644
--- a/test/thread_arena.c
+++ b/test/thread_arena.c
@@ -1,7 +1,7 @@
#define JEMALLOC_MANGLE
#include "jemalloc_test.h"
-#define NTHREADS 10
+#define NTHREADS 10
void *
je_thread_start(void *arg)
@@ -66,8 +66,10 @@ main(void)
goto label_return;
}
- for (i = 0; i < NTHREADS; i++)
- je_thread_create(&threads[i], je_thread_start, (void *)&arena_ind);
+ for (i = 0; i < NTHREADS; i++) {
+ je_thread_create(&threads[i], je_thread_start,
+ (void *)&arena_ind);
+ }
for (i = 0; i < NTHREADS; i++)
je_thread_join(threads[i], (void *)&ret);