90typedef struct xtc_slab xtc_slab_t;
93typedef int64_t xtc_slab_off_t;
94#define XTC_SLAB_OFF_NONE ((xtc_slab_off_t)-1)
97typedef int (*xtc_slab_ctor_fn)(
void *obj,
void *user);
98typedef void (*xtc_slab_dtor_fn)(
void *obj,
void *user);
102typedef void (*xtc_slab_pressure_fn)(
int level,
void *user);
106typedef struct psi_listener xtc_slab_pressure_t;
109typedef enum xtc_slab_mode {
110 XTC_SLAB_PROCESS_LOCAL = 0,
111 XTC_SLAB_SHARED_MEMORY = 1
115typedef enum xtc_slab_oom_policy {
116 XTC_SLAB_OOM_FAIL = 0,
117 XTC_SLAB_OOM_BACKOFF = 1,
118 XTC_SLAB_OOM_ABORT = 2
119} xtc_slab_oom_policy_t;
122#define XTC_SLAB_REDZONE (1u << 0)
123#define XTC_SLAB_AUDIT (1u << 1)
124#define XTC_SLAB_BACKTRACE (1u << 2)
125#define XTC_SLAB_NO_MAGAZINE (1u << 3)
127typedef struct xtc_slab_opts {
133 xtc_slab_ctor_fn ctor;
134 xtc_slab_dtor_fn dtor;
137 xtc_slab_oom_policy_t oom_policy;
144 xtc_slab_mode_t mode;
149#define XTC_SLAB_OPTS_DEFAULT { \
153 .chunk_size = 64 * 1024, \
154 .magazine_size = 16, \
155 .ctor = NULL, .dtor = NULL, .cb_user = NULL, \
157 .oom_policy = XTC_SLAB_OOM_FAIL, \
159 .mode = XTC_SLAB_PROCESS_LOCAL, \
164typedef struct xtc_slab_stats {
172 uint64_t bytes_inuse;
173 uint64_t bytes_total;
176 uint64_t redzone_violations;
199void xtc_slab_destroy(xtc_slab_t *slab);
201void *xtc_slab_alloc(xtc_slab_t *slab);
202void xtc_slab_free(xtc_slab_t *slab,
void *obj);
205int xtc_slab_reap(xtc_slab_t *slab);
212xtc_slab_off_t xtc_slab_offset(
const xtc_slab_t *slab,
const void *p);
213void *xtc_slab_resolve(
const xtc_slab_t *slab, xtc_slab_off_t off);
221int xtc_slab_pressure_listen(
const char *psi_path,
222 xtc_slab_pressure_fn fn,
229int xtc_slab_pressure_listen_ex(
const char *psi_path,
230 xtc_slab_pressure_fn fn,
232 xtc_slab_pressure_t **out);
238int xtc_slab_pressure_stop(xtc_slab_pressure_t *handle);
242int xtc_slab_reap_all(
void);
248int xtc_slab_reaper_spawn(xtc_loop_t *loop, int64_t interval_ns,