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
|
|
|
|
2021-06-08 02:45:57 +08:00
|
|
|
/*
|
|
|
|
* These exist only as a transitional state. Eventually, deferral should be
|
|
|
|
* part of the PAI, and each implementation can indicate wait times with more
|
|
|
|
* specificity.
|
|
|
|
*/
|
|
|
|
#define BACKGROUND_THREAD_HPA_INTERVAL_MAX_UNINITIALIZED (-2)
|
|
|
|
#define BACKGROUND_THREAD_HPA_INTERVAL_MAX_DEFAULT_WHEN_ENABLED 5000
|
|
|
|
|
2021-08-07 05:53:05 +08:00
|
|
|
#define BACKGROUND_THREAD_DEFERRED_MIN UINT64_C(0)
|
2021-08-19 10:24:37 +08:00
|
|
|
#define BACKGROUND_THREAD_DEFERRED_MAX UINT64_MAX
|
2021-08-07 05:53:05 +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;
|
2019-08-15 07:10:09 +08:00
|
|
|
mutex_prof_data_t max_counter_per_bg_thd;
|
2017-05-13 03:30:33 +08:00
|
|
|
};
|
|
|
|
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 */
|