Ehooks: Add head tracking.

This commit is contained in:
David Goldblatt
2019-12-11 17:23:24 -08:00
committed by David Goldblatt
parent 09475bf8ac
commit 0704516245
5 changed files with 68 additions and 66 deletions

View File

@@ -467,20 +467,12 @@ edata_prof_alloc_time_set(edata_t *edata, nstime_t *t) {
static inline bool
edata_is_head_get(edata_t *edata) {
if (maps_coalesce) {
not_reached();
}
return (bool)((edata->e_bits & EDATA_BITS_IS_HEAD_MASK) >>
EDATA_BITS_IS_HEAD_SHIFT);
}
static inline void
edata_is_head_set(edata_t *edata, bool is_head) {
if (maps_coalesce) {
not_reached();
}
edata->e_bits = (edata->e_bits & ~EDATA_BITS_IS_HEAD_MASK) |
((uint64_t)is_head << EDATA_BITS_IS_HEAD_SHIFT);
}
@@ -502,9 +494,7 @@ edata_init(edata_t *edata, unsigned arena_ind, void *addr, size_t size,
edata_committed_set(edata, committed);
edata_dumpable_set(edata, dumpable);
ql_elm_new(edata, ql_link);
if (!maps_coalesce) {
edata_is_head_set(edata, is_head == EXTENT_IS_HEAD);
}
edata_is_head_set(edata, is_head == EXTENT_IS_HEAD);
if (config_prof) {
edata_prof_tctx_set(edata, NULL);
}

View File

@@ -1,16 +1,21 @@
#ifndef JEMALLOC_INTERNAL_EHOOKS_H
#define JEMALLOC_INTERNAL_EHOOKS_H
#include "jemalloc/internal/atomic.h"
#include "jemalloc/internal/extent_mmap.h"
/*
* This module is the internal interface to the extent hooks (both
* user-specified and external). Eventually, this will give us the flexibility
* to use multiple different versions of user-visible extent-hook APIs under a
* single user interface.
*
* Current API expansions (not available to anyone but the default hooks yet):
* - Head state tracking. Hooks can decide whether or not to merge two
* extents based on whether or not one of them is the head (i.e. was
* allocated on its own). The later extent loses its "head" status.
*/
#include "jemalloc/internal/atomic.h"
#include "jemalloc/internal/extent_mmap.h"
extern const extent_hooks_t ehooks_default_extent_hooks;
typedef struct ehooks_s ehooks_t;
@@ -43,7 +48,8 @@ bool ehooks_default_purge_lazy_impl(void *addr, size_t offset, size_t length);
bool ehooks_default_purge_forced_impl(void *addr, size_t offset, size_t length);
#endif
bool ehooks_default_split_impl();
bool ehooks_default_merge_impl(void *addr_a, void *addr_b);
bool ehooks_default_merge_impl(tsdn_t *tsdn, void *addr_a, bool head_a,
void *addr_b, bool head_b);
void ehooks_default_zero_impl(void *addr, size_t size);
/*
@@ -314,10 +320,12 @@ ehooks_split(tsdn_t *tsdn, ehooks_t *ehooks, void *addr, size_t size,
static inline bool
ehooks_merge(tsdn_t *tsdn, ehooks_t *ehooks, void *addr_a, size_t size_a,
void *addr_b, size_t size_b, bool committed, unsigned arena_ind) {
bool head_a, void *addr_b, size_t size_b, bool head_b, bool committed,
unsigned arena_ind) {
extent_hooks_t *extent_hooks = ehooks_get_extent_hooks_ptr(ehooks);
if (extent_hooks == &ehooks_default_extent_hooks) {
return ehooks_default_merge_impl(addr_a, addr_b);
return ehooks_default_merge_impl(tsdn, addr_a, head_a, addr_b,
head_b);
} else if (extent_hooks->merge == NULL) {
return true;
} else {

View File

@@ -54,7 +54,6 @@ edata_t *extent_split_wrapper(tsdn_t *tsdn, arena_t *arena, ehooks_t *ehooks,
size_t size_b, szind_t szind_b, bool slab_b);
bool extent_merge_wrapper(tsdn_t *tsdn, arena_t *arena, ehooks_t *ehooks,
edata_t *a, edata_t *b);
bool extent_head_no_merge(edata_t *a, edata_t *b);
bool extent_boot(void);