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