diff options
author | Jason Evans <je@fb.com> | 2011-03-18 20:41:33 (GMT) |
---|---|---|
committer | Jason Evans <je@fb.com> | 2011-03-18 20:41:33 (GMT) |
commit | 597632be188d2bcc135dad2145cc46ef44897aad (patch) | |
tree | fb092c04978ccd91b7e12fbd3259ffbb47c7d6a4 /jemalloc/include | |
parent | 9c43c13a35220c10d97a886616899189daceb359 (diff) | |
download | jemalloc-597632be188d2bcc135dad2145cc46ef44897aad.zip jemalloc-597632be188d2bcc135dad2145cc46ef44897aad.tar.gz jemalloc-597632be188d2bcc135dad2145cc46ef44897aad.tar.bz2 |
Improve thread-->arena assignment.
Rather than blindly assigning threads to arenas in round-robin fashion,
choose the lowest-numbered arena that currently has the smallest number
of threads assigned to it.
Add the "stats.arenas.<i>.nthreads" mallctl.
Diffstat (limited to 'jemalloc/include')
-rw-r--r-- | jemalloc/include/jemalloc/internal/arena.h | 14 | ||||
-rw-r--r-- | jemalloc/include/jemalloc/internal/ctl.h | 1 | ||||
-rw-r--r-- | jemalloc/include/jemalloc/internal/jemalloc_internal.h.in | 3 |
3 files changed, 15 insertions, 3 deletions
diff --git a/jemalloc/include/jemalloc/internal/arena.h b/jemalloc/include/jemalloc/internal/arena.h index 1744b45..94b7f3d 100644 --- a/jemalloc/include/jemalloc/internal/arena.h +++ b/jemalloc/include/jemalloc/internal/arena.h @@ -295,8 +295,18 @@ struct arena_s { unsigned ind; /* - * All non-bin-related operations on this arena require that lock be - * locked. + * Number of threads currently assigned to this arena. This field is + * protected by arenas_lock. + */ + unsigned nthreads; + + /* + * There are three classes of arena operations from a locking + * perspective: + * 1) Thread asssignment (modifies nthreads) is protected by + * arenas_lock. + * 2) Bin-related operations are protected by bin locks. + * 3) Chunk- and run-related operations are protected by this mutex. */ malloc_mutex_t lock; diff --git a/jemalloc/include/jemalloc/internal/ctl.h b/jemalloc/include/jemalloc/internal/ctl.h index 8776ad1..f1f5eb7 100644 --- a/jemalloc/include/jemalloc/internal/ctl.h +++ b/jemalloc/include/jemalloc/internal/ctl.h @@ -29,6 +29,7 @@ struct ctl_node_s { struct ctl_arena_stats_s { bool initialized; + unsigned nthreads; size_t pactive; size_t pdirty; #ifdef JEMALLOC_STATS diff --git a/jemalloc/include/jemalloc/internal/jemalloc_internal.h.in b/jemalloc/include/jemalloc/internal/jemalloc_internal.h.in index a80fc7c..a7472c0 100644 --- a/jemalloc/include/jemalloc/internal/jemalloc_internal.h.in +++ b/jemalloc/include/jemalloc/internal/jemalloc_internal.h.in @@ -293,6 +293,7 @@ extern size_t lg_pagesize; extern unsigned ncpus; extern malloc_mutex_t arenas_lock; /* Protects arenas initialization. */ +extern pthread_key_t arenas_tsd; #ifndef NO_TLS /* * Map of pthread_self() --> arenas[???], used for selecting an arena to use @@ -302,9 +303,9 @@ extern __thread arena_t *arenas_tls JEMALLOC_ATTR(tls_model("initial-exec")); # define ARENA_GET() arenas_tls # define ARENA_SET(v) do { \ arenas_tls = (v); \ + pthread_setspecific(arenas_tsd, (void *)(v)); \ } while (0) #else -extern pthread_key_t arenas_tsd; # define ARENA_GET() ((arena_t *)pthread_getspecific(arenas_tsd)) # define ARENA_SET(v) do { \ pthread_setspecific(arenas_tsd, (void *)(v)); \ |