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 | /* |
15 | * These exist only as a transitional state. Eventually, deferral should be |
16 | * part of the PAI, and each implementation can indicate wait times with more |
17 | * specificity. |
18 | */ |
19 | #define BACKGROUND_THREAD_HPA_INTERVAL_MAX_UNINITIALIZED (-2) |
20 | #define BACKGROUND_THREAD_HPA_INTERVAL_MAX_DEFAULT_WHEN_ENABLED 5000 |
21 | |
22 | #define BACKGROUND_THREAD_DEFERRED_MIN UINT64_C(0) |
23 | #define BACKGROUND_THREAD_DEFERRED_MAX UINT64_MAX |
24 | |
25 | typedef enum { |
26 | background_thread_stopped, |
27 | background_thread_started, |
28 | /* Thread waits on the global lock when paused (for arena_reset). */ |
29 | background_thread_paused, |
30 | } background_thread_state_t; |
31 | |
32 | struct background_thread_info_s { |
33 | #ifdef JEMALLOC_BACKGROUND_THREAD |
34 | /* Background thread is pthread specific. */ |
35 | pthread_t thread; |
36 | pthread_cond_t cond; |
37 | #endif |
38 | malloc_mutex_t mtx; |
39 | background_thread_state_t state; |
40 | /* When true, it means no wakeup scheduled. */ |
41 | atomic_b_t indefinite_sleep; |
42 | /* Next scheduled wakeup time (absolute time in ns). */ |
43 | nstime_t next_wakeup; |
44 | /* |
45 | * Since the last background thread run, newly added number of pages |
46 | * that need to be purged by the next wakeup. This is adjusted on |
47 | * epoch advance, and is used to determine whether we should signal the |
48 | * background thread to wake up earlier. |
49 | */ |
50 | size_t npages_to_purge_new; |
51 | /* Stats: total number of runs since started. */ |
52 | uint64_t tot_n_runs; |
53 | /* Stats: total sleep time since started. */ |
54 | nstime_t tot_sleep_time; |
55 | }; |
56 | typedef struct background_thread_info_s background_thread_info_t; |
57 | |
58 | struct background_thread_stats_s { |
59 | size_t num_threads; |
60 | uint64_t num_runs; |
61 | nstime_t run_interval; |
62 | mutex_prof_data_t max_counter_per_bg_thd; |
63 | }; |
64 | typedef struct background_thread_stats_s background_thread_stats_t; |
65 | |
66 | #endif /* JEMALLOC_INTERNAL_BACKGROUND_THREAD_STRUCTS_H */ |
67 | |