1*8e33eff8Schristos #ifndef JEMALLOC_INTERNAL_BACKGROUND_THREAD_STRUCTS_H 2*8e33eff8Schristos #define JEMALLOC_INTERNAL_BACKGROUND_THREAD_STRUCTS_H 3*8e33eff8Schristos 4*8e33eff8Schristos /* This file really combines "structs" and "types", but only transitionally. */ 5*8e33eff8Schristos 6*8e33eff8Schristos #if defined(JEMALLOC_BACKGROUND_THREAD) || defined(JEMALLOC_LAZY_LOCK) 7*8e33eff8Schristos # define JEMALLOC_PTHREAD_CREATE_WRAPPER 8*8e33eff8Schristos #endif 9*8e33eff8Schristos 10*8e33eff8Schristos #define BACKGROUND_THREAD_INDEFINITE_SLEEP UINT64_MAX 11*8e33eff8Schristos #define MAX_BACKGROUND_THREAD_LIMIT MALLOCX_ARENA_LIMIT 12*8e33eff8Schristos 13*8e33eff8Schristos typedef enum { 14*8e33eff8Schristos background_thread_stopped, 15*8e33eff8Schristos background_thread_started, 16*8e33eff8Schristos /* Thread waits on the global lock when paused (for arena_reset). */ 17*8e33eff8Schristos background_thread_paused, 18*8e33eff8Schristos } background_thread_state_t; 19*8e33eff8Schristos 20*8e33eff8Schristos struct background_thread_info_s { 21*8e33eff8Schristos #ifdef JEMALLOC_BACKGROUND_THREAD 22*8e33eff8Schristos /* Background thread is pthread specific. */ 23*8e33eff8Schristos pthread_t thread; 24*8e33eff8Schristos pthread_cond_t cond; 25*8e33eff8Schristos #endif 26*8e33eff8Schristos malloc_mutex_t mtx; 27*8e33eff8Schristos background_thread_state_t state; 28*8e33eff8Schristos /* When true, it means no wakeup scheduled. */ 29*8e33eff8Schristos atomic_b_t indefinite_sleep; 30*8e33eff8Schristos /* Next scheduled wakeup time (absolute time in ns). */ 31*8e33eff8Schristos nstime_t next_wakeup; 32*8e33eff8Schristos /* 33*8e33eff8Schristos * Since the last background thread run, newly added number of pages 34*8e33eff8Schristos * that need to be purged by the next wakeup. This is adjusted on 35*8e33eff8Schristos * epoch advance, and is used to determine whether we should signal the 36*8e33eff8Schristos * background thread to wake up earlier. 37*8e33eff8Schristos */ 38*8e33eff8Schristos size_t npages_to_purge_new; 39*8e33eff8Schristos /* Stats: total number of runs since started. */ 40*8e33eff8Schristos uint64_t tot_n_runs; 41*8e33eff8Schristos /* Stats: total sleep time since started. */ 42*8e33eff8Schristos nstime_t tot_sleep_time; 43*8e33eff8Schristos }; 44*8e33eff8Schristos typedef struct background_thread_info_s background_thread_info_t; 45*8e33eff8Schristos 46*8e33eff8Schristos struct background_thread_stats_s { 47*8e33eff8Schristos size_t num_threads; 48*8e33eff8Schristos uint64_t num_runs; 49*8e33eff8Schristos nstime_t run_interval; 50*8e33eff8Schristos }; 51*8e33eff8Schristos typedef struct background_thread_stats_s background_thread_stats_t; 52*8e33eff8Schristos 53*8e33eff8Schristos #endif /* JEMALLOC_INTERNAL_BACKGROUND_THREAD_STRUCTS_H */ 54