Blame jemalloc/include/jemalloc/internal/background_thread_structs.h

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