aboutsummaryrefslogtreecommitdiffstats
path: root/include/jemalloc/internal
diff options
context:
space:
mode:
authorQi Wang <interwq@gwu.edu>2017-05-22 15:26:25 -0700
committerQi Wang <interwq@gmail.com>2017-05-23 12:26:20 -0700
commit0eae838b0d4343b09d80dee00f20a39ce709ca8f (patch)
tree65aae1c84a45b485b9a8d10e90c57f5b27bb0d71 /include/jemalloc/internal
parent2c368284d2485bda47002f22dace6c0b55e4701e (diff)
downloadplatform_external_jemalloc_new-0eae838b0d4343b09d80dee00f20a39ce709ca8f.tar.gz
platform_external_jemalloc_new-0eae838b0d4343b09d80dee00f20a39ce709ca8f.tar.bz2
platform_external_jemalloc_new-0eae838b0d4343b09d80dee00f20a39ce709ca8f.zip
Check for background thread inactivity on extents_dalloc.
To avoid background threads sleeping forever with idle arenas, we eagerly check background threads' sleep time after extents_dalloc, and signal the thread if necessary.
Diffstat (limited to 'include/jemalloc/internal')
-rw-r--r--include/jemalloc/internal/background_thread_inlines.h35
-rw-r--r--include/jemalloc/internal/background_thread_structs.h14
2 files changed, 45 insertions, 4 deletions
diff --git a/include/jemalloc/internal/background_thread_inlines.h b/include/jemalloc/internal/background_thread_inlines.h
index 2709ae31..fd5095f2 100644
--- a/include/jemalloc/internal/background_thread_inlines.h
+++ b/include/jemalloc/internal/background_thread_inlines.h
@@ -18,4 +18,39 @@ arena_background_thread_info_get(arena_t *arena) {
return &background_thread_info[arena_ind % ncpus];
}
+JEMALLOC_ALWAYS_INLINE uint64_t
+background_thread_wakeup_time_get(background_thread_info_t *info) {
+ uint64_t next_wakeup = nstime_ns(&info->next_wakeup);
+ assert(atomic_load_b(&info->indefinite_sleep, ATOMIC_ACQUIRE) ==
+ (next_wakeup == BACKGROUND_THREAD_INDEFINITE_SLEEP));
+ return next_wakeup;
+}
+
+JEMALLOC_ALWAYS_INLINE void
+background_thread_wakeup_time_set(tsdn_t *tsdn, background_thread_info_t *info,
+ uint64_t wakeup_time) {
+ malloc_mutex_assert_owner(tsdn, &info->mtx);
+ atomic_store_b(&info->indefinite_sleep,
+ wakeup_time == BACKGROUND_THREAD_INDEFINITE_SLEEP, ATOMIC_RELEASE);
+ nstime_init(&info->next_wakeup, wakeup_time);
+}
+
+JEMALLOC_ALWAYS_INLINE bool
+background_thread_indefinite_sleep(background_thread_info_t *info) {
+ return atomic_load_b(&info->indefinite_sleep, ATOMIC_ACQUIRE);
+}
+
+JEMALLOC_ALWAYS_INLINE void
+arena_background_thread_inactivity_check(tsdn_t *tsdn, arena_t *arena) {
+ if (!background_thread_enabled()) {
+ return;
+ }
+ background_thread_info_t *info =
+ arena_background_thread_info_get(arena);
+ if (background_thread_indefinite_sleep(info)) {
+ background_thread_interval_check(tsdn, arena,
+ &arena->decay_dirty, 0);
+ }
+}
+
#endif /* JEMALLOC_INTERNAL_BACKGROUND_THREAD_INLINES_H */
diff --git a/include/jemalloc/internal/background_thread_structs.h b/include/jemalloc/internal/background_thread_structs.h
index c4eb8273..9507abcd 100644
--- a/include/jemalloc/internal/background_thread_structs.h
+++ b/include/jemalloc/internal/background_thread_structs.h
@@ -1,15 +1,22 @@
#ifndef JEMALLOC_INTERNAL_BACKGROUND_THREAD_STRUCTS_H
#define JEMALLOC_INTERNAL_BACKGROUND_THREAD_STRUCTS_H
+/* This file really combines "structs" and "types", but only transitionally. */
+
+#define BACKGROUND_THREAD_INDEFINITE_SLEEP UINT64_MAX
+
struct background_thread_info_s {
- malloc_mutex_t mtx;
#ifdef JEMALLOC_BACKGROUND_THREAD
/* Background thread is pthread specific. */
- pthread_cond_t cond;
pthread_t thread;
+ pthread_cond_t cond;
+#endif
+ malloc_mutex_t mtx;
/* Whether the thread has been created. */
bool started;
- /* Next scheduled wakeup time (absolute time). */
+ /* When true, it means no wakeup scheduled. */
+ atomic_b_t indefinite_sleep;
+ /* Next scheduled wakeup time (absolute time in ns). */
nstime_t next_wakeup;
/*
* Since the last background thread run, newly added number of pages
@@ -22,7 +29,6 @@ struct background_thread_info_s {
uint64_t tot_n_runs;
/* Stats: total sleep time since started. */
nstime_t tot_sleep_time;
-#endif /* ifdef JEMALLOC_BACKGROUND_THREAD */
};
typedef struct background_thread_info_s background_thread_info_t;