2017-03-18 03:42:33 +08:00
|
|
|
#ifndef JEMALLOC_INTERNAL_BACKGROUND_THREAD_STRUCTS_H
|
|
|
|
#define JEMALLOC_INTERNAL_BACKGROUND_THREAD_STRUCTS_H
|
|
|
|
|
2017-05-23 06:26:25 +08:00
|
|
|
/* This file really combines "structs" and "types", but only transitionally. */
|
|
|
|
|
2017-06-01 07:45:14 +08:00
|
|
|
#if defined(JEMALLOC_BACKGROUND_THREAD) || defined(JEMALLOC_LAZY_LOCK)
|
|
|
|
# define JEMALLOC_PTHREAD_CREATE_WRAPPER
|
|
|
|
#endif
|
|
|
|
|
2017-05-23 06:26:25 +08:00
|
|
|
#define BACKGROUND_THREAD_INDEFINITE_SLEEP UINT64_MAX
|
2018-03-30 03:58:13 +08:00
|
|
|
#define MAX_BACKGROUND_THREAD_LIMIT MALLOCX_ARENA_LIMIT
|
2018-11-16 05:01:05 +08:00
|
|
|
#define DEFAULT_NUM_BACKGROUND_THREAD 4
|
2017-05-23 06:26:25 +08:00
|
|
|
|
2017-06-10 06:45:25 +08:00
|
|
|
typedef enum {
|
|
|
|
background_thread_stopped,
|
|
|
|
background_thread_started,
|
|
|
|
/* Thread waits on the global lock when paused (for arena_reset). */
|
|
|
|
background_thread_paused,
|
|
|
|
} background_thread_state_t;
|
|
|
|
|
2017-03-18 03:42:33 +08:00
|
|
|
struct background_thread_info_s {
|
|
|
|
#ifdef JEMALLOC_BACKGROUND_THREAD
|
|
|
|
/* Background thread is pthread specific. */
|
|
|
|
pthread_t thread;
|
2017-05-23 06:26:25 +08:00
|
|
|
pthread_cond_t cond;
|
|
|
|
#endif
|
|
|
|
malloc_mutex_t mtx;
|
2017-06-10 06:45:25 +08:00
|
|
|
background_thread_state_t state;
|
2017-05-23 06:26:25 +08:00
|
|
|
/* When true, it means no wakeup scheduled. */
|
|
|
|
atomic_b_t indefinite_sleep;
|
|
|
|
/* Next scheduled wakeup time (absolute time in ns). */
|
2017-03-18 03:42:33 +08:00
|
|
|
nstime_t next_wakeup;
|
|
|
|
/*
|
|
|
|
* Since the last background thread run, newly added number of pages
|
|
|
|
* that need to be purged by the next wakeup. This is adjusted on
|
|
|
|
* epoch advance, and is used to determine whether we should signal the
|
|
|
|
* background thread to wake up earlier.
|
|
|
|
*/
|
|
|
|
size_t npages_to_purge_new;
|
2017-05-13 03:30:33 +08:00
|
|
|
/* Stats: total number of runs since started. */
|
|
|
|
uint64_t tot_n_runs;
|
|
|
|
/* Stats: total sleep time since started. */
|
|
|
|
nstime_t tot_sleep_time;
|
2017-03-18 03:42:33 +08:00
|
|
|
};
|
|
|
|
typedef struct background_thread_info_s background_thread_info_t;
|
|
|
|
|
2017-05-13 03:30:33 +08:00
|
|
|
struct background_thread_stats_s {
|
|
|
|
size_t num_threads;
|
|
|
|
uint64_t num_runs;
|
|
|
|
nstime_t run_interval;
|
|
|
|
};
|
|
|
|
typedef struct background_thread_stats_s background_thread_stats_t;
|
|
|
|
|
2017-03-18 03:42:33 +08:00
|
|
|
#endif /* JEMALLOC_INTERNAL_BACKGROUND_THREAD_STRUCTS_H */
|