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