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

@@ -183,8 +183,51 @@ ehooks_default_split(extent_hooks_t *extent_hooks, void *addr, size_t size,
return ehooks_default_split_impl();
}
static inline bool
ehooks_same_sn(tsdn_t *tsdn, void *addr_a, void *addr_b) {
edata_t *a = iealloc(tsdn, addr_a);
edata_t *b = iealloc(tsdn, addr_b);
return edata_sn_comp(a, b) == 0;
}
/*
* Returns true if the given extents can't be merged because of their head bit
* settings. Assumes the second extent has the higher address.
*/
static bool
ehooks_no_merge_heads(tsdn_t *tsdn, void *addr_a, bool head_a, void *addr_b,
bool head_b) {
/*
* When coalesce is not always allowed (Windows), only merge extents
* from the same VirtualAlloc region under opt.retain (in which case
* MEM_DECOMMIT is utilized for purging).
*/
if (maps_coalesce) {
return false;
}
if (!opt_retain) {
return true;
}
/* If b is a head extent, disallow the cross-region merge. */
if (head_b) {
/*
* Additionally, sn should not overflow with retain; sanity
* check that different regions have unique sn.
*/
assert(!ehooks_same_sn(tsdn, addr_a, addr_b));
return true;
}
assert(ehooks_same_sn(tsdn, addr_a, addr_b));
return false;
}
bool
ehooks_default_merge_impl(void *addr_a, void *addr_b) {
ehooks_default_merge_impl(tsdn_t *tsdn, void *addr_a, bool head_a, void *addr_b,
bool head_b) {
if (ehooks_no_merge_heads(tsdn, addr_a, head_a, addr_b, head_b)) {
return true;
}
if (!maps_coalesce && !opt_retain) {
return true;
}
@@ -198,15 +241,12 @@ ehooks_default_merge_impl(void *addr_a, void *addr_b) {
static bool
ehooks_default_merge(extent_hooks_t *extent_hooks, void *addr_a, size_t size_a,
void *addr_b, size_t size_b, bool committed, unsigned arena_ind) {
if (!maps_coalesce) {
tsdn_t *tsdn = tsdn_fetch();
edata_t *a = iealloc(tsdn, addr_a);
edata_t *b = iealloc(tsdn, addr_b);
if (extent_head_no_merge(a, b)) {
return true;
}
}
return ehooks_default_merge_impl(addr_a, addr_b);
tsdn_t *tsdn = tsdn_fetch();
edata_t *a = iealloc(tsdn, addr_a);
bool head_a = edata_is_head_get(a);
edata_t *b = iealloc(tsdn, addr_b);
bool head_b = edata_is_head_get(b);
return ehooks_default_merge_impl(tsdn, addr_a, head_a, addr_b, head_b);
}
void

View File

@@ -1493,38 +1493,6 @@ extent_split_wrapper(tsdn_t *tsdn, arena_t *arena, ehooks_t *ehooks,
slab_a, size_b, szind_b, slab_b, false);
}
/*
* Returns true if the given extents can't be merged because of their head bit
* settings. Assumes the second extent has the higher address.
*/
bool
extent_head_no_merge(edata_t *a, edata_t *b) {
assert(edata_base_get(a) < edata_base_get(b));
/*
* When coalesce is not always allowed (Windows), only merge extents
* from the same VirtualAlloc region under opt.retain (in which case
* MEM_DECOMMIT is utilized for purging).
*/
if (maps_coalesce) {
return false;
}
if (!opt_retain) {
return true;
}
/* If b is a head extent, disallow the cross-region merge. */
if (edata_is_head_get(b)) {
/*
* Additionally, sn should not overflow with retain; sanity
* check that different regions have unique sn.
*/
assert(edata_sn_comp(a, b) != 0);
return true;
}
assert(edata_sn_comp(a, b) == 0);
return false;
}
static bool
extent_merge_impl(tsdn_t *tsdn, arena_t *arena, ehooks_t *ehooks, edata_t *a,
edata_t *b, bool growing_retained) {
@@ -1532,13 +1500,10 @@ extent_merge_impl(tsdn_t *tsdn, arena_t *arena, ehooks_t *ehooks, edata_t *a,
WITNESS_RANK_CORE, growing_retained ? 1 : 0);
assert(edata_base_get(a) < edata_base_get(b));
if (ehooks_merge_will_fail(ehooks) || extent_head_no_merge(a, b)) {
return true;
}
bool err = ehooks_merge(tsdn, ehooks, edata_base_get(a),
edata_size_get(a), edata_base_get(b), edata_size_get(b),
edata_committed_get(a), arena_ind_get(arena));
edata_size_get(a), edata_is_head_get(a), edata_base_get(b),
edata_size_get(b), edata_is_head_get(b), edata_committed_get(a),
arena_ind_get(arena));
if (err) {
return true;