Fix background thread index issues with max_background_threads.
This commit is contained in:
parent
e8a63b87c3
commit
312352faa8
@ -15,7 +15,12 @@ background_thread_enabled_set(tsdn_t *tsdn, bool state) {
|
|||||||
JEMALLOC_ALWAYS_INLINE background_thread_info_t *
|
JEMALLOC_ALWAYS_INLINE background_thread_info_t *
|
||||||
arena_background_thread_info_get(arena_t *arena) {
|
arena_background_thread_info_get(arena_t *arena) {
|
||||||
unsigned arena_ind = arena_ind_get(arena);
|
unsigned arena_ind = arena_ind_get(arena);
|
||||||
return &background_thread_info[arena_ind % ncpus];
|
return &background_thread_info[arena_ind % max_background_threads];
|
||||||
|
}
|
||||||
|
|
||||||
|
JEMALLOC_ALWAYS_INLINE background_thread_info_t *
|
||||||
|
background_thread_info_get(size_t ind) {
|
||||||
|
return &background_thread_info[ind % max_background_threads];
|
||||||
}
|
}
|
||||||
|
|
||||||
JEMALLOC_ALWAYS_INLINE uint64_t
|
JEMALLOC_ALWAYS_INLINE uint64_t
|
||||||
|
@ -2044,9 +2044,8 @@ arena_reset_prepare_background_thread(tsd_t *tsd, unsigned arena_ind) {
|
|||||||
if (have_background_thread) {
|
if (have_background_thread) {
|
||||||
malloc_mutex_lock(tsd_tsdn(tsd), &background_thread_lock);
|
malloc_mutex_lock(tsd_tsdn(tsd), &background_thread_lock);
|
||||||
if (background_thread_enabled()) {
|
if (background_thread_enabled()) {
|
||||||
unsigned ind = arena_ind % ncpus;
|
|
||||||
background_thread_info_t *info =
|
background_thread_info_t *info =
|
||||||
&background_thread_info[ind];
|
background_thread_info_get(arena_ind);
|
||||||
assert(info->state == background_thread_started);
|
assert(info->state == background_thread_started);
|
||||||
malloc_mutex_lock(tsd_tsdn(tsd), &info->mtx);
|
malloc_mutex_lock(tsd_tsdn(tsd), &info->mtx);
|
||||||
info->state = background_thread_paused;
|
info->state = background_thread_paused;
|
||||||
@ -2059,9 +2058,8 @@ static void
|
|||||||
arena_reset_finish_background_thread(tsd_t *tsd, unsigned arena_ind) {
|
arena_reset_finish_background_thread(tsd_t *tsd, unsigned arena_ind) {
|
||||||
if (have_background_thread) {
|
if (have_background_thread) {
|
||||||
if (background_thread_enabled()) {
|
if (background_thread_enabled()) {
|
||||||
unsigned ind = arena_ind % ncpus;
|
|
||||||
background_thread_info_t *info =
|
background_thread_info_t *info =
|
||||||
&background_thread_info[ind];
|
background_thread_info_get(arena_ind);
|
||||||
assert(info->state == background_thread_paused);
|
assert(info->state == background_thread_paused);
|
||||||
malloc_mutex_lock(tsd_tsdn(tsd), &info->mtx);
|
malloc_mutex_lock(tsd_tsdn(tsd), &info->mtx);
|
||||||
info->state = background_thread_started;
|
info->state = background_thread_started;
|
||||||
|
@ -142,7 +142,7 @@ do_arena_reset_post(void **ptrs, unsigned nptrs, unsigned arena_ind) {
|
|||||||
|
|
||||||
if (have_background_thread) {
|
if (have_background_thread) {
|
||||||
malloc_mutex_lock(tsdn,
|
malloc_mutex_lock(tsdn,
|
||||||
&background_thread_info[arena_ind % ncpus].mtx);
|
&background_thread_info_get(arena_ind)->mtx);
|
||||||
}
|
}
|
||||||
/* Verify allocations no longer exist. */
|
/* Verify allocations no longer exist. */
|
||||||
for (i = 0; i < nptrs; i++) {
|
for (i = 0; i < nptrs; i++) {
|
||||||
@ -151,7 +151,7 @@ do_arena_reset_post(void **ptrs, unsigned nptrs, unsigned arena_ind) {
|
|||||||
}
|
}
|
||||||
if (have_background_thread) {
|
if (have_background_thread) {
|
||||||
malloc_mutex_unlock(tsdn,
|
malloc_mutex_unlock(tsdn,
|
||||||
&background_thread_info[arena_ind % ncpus].mtx);
|
&background_thread_info_get(arena_ind)->mtx);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(ptrs);
|
free(ptrs);
|
||||||
|
Loading…
Reference in New Issue
Block a user