2017-01-20 13:41:41 +08:00
|
|
|
#define JEMALLOC_EXTENT_C_
|
2017-04-11 09:17:55 +08:00
|
|
|
#include "jemalloc/internal/jemalloc_preamble.h"
|
2017-04-12 05:43:12 +08:00
|
|
|
#include "jemalloc/internal/jemalloc_internal_includes.h"
|
2010-01-17 01:53:50 +08:00
|
|
|
|
2017-04-12 05:43:12 +08:00
|
|
|
#include "jemalloc/internal/assert.h"
|
2017-05-24 05:36:09 +08:00
|
|
|
#include "jemalloc/internal/extent_dss.h"
|
2017-05-24 05:42:32 +08:00
|
|
|
#include "jemalloc/internal/extent_mmap.h"
|
2017-04-11 07:54:25 +08:00
|
|
|
#include "jemalloc/internal/ph.h"
|
2017-05-24 05:26:31 +08:00
|
|
|
#include "jemalloc/internal/rtree.h"
|
2017-05-24 03:28:19 +08:00
|
|
|
#include "jemalloc/internal/mutex.h"
|
2017-05-24 05:56:24 +08:00
|
|
|
#include "jemalloc/internal/mutex_pool.h"
|
2017-04-11 07:54:25 +08:00
|
|
|
|
2016-06-02 03:10:39 +08:00
|
|
|
/******************************************************************************/
|
|
|
|
/* Data. */
|
|
|
|
|
|
|
|
rtree_t extents_rtree;
|
2017-05-16 05:23:51 +08:00
|
|
|
/* Keyed by the address of the extent_t being protected. */
|
|
|
|
mutex_pool_t extent_mutex_pool;
|
2016-06-02 03:10:39 +08:00
|
|
|
|
2017-11-10 05:51:39 +08:00
|
|
|
size_t opt_lg_extent_max_active_fit = LG_EXTENT_MAX_ACTIVE_FIT_DEFAULT;
|
|
|
|
|
2017-03-24 14:45:11 +08:00
|
|
|
static const bitmap_info_t extents_bitmap_info =
|
2018-07-20 08:08:10 +08:00
|
|
|
BITMAP_INFO_INITIALIZER(SC_NPSIZES+1);
|
2017-03-24 14:45:11 +08:00
|
|
|
|
2017-05-27 02:06:01 +08:00
|
|
|
static void *extent_alloc_default(extent_hooks_t *extent_hooks, void *new_addr,
|
|
|
|
size_t size, size_t alignment, bool *zero, bool *commit,
|
2016-06-04 03:05:53 +08:00
|
|
|
unsigned arena_ind);
|
2017-05-27 02:06:01 +08:00
|
|
|
static bool extent_dalloc_default(extent_hooks_t *extent_hooks, void *addr,
|
2016-06-04 03:05:53 +08:00
|
|
|
size_t size, bool committed, unsigned arena_ind);
|
2017-05-27 02:06:01 +08:00
|
|
|
static void extent_destroy_default(extent_hooks_t *extent_hooks, void *addr,
|
2017-04-28 06:51:35 +08:00
|
|
|
size_t size, bool committed, unsigned arena_ind);
|
2017-05-27 02:06:01 +08:00
|
|
|
static bool extent_commit_default(extent_hooks_t *extent_hooks, void *addr,
|
2016-06-04 03:05:53 +08:00
|
|
|
size_t size, size_t offset, size_t length, unsigned arena_ind);
|
2017-05-27 02:06:01 +08:00
|
|
|
static bool extent_commit_impl(tsdn_t *tsdn, arena_t *arena,
|
|
|
|
extent_hooks_t **r_extent_hooks, extent_t *extent, size_t offset,
|
|
|
|
size_t length, bool growing_retained);
|
|
|
|
static bool extent_decommit_default(extent_hooks_t *extent_hooks,
|
2016-06-04 03:05:53 +08:00
|
|
|
void *addr, size_t size, size_t offset, size_t length, unsigned arena_ind);
|
2016-12-04 07:38:25 +08:00
|
|
|
#ifdef PAGES_CAN_PURGE_LAZY
|
2017-05-27 02:06:01 +08:00
|
|
|
static bool extent_purge_lazy_default(extent_hooks_t *extent_hooks, void *addr,
|
|
|
|
size_t size, size_t offset, size_t length, unsigned arena_ind);
|
2016-12-04 07:38:25 +08:00
|
|
|
#endif
|
2017-05-27 02:06:01 +08:00
|
|
|
static bool extent_purge_lazy_impl(tsdn_t *tsdn, arena_t *arena,
|
|
|
|
extent_hooks_t **r_extent_hooks, extent_t *extent, size_t offset,
|
|
|
|
size_t length, bool growing_retained);
|
2016-12-04 07:38:25 +08:00
|
|
|
#ifdef PAGES_CAN_PURGE_FORCED
|
2017-05-27 02:06:01 +08:00
|
|
|
static bool extent_purge_forced_default(extent_hooks_t *extent_hooks,
|
2016-12-04 07:38:25 +08:00
|
|
|
void *addr, size_t size, size_t offset, size_t length, unsigned arena_ind);
|
|
|
|
#endif
|
2017-05-27 02:06:01 +08:00
|
|
|
static bool extent_purge_forced_impl(tsdn_t *tsdn, arena_t *arena,
|
|
|
|
extent_hooks_t **r_extent_hooks, extent_t *extent, size_t offset,
|
|
|
|
size_t length, bool growing_retained);
|
2016-12-04 07:38:25 +08:00
|
|
|
#ifdef JEMALLOC_MAPS_COALESCE
|
2017-05-27 02:06:01 +08:00
|
|
|
static bool extent_split_default(extent_hooks_t *extent_hooks, void *addr,
|
2016-06-04 03:05:53 +08:00
|
|
|
size_t size, size_t size_a, size_t size_b, bool committed,
|
|
|
|
unsigned arena_ind);
|
2017-05-27 02:06:01 +08:00
|
|
|
#endif
|
|
|
|
static extent_t *extent_split_impl(tsdn_t *tsdn, arena_t *arena,
|
|
|
|
extent_hooks_t **r_extent_hooks, extent_t *extent, size_t size_a,
|
|
|
|
szind_t szind_a, bool slab_a, size_t size_b, szind_t szind_b, bool slab_b,
|
|
|
|
bool growing_retained);
|
|
|
|
#ifdef JEMALLOC_MAPS_COALESCE
|
|
|
|
static bool extent_merge_default(extent_hooks_t *extent_hooks, void *addr_a,
|
2016-06-04 03:05:53 +08:00
|
|
|
size_t size_a, void *addr_b, size_t size_b, bool committed,
|
2016-06-02 03:59:02 +08:00
|
|
|
unsigned arena_ind);
|
2016-12-04 07:38:25 +08:00
|
|
|
#endif
|
2017-05-27 02:06:01 +08:00
|
|
|
static bool extent_merge_impl(tsdn_t *tsdn, arena_t *arena,
|
|
|
|
extent_hooks_t **r_extent_hooks, extent_t *a, extent_t *b,
|
|
|
|
bool growing_retained);
|
2016-06-02 03:59:02 +08:00
|
|
|
|
|
|
|
const extent_hooks_t extent_hooks_default = {
|
|
|
|
extent_alloc_default,
|
|
|
|
extent_dalloc_default,
|
2017-04-28 06:51:35 +08:00
|
|
|
extent_destroy_default,
|
2016-06-02 03:59:02 +08:00
|
|
|
extent_commit_default,
|
2016-12-04 07:38:25 +08:00
|
|
|
extent_decommit_default
|
|
|
|
#ifdef PAGES_CAN_PURGE_LAZY
|
|
|
|
,
|
|
|
|
extent_purge_lazy_default
|
|
|
|
#else
|
|
|
|
,
|
|
|
|
NULL
|
|
|
|
#endif
|
|
|
|
#ifdef PAGES_CAN_PURGE_FORCED
|
|
|
|
,
|
|
|
|
extent_purge_forced_default
|
|
|
|
#else
|
|
|
|
,
|
|
|
|
NULL
|
|
|
|
#endif
|
|
|
|
#ifdef JEMALLOC_MAPS_COALESCE
|
|
|
|
,
|
2016-06-02 03:59:02 +08:00
|
|
|
extent_split_default,
|
|
|
|
extent_merge_default
|
2016-12-04 07:38:25 +08:00
|
|
|
#endif
|
2016-06-02 03:59:02 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Used exclusively for gdump triggering. */
|
2017-04-05 09:20:42 +08:00
|
|
|
static atomic_zu_t curpages;
|
|
|
|
static atomic_zu_t highpages;
|
2016-06-02 03:59:02 +08:00
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
/*
|
|
|
|
* Function prototypes for static functions that are referenced prior to
|
|
|
|
* definition.
|
|
|
|
*/
|
|
|
|
|
2017-01-30 13:57:14 +08:00
|
|
|
static void extent_deregister(tsdn_t *tsdn, extent_t *extent);
|
Implement two-phase decay-based purging.
Split decay-based purging into two phases, the first of which uses lazy
purging to convert dirty pages to "muzzy", and the second of which uses
forced purging, decommit, or unmapping to convert pages to clean or
destroy them altogether. Not all operating systems support lazy
purging, yet the application may provide extent hooks that implement
lazy purging, so care must be taken to dynamically omit the first phase
when necessary.
The mallctl interfaces change as follows:
- opt.decay_time --> opt.{dirty,muzzy}_decay_time
- arena.<i>.decay_time --> arena.<i>.{dirty,muzzy}_decay_time
- arenas.decay_time --> arenas.{dirty,muzzy}_decay_time
- stats.arenas.<i>.pdirty --> stats.arenas.<i>.p{dirty,muzzy}
- stats.arenas.<i>.{npurge,nmadvise,purged} -->
stats.arenas.<i>.{dirty,muzzy}_{npurge,nmadvise,purged}
This resolves #521.
2017-03-09 14:42:57 +08:00
|
|
|
static extent_t *extent_recycle(tsdn_t *tsdn, arena_t *arena,
|
|
|
|
extent_hooks_t **r_extent_hooks, extents_t *extents, void *new_addr,
|
2017-03-14 08:36:57 +08:00
|
|
|
size_t usize, size_t pad, size_t alignment, bool slab, szind_t szind,
|
2017-05-27 02:06:01 +08:00
|
|
|
bool *zero, bool *commit, bool growing_retained);
|
2017-03-03 10:04:35 +08:00
|
|
|
static extent_t *extent_try_coalesce(tsdn_t *tsdn, arena_t *arena,
|
|
|
|
extent_hooks_t **r_extent_hooks, rtree_ctx_t *rtree_ctx, extents_t *extents,
|
2017-05-27 02:06:01 +08:00
|
|
|
extent_t *extent, bool *coalesced, bool growing_retained);
|
2017-01-30 13:57:14 +08:00
|
|
|
static void extent_record(tsdn_t *tsdn, arena_t *arena,
|
2017-05-27 02:06:01 +08:00
|
|
|
extent_hooks_t **r_extent_hooks, extents_t *extents, extent_t *extent,
|
|
|
|
bool growing_retained);
|
2016-06-02 03:59:02 +08:00
|
|
|
|
2010-01-17 01:53:50 +08:00
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-05-03 17:40:53 +08:00
|
|
|
#define ATTR_NONE /* does nothing */
|
|
|
|
|
|
|
|
ph_gen(ATTR_NONE, extent_avail_, extent_tree_t, extent_t, ph_link,
|
2017-04-17 13:31:16 +08:00
|
|
|
extent_esnead_comp)
|
|
|
|
|
2018-05-03 17:40:53 +08:00
|
|
|
#undef ATTR_NONE
|
|
|
|
|
2017-05-16 05:23:51 +08:00
|
|
|
typedef enum {
|
|
|
|
lock_result_success,
|
|
|
|
lock_result_failure,
|
|
|
|
lock_result_no_extent
|
|
|
|
} lock_result_t;
|
|
|
|
|
|
|
|
static lock_result_t
|
|
|
|
extent_rtree_leaf_elm_try_lock(tsdn_t *tsdn, rtree_leaf_elm_t *elm,
|
|
|
|
extent_t **result) {
|
|
|
|
extent_t *extent1 = rtree_leaf_elm_extent_read(tsdn, &extents_rtree,
|
|
|
|
elm, true);
|
|
|
|
|
|
|
|
if (extent1 == NULL) {
|
|
|
|
return lock_result_no_extent;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* It's possible that the extent changed out from under us, and with it
|
|
|
|
* the leaf->extent mapping. We have to recheck while holding the lock.
|
|
|
|
*/
|
|
|
|
extent_lock(tsdn, extent1);
|
|
|
|
extent_t *extent2 = rtree_leaf_elm_extent_read(tsdn,
|
|
|
|
&extents_rtree, elm, true);
|
|
|
|
|
|
|
|
if (extent1 == extent2) {
|
|
|
|
*result = extent1;
|
|
|
|
return lock_result_success;
|
|
|
|
} else {
|
|
|
|
extent_unlock(tsdn, extent1);
|
|
|
|
return lock_result_failure;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns a pool-locked extent_t * if there's one associated with the given
|
|
|
|
* address, and NULL otherwise.
|
|
|
|
*/
|
|
|
|
static extent_t *
|
|
|
|
extent_lock_from_addr(tsdn_t *tsdn, rtree_ctx_t *rtree_ctx, void *addr) {
|
|
|
|
extent_t *ret = NULL;
|
|
|
|
rtree_leaf_elm_t *elm = rtree_leaf_elm_lookup(tsdn, &extents_rtree,
|
|
|
|
rtree_ctx, (uintptr_t)addr, false, false);
|
|
|
|
if (elm == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
lock_result_t lock_result;
|
|
|
|
do {
|
|
|
|
lock_result = extent_rtree_leaf_elm_try_lock(tsdn, elm, &ret);
|
|
|
|
} while (lock_result == lock_result_failure);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-05-24 05:56:35 +08:00
|
|
|
extent_t *
|
2017-01-16 08:56:30 +08:00
|
|
|
extent_alloc(tsdn_t *tsdn, arena_t *arena) {
|
2017-04-17 13:31:16 +08:00
|
|
|
malloc_mutex_lock(tsdn, &arena->extent_avail_mtx);
|
|
|
|
extent_t *extent = extent_avail_first(&arena->extent_avail);
|
2016-05-24 05:56:35 +08:00
|
|
|
if (extent == NULL) {
|
2017-04-17 13:31:16 +08:00
|
|
|
malloc_mutex_unlock(tsdn, &arena->extent_avail_mtx);
|
2017-04-17 12:51:26 +08:00
|
|
|
return base_alloc_extent(tsdn, arena->base);
|
2016-05-24 05:56:35 +08:00
|
|
|
}
|
2017-04-17 13:31:16 +08:00
|
|
|
extent_avail_remove(&arena->extent_avail, extent);
|
2018-08-02 05:14:33 +08:00
|
|
|
atomic_fetch_sub_zu(&arena->extent_avail_cnt, 1, ATOMIC_RELAXED);
|
2017-04-17 13:31:16 +08:00
|
|
|
malloc_mutex_unlock(tsdn, &arena->extent_avail_mtx);
|
2017-01-20 10:15:45 +08:00
|
|
|
return extent;
|
2016-05-24 05:56:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-01-16 08:56:30 +08:00
|
|
|
extent_dalloc(tsdn_t *tsdn, arena_t *arena, extent_t *extent) {
|
2017-04-17 13:31:16 +08:00
|
|
|
malloc_mutex_lock(tsdn, &arena->extent_avail_mtx);
|
|
|
|
extent_avail_insert(&arena->extent_avail, extent);
|
2018-08-02 05:14:33 +08:00
|
|
|
atomic_fetch_add_zu(&arena->extent_avail_cnt, 1, ATOMIC_RELAXED);
|
2017-04-17 13:31:16 +08:00
|
|
|
malloc_mutex_unlock(tsdn, &arena->extent_avail_mtx);
|
2016-05-24 05:56:35 +08:00
|
|
|
}
|
|
|
|
|
2016-06-04 03:05:53 +08:00
|
|
|
extent_hooks_t *
|
2017-01-16 08:56:30 +08:00
|
|
|
extent_hooks_get(arena_t *arena) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return base_extent_hooks_get(arena->base);
|
2016-06-02 03:59:02 +08:00
|
|
|
}
|
|
|
|
|
2016-06-04 03:05:53 +08:00
|
|
|
extent_hooks_t *
|
2017-06-03 07:27:05 +08:00
|
|
|
extent_hooks_set(tsd_t *tsd, arena_t *arena, extent_hooks_t *extent_hooks) {
|
|
|
|
background_thread_info_t *info;
|
|
|
|
if (have_background_thread) {
|
|
|
|
info = arena_background_thread_info_get(arena);
|
|
|
|
malloc_mutex_lock(tsd_tsdn(tsd), &info->mtx);
|
|
|
|
}
|
|
|
|
extent_hooks_t *ret = base_extent_hooks_set(arena->base, extent_hooks);
|
|
|
|
if (have_background_thread) {
|
|
|
|
malloc_mutex_unlock(tsd_tsdn(tsd), &info->mtx);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2016-06-02 03:59:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-01-16 08:56:30 +08:00
|
|
|
extent_hooks_assure_initialized(arena_t *arena,
|
|
|
|
extent_hooks_t **r_extent_hooks) {
|
|
|
|
if (*r_extent_hooks == EXTENT_HOOKS_INITIALIZER) {
|
2016-06-04 03:05:53 +08:00
|
|
|
*r_extent_hooks = extent_hooks_get(arena);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2016-06-02 03:59:02 +08:00
|
|
|
}
|
|
|
|
|
2017-02-27 04:48:43 +08:00
|
|
|
#ifndef JEMALLOC_JET
|
|
|
|
static
|
2016-05-18 05:58:56 +08:00
|
|
|
#endif
|
|
|
|
size_t
|
2017-01-16 08:56:30 +08:00
|
|
|
extent_size_quantize_floor(size_t size) {
|
2016-05-18 05:58:56 +08:00
|
|
|
size_t ret;
|
|
|
|
pszind_t pind;
|
2015-05-05 00:58:36 +08:00
|
|
|
|
2016-05-18 05:58:56 +08:00
|
|
|
assert(size > 0);
|
|
|
|
assert((size & PAGE_MASK) == 0);
|
|
|
|
|
2017-05-31 01:45:37 +08:00
|
|
|
pind = sz_psz2ind(size - sz_large_pad + 1);
|
2016-05-18 05:58:56 +08:00
|
|
|
if (pind == 0) {
|
|
|
|
/*
|
|
|
|
* Avoid underflow. This short-circuit would also do the right
|
|
|
|
* thing for all sizes in the range for which there are
|
|
|
|
* PAGE-spaced size classes, but it's simplest to just handle
|
|
|
|
* the one case that would cause erroneous results.
|
|
|
|
*/
|
2017-01-20 10:15:45 +08:00
|
|
|
return size;
|
2016-05-18 05:58:56 +08:00
|
|
|
}
|
2017-05-31 01:45:37 +08:00
|
|
|
ret = sz_pind2sz(pind - 1) + sz_large_pad;
|
2016-05-18 05:58:56 +08:00
|
|
|
assert(ret <= size);
|
2017-01-20 10:15:45 +08:00
|
|
|
return ret;
|
2015-05-05 00:58:36 +08:00
|
|
|
}
|
|
|
|
|
2017-02-27 04:48:43 +08:00
|
|
|
#ifndef JEMALLOC_JET
|
|
|
|
static
|
2016-05-18 05:58:56 +08:00
|
|
|
#endif
|
|
|
|
size_t
|
2017-01-16 08:56:30 +08:00
|
|
|
extent_size_quantize_ceil(size_t size) {
|
2016-05-18 05:58:56 +08:00
|
|
|
size_t ret;
|
|
|
|
|
|
|
|
assert(size > 0);
|
2018-07-12 07:05:58 +08:00
|
|
|
assert(size - sz_large_pad <= SC_LARGE_MAXCLASS);
|
2016-05-18 05:58:56 +08:00
|
|
|
assert((size & PAGE_MASK) == 0);
|
2010-01-17 01:53:50 +08:00
|
|
|
|
2016-05-18 05:58:56 +08:00
|
|
|
ret = extent_size_quantize_floor(size);
|
|
|
|
if (ret < size) {
|
|
|
|
/*
|
|
|
|
* Skip a quantization that may have an adequately large extent,
|
|
|
|
* because under-sized extents may be mixed in. This only
|
|
|
|
* happens when an unusual size is requested, i.e. for aligned
|
|
|
|
* allocation, and is just one of several places where linear
|
|
|
|
* search would potentially find sufficiently aligned available
|
|
|
|
* memory somewhere lower.
|
|
|
|
*/
|
2017-05-31 01:45:37 +08:00
|
|
|
ret = sz_pind2sz(sz_psz2ind(ret - sz_large_pad + 1)) +
|
|
|
|
sz_large_pad;
|
2016-05-18 05:58:56 +08:00
|
|
|
}
|
2017-01-20 10:15:45 +08:00
|
|
|
return ret;
|
2010-01-17 01:53:50 +08:00
|
|
|
}
|
2016-05-18 05:58:56 +08:00
|
|
|
|
|
|
|
/* Generate pairing heap functions. */
|
2016-11-16 05:07:53 +08:00
|
|
|
ph_gen(, extent_heap_, extent_heap_t, extent_t, ph_link, extent_snad_comp)
|
2016-06-02 03:10:39 +08:00
|
|
|
|
2017-01-30 13:57:14 +08:00
|
|
|
bool
|
2017-02-13 15:18:57 +08:00
|
|
|
extents_init(tsdn_t *tsdn, extents_t *extents, extent_state_t state,
|
2017-03-03 10:04:35 +08:00
|
|
|
bool delay_coalesce) {
|
2017-05-16 06:38:15 +08:00
|
|
|
if (malloc_mutex_init(&extents->mtx, "extents", WITNESS_RANK_EXTENTS,
|
|
|
|
malloc_mutex_rank_exclusive)) {
|
2017-01-30 13:57:14 +08:00
|
|
|
return true;
|
|
|
|
}
|
2018-07-20 08:08:10 +08:00
|
|
|
for (unsigned i = 0; i < SC_NPSIZES + 1; i++) {
|
2017-01-30 13:57:14 +08:00
|
|
|
extent_heap_new(&extents->heaps[i]);
|
|
|
|
}
|
2017-03-24 14:45:11 +08:00
|
|
|
bitmap_init(extents->bitmap, &extents_bitmap_info, true);
|
2017-01-30 13:57:14 +08:00
|
|
|
extent_list_init(&extents->lru);
|
2017-03-08 09:57:48 +08:00
|
|
|
atomic_store_zu(&extents->npages, 0, ATOMIC_RELAXED);
|
2017-01-30 13:57:14 +08:00
|
|
|
extents->state = state;
|
2017-03-03 10:04:35 +08:00
|
|
|
extents->delay_coalesce = delay_coalesce;
|
2017-01-30 13:57:14 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
extent_state_t
|
|
|
|
extents_state_get(const extents_t *extents) {
|
|
|
|
return extents->state;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
extents_npages_get(extents_t *extents) {
|
2017-03-08 09:57:48 +08:00
|
|
|
return atomic_load_zu(&extents->npages, ATOMIC_RELAXED);
|
2017-01-30 13:57:14 +08:00
|
|
|
}
|
|
|
|
|
2018-08-01 00:49:49 +08:00
|
|
|
size_t
|
|
|
|
extents_nextents_get(extents_t *extents, pszind_t pind) {
|
|
|
|
return atomic_load_zu(&extents->nextents[pind], ATOMIC_RELAXED);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
extents_nbytes_get(extents_t *extents, pszind_t pind) {
|
|
|
|
return atomic_load_zu(&extents->nbytes[pind], ATOMIC_RELAXED);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
extents_stats_add(extents_t *extent, pszind_t pind, size_t sz) {
|
|
|
|
size_t cur = atomic_load_zu(&extent->nextents[pind], ATOMIC_RELAXED);
|
|
|
|
atomic_store_zu(&extent->nextents[pind], cur + 1, ATOMIC_RELAXED);
|
|
|
|
cur = atomic_load_zu(&extent->nbytes[pind], ATOMIC_RELAXED);
|
|
|
|
atomic_store_zu(&extent->nbytes[pind], cur + sz, ATOMIC_RELAXED);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
extents_stats_sub(extents_t *extent, pszind_t pind, size_t sz) {
|
|
|
|
size_t cur = atomic_load_zu(&extent->nextents[pind], ATOMIC_RELAXED);
|
|
|
|
atomic_store_zu(&extent->nextents[pind], cur - 1, ATOMIC_RELAXED);
|
|
|
|
cur = atomic_load_zu(&extent->nbytes[pind], ATOMIC_RELAXED);
|
|
|
|
atomic_store_zu(&extent->nbytes[pind], cur - sz, ATOMIC_RELAXED);
|
|
|
|
}
|
|
|
|
|
2016-06-02 03:59:02 +08:00
|
|
|
static void
|
2018-02-23 01:40:27 +08:00
|
|
|
extents_insert_locked(tsdn_t *tsdn, extents_t *extents, extent_t *extent) {
|
2017-01-30 13:57:14 +08:00
|
|
|
malloc_mutex_assert_owner(tsdn, &extents->mtx);
|
|
|
|
assert(extent_state_get(extent) == extents->state);
|
|
|
|
|
|
|
|
size_t size = extent_size_get(extent);
|
|
|
|
size_t psz = extent_size_quantize_floor(size);
|
2017-05-31 01:45:37 +08:00
|
|
|
pszind_t pind = sz_psz2ind(psz);
|
2017-03-24 14:45:11 +08:00
|
|
|
if (extent_heap_empty(&extents->heaps[pind])) {
|
|
|
|
bitmap_unset(extents->bitmap, &extents_bitmap_info,
|
|
|
|
(size_t)pind);
|
|
|
|
}
|
2017-01-30 13:57:14 +08:00
|
|
|
extent_heap_insert(&extents->heaps[pind], extent);
|
2018-08-01 00:49:49 +08:00
|
|
|
|
|
|
|
if (config_stats) {
|
|
|
|
extents_stats_add(extents, pind, size);
|
|
|
|
}
|
|
|
|
|
2018-02-23 01:40:27 +08:00
|
|
|
extent_list_append(&extents->lru, extent);
|
2017-01-30 13:57:14 +08:00
|
|
|
size_t npages = size >> LG_PAGE;
|
2017-03-08 09:57:48 +08:00
|
|
|
/*
|
|
|
|
* All modifications to npages hold the mutex (as asserted above), so we
|
|
|
|
* don't need an atomic fetch-add; we can get by with a load followed by
|
|
|
|
* a store.
|
|
|
|
*/
|
|
|
|
size_t cur_extents_npages =
|
|
|
|
atomic_load_zu(&extents->npages, ATOMIC_RELAXED);
|
|
|
|
atomic_store_zu(&extents->npages, cur_extents_npages + npages,
|
|
|
|
ATOMIC_RELAXED);
|
2017-01-30 13:57:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-02-23 01:40:27 +08:00
|
|
|
extents_remove_locked(tsdn_t *tsdn, extents_t *extents, extent_t *extent) {
|
2017-01-30 13:57:14 +08:00
|
|
|
malloc_mutex_assert_owner(tsdn, &extents->mtx);
|
|
|
|
assert(extent_state_get(extent) == extents->state);
|
|
|
|
|
|
|
|
size_t size = extent_size_get(extent);
|
|
|
|
size_t psz = extent_size_quantize_floor(size);
|
2017-05-31 01:45:37 +08:00
|
|
|
pszind_t pind = sz_psz2ind(psz);
|
2017-01-30 13:57:14 +08:00
|
|
|
extent_heap_remove(&extents->heaps[pind], extent);
|
2018-08-01 00:49:49 +08:00
|
|
|
|
|
|
|
if (config_stats) {
|
|
|
|
extents_stats_sub(extents, pind, size);
|
|
|
|
}
|
|
|
|
|
2017-03-24 14:45:11 +08:00
|
|
|
if (extent_heap_empty(&extents->heaps[pind])) {
|
|
|
|
bitmap_set(extents->bitmap, &extents_bitmap_info,
|
|
|
|
(size_t)pind);
|
|
|
|
}
|
2018-02-23 01:40:27 +08:00
|
|
|
extent_list_remove(&extents->lru, extent);
|
2017-01-30 13:57:14 +08:00
|
|
|
size_t npages = size >> LG_PAGE;
|
2017-03-08 09:57:48 +08:00
|
|
|
/*
|
|
|
|
* As in extents_insert_locked, we hold extents->mtx and so don't need
|
|
|
|
* atomic operations for updating extents->npages.
|
|
|
|
*/
|
|
|
|
size_t cur_extents_npages =
|
|
|
|
atomic_load_zu(&extents->npages, ATOMIC_RELAXED);
|
|
|
|
assert(cur_extents_npages >= npages);
|
|
|
|
atomic_store_zu(&extents->npages,
|
|
|
|
cur_extents_npages - (size >> LG_PAGE), ATOMIC_RELAXED);
|
2017-01-30 13:57:14 +08:00
|
|
|
}
|
|
|
|
|
2017-12-22 08:17:45 +08:00
|
|
|
/*
|
|
|
|
* Find an extent with size [min_size, max_size) to satisfy the alignment
|
|
|
|
* requirement. For each size, try only the first extent in the heap.
|
|
|
|
*/
|
|
|
|
static extent_t *
|
|
|
|
extents_fit_alignment(extents_t *extents, size_t min_size, size_t max_size,
|
|
|
|
size_t alignment) {
|
|
|
|
pszind_t pind = sz_psz2ind(extent_size_quantize_ceil(min_size));
|
|
|
|
pszind_t pind_max = sz_psz2ind(extent_size_quantize_ceil(max_size));
|
|
|
|
|
|
|
|
for (pszind_t i = (pszind_t)bitmap_ffu(extents->bitmap,
|
|
|
|
&extents_bitmap_info, (size_t)pind); i < pind_max; i =
|
|
|
|
(pszind_t)bitmap_ffu(extents->bitmap, &extents_bitmap_info,
|
|
|
|
(size_t)i+1)) {
|
2018-07-20 08:08:10 +08:00
|
|
|
assert(i < SC_NPSIZES);
|
2017-12-22 08:17:45 +08:00
|
|
|
assert(!extent_heap_empty(&extents->heaps[i]));
|
|
|
|
extent_t *extent = extent_heap_first(&extents->heaps[i]);
|
|
|
|
uintptr_t base = (uintptr_t)extent_base_get(extent);
|
|
|
|
size_t candidate_size = extent_size_get(extent);
|
|
|
|
assert(candidate_size >= min_size);
|
|
|
|
|
|
|
|
uintptr_t next_align = ALIGNMENT_CEILING((uintptr_t)base,
|
|
|
|
PAGE_CEILING(alignment));
|
|
|
|
if (base > next_align || base + candidate_size <= next_align) {
|
|
|
|
/* Overflow or not crossing the next alignment. */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t leadsize = next_align - base;
|
|
|
|
if (candidate_size - leadsize >= min_size) {
|
|
|
|
return extent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-03-23 11:06:25 +08:00
|
|
|
/* Do any-best-fit extent selection, i.e. select any extent that best fits. */
|
2017-01-30 13:57:14 +08:00
|
|
|
static extent_t *
|
2017-03-04 14:55:28 +08:00
|
|
|
extents_best_fit_locked(tsdn_t *tsdn, arena_t *arena, extents_t *extents,
|
2017-01-30 13:57:14 +08:00
|
|
|
size_t size) {
|
2017-05-31 01:45:37 +08:00
|
|
|
pszind_t pind = sz_psz2ind(extent_size_quantize_ceil(size));
|
2017-03-24 14:45:11 +08:00
|
|
|
pszind_t i = (pszind_t)bitmap_ffu(extents->bitmap, &extents_bitmap_info,
|
|
|
|
(size_t)pind);
|
2018-07-20 08:08:10 +08:00
|
|
|
if (i < SC_NPSIZES + 1) {
|
2017-11-10 05:51:39 +08:00
|
|
|
/*
|
|
|
|
* In order to reduce fragmentation, avoid reusing and splitting
|
|
|
|
* large extents for much smaller sizes.
|
|
|
|
*/
|
|
|
|
if ((sz_pind2sz(i) >> opt_lg_extent_max_active_fit) > size) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-03-24 14:45:11 +08:00
|
|
|
assert(!extent_heap_empty(&extents->heaps[i]));
|
2017-11-14 03:41:53 +08:00
|
|
|
extent_t *extent = extent_heap_first(&extents->heaps[i]);
|
2017-03-24 14:45:11 +08:00
|
|
|
assert(extent_size_get(extent) >= size);
|
|
|
|
return extent;
|
2017-01-30 13:57:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-03-23 11:06:25 +08:00
|
|
|
/*
|
|
|
|
* Do first-fit extent selection, i.e. select the oldest/lowest extent that is
|
|
|
|
* large enough.
|
|
|
|
*/
|
|
|
|
static extent_t *
|
|
|
|
extents_first_fit_locked(tsdn_t *tsdn, arena_t *arena, extents_t *extents,
|
|
|
|
size_t size) {
|
|
|
|
extent_t *ret = NULL;
|
|
|
|
|
2017-05-31 01:45:37 +08:00
|
|
|
pszind_t pind = sz_psz2ind(extent_size_quantize_ceil(size));
|
2017-03-24 14:45:11 +08:00
|
|
|
for (pszind_t i = (pszind_t)bitmap_ffu(extents->bitmap,
|
2017-12-15 04:46:39 +08:00
|
|
|
&extents_bitmap_info, (size_t)pind);
|
2018-07-20 08:08:10 +08:00
|
|
|
i < SC_NPSIZES + 1;
|
2017-12-15 04:46:39 +08:00
|
|
|
i = (pszind_t)bitmap_ffu(extents->bitmap, &extents_bitmap_info,
|
2017-03-24 14:45:11 +08:00
|
|
|
(size_t)i+1)) {
|
|
|
|
assert(!extent_heap_empty(&extents->heaps[i]));
|
2017-03-23 11:06:25 +08:00
|
|
|
extent_t *extent = extent_heap_first(&extents->heaps[i]);
|
2017-03-24 14:45:11 +08:00
|
|
|
assert(extent_size_get(extent) >= size);
|
|
|
|
if (ret == NULL || extent_snad_comp(extent, ret) < 0) {
|
|
|
|
ret = extent;
|
|
|
|
}
|
2018-07-20 08:08:10 +08:00
|
|
|
if (i == SC_NPSIZES) {
|
2017-03-24 14:45:11 +08:00
|
|
|
break;
|
2017-03-23 11:06:25 +08:00
|
|
|
}
|
2018-07-20 08:08:10 +08:00
|
|
|
assert(i < SC_NPSIZES);
|
2017-03-23 11:06:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do {best,first}-fit extent selection, where the selection policy choice is
|
|
|
|
* based on extents->delay_coalesce. Best-fit selection requires less
|
|
|
|
* searching, but its layout policy is less stable and may cause higher virtual
|
|
|
|
* memory fragmentation as a side effect.
|
|
|
|
*/
|
|
|
|
static extent_t *
|
|
|
|
extents_fit_locked(tsdn_t *tsdn, arena_t *arena, extents_t *extents,
|
2017-12-22 08:17:45 +08:00
|
|
|
size_t esize, size_t alignment) {
|
2017-03-23 11:06:25 +08:00
|
|
|
malloc_mutex_assert_owner(tsdn, &extents->mtx);
|
|
|
|
|
2017-12-22 08:17:45 +08:00
|
|
|
size_t max_size = esize + PAGE_CEILING(alignment) - PAGE;
|
|
|
|
/* Beware size_t wrap-around. */
|
|
|
|
if (max_size < esize) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
extent_t *extent = extents->delay_coalesce ?
|
|
|
|
extents_best_fit_locked(tsdn, arena, extents, max_size) :
|
|
|
|
extents_first_fit_locked(tsdn, arena, extents, max_size);
|
|
|
|
|
|
|
|
if (alignment > PAGE && extent == NULL) {
|
|
|
|
/*
|
|
|
|
* max_size guarantees the alignment requirement but is rather
|
|
|
|
* pessimistic. Next we try to satisfy the aligned allocation
|
|
|
|
* with sizes in [esize, max_size).
|
|
|
|
*/
|
|
|
|
extent = extents_fit_alignment(extents, esize, max_size,
|
|
|
|
alignment);
|
|
|
|
}
|
|
|
|
|
|
|
|
return extent;
|
2017-03-23 11:06:25 +08:00
|
|
|
}
|
|
|
|
|
2017-03-03 10:04:35 +08:00
|
|
|
static bool
|
|
|
|
extent_try_delayed_coalesce(tsdn_t *tsdn, arena_t *arena,
|
|
|
|
extent_hooks_t **r_extent_hooks, rtree_ctx_t *rtree_ctx, extents_t *extents,
|
|
|
|
extent_t *extent) {
|
|
|
|
extent_state_set(extent, extent_state_active);
|
|
|
|
bool coalesced;
|
|
|
|
extent = extent_try_coalesce(tsdn, arena, r_extent_hooks, rtree_ctx,
|
2017-05-27 02:06:01 +08:00
|
|
|
extents, extent, &coalesced, false);
|
2017-03-03 10:04:35 +08:00
|
|
|
extent_state_set(extent, extents_state_get(extents));
|
|
|
|
|
|
|
|
if (!coalesced) {
|
|
|
|
return true;
|
|
|
|
}
|
2018-02-23 01:40:27 +08:00
|
|
|
extents_insert_locked(tsdn, extents, extent);
|
2017-03-03 10:04:35 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
Implement two-phase decay-based purging.
Split decay-based purging into two phases, the first of which uses lazy
purging to convert dirty pages to "muzzy", and the second of which uses
forced purging, decommit, or unmapping to convert pages to clean or
destroy them altogether. Not all operating systems support lazy
purging, yet the application may provide extent hooks that implement
lazy purging, so care must be taken to dynamically omit the first phase
when necessary.
The mallctl interfaces change as follows:
- opt.decay_time --> opt.{dirty,muzzy}_decay_time
- arena.<i>.decay_time --> arena.<i>.{dirty,muzzy}_decay_time
- arenas.decay_time --> arenas.{dirty,muzzy}_decay_time
- stats.arenas.<i>.pdirty --> stats.arenas.<i>.p{dirty,muzzy}
- stats.arenas.<i>.{npurge,nmadvise,purged} -->
stats.arenas.<i>.{dirty,muzzy}_{npurge,nmadvise,purged}
This resolves #521.
2017-03-09 14:42:57 +08:00
|
|
|
extent_t *
|
|
|
|
extents_alloc(tsdn_t *tsdn, arena_t *arena, extent_hooks_t **r_extent_hooks,
|
2017-03-14 08:36:57 +08:00
|
|
|
extents_t *extents, void *new_addr, size_t size, size_t pad,
|
|
|
|
size_t alignment, bool slab, szind_t szind, bool *zero, bool *commit) {
|
|
|
|
assert(size + pad != 0);
|
Implement two-phase decay-based purging.
Split decay-based purging into two phases, the first of which uses lazy
purging to convert dirty pages to "muzzy", and the second of which uses
forced purging, decommit, or unmapping to convert pages to clean or
destroy them altogether. Not all operating systems support lazy
purging, yet the application may provide extent hooks that implement
lazy purging, so care must be taken to dynamically omit the first phase
when necessary.
The mallctl interfaces change as follows:
- opt.decay_time --> opt.{dirty,muzzy}_decay_time
- arena.<i>.decay_time --> arena.<i>.{dirty,muzzy}_decay_time
- arenas.decay_time --> arenas.{dirty,muzzy}_decay_time
- stats.arenas.<i>.pdirty --> stats.arenas.<i>.p{dirty,muzzy}
- stats.arenas.<i>.{npurge,nmadvise,purged} -->
stats.arenas.<i>.{dirty,muzzy}_{npurge,nmadvise,purged}
This resolves #521.
2017-03-09 14:42:57 +08:00
|
|
|
assert(alignment != 0);
|
2017-05-23 10:32:04 +08:00
|
|
|
witness_assert_depth_to_rank(tsdn_witness_tsdp_get(tsdn),
|
|
|
|
WITNESS_RANK_CORE, 0);
|
Implement two-phase decay-based purging.
Split decay-based purging into two phases, the first of which uses lazy
purging to convert dirty pages to "muzzy", and the second of which uses
forced purging, decommit, or unmapping to convert pages to clean or
destroy them altogether. Not all operating systems support lazy
purging, yet the application may provide extent hooks that implement
lazy purging, so care must be taken to dynamically omit the first phase
when necessary.
The mallctl interfaces change as follows:
- opt.decay_time --> opt.{dirty,muzzy}_decay_time
- arena.<i>.decay_time --> arena.<i>.{dirty,muzzy}_decay_time
- arenas.decay_time --> arenas.{dirty,muzzy}_decay_time
- stats.arenas.<i>.pdirty --> stats.arenas.<i>.p{dirty,muzzy}
- stats.arenas.<i>.{npurge,nmadvise,purged} -->
stats.arenas.<i>.{dirty,muzzy}_{npurge,nmadvise,purged}
This resolves #521.
2017-03-09 14:42:57 +08:00
|
|
|
|
2017-09-19 08:25:57 +08:00
|
|
|
extent_t *extent = extent_recycle(tsdn, arena, r_extent_hooks, extents,
|
|
|
|
new_addr, size, pad, alignment, slab, szind, zero, commit, false);
|
|
|
|
assert(extent == NULL || extent_dumpable_get(extent));
|
|
|
|
return extent;
|
Implement two-phase decay-based purging.
Split decay-based purging into two phases, the first of which uses lazy
purging to convert dirty pages to "muzzy", and the second of which uses
forced purging, decommit, or unmapping to convert pages to clean or
destroy them altogether. Not all operating systems support lazy
purging, yet the application may provide extent hooks that implement
lazy purging, so care must be taken to dynamically omit the first phase
when necessary.
The mallctl interfaces change as follows:
- opt.decay_time --> opt.{dirty,muzzy}_decay_time
- arena.<i>.decay_time --> arena.<i>.{dirty,muzzy}_decay_time
- arenas.decay_time --> arenas.{dirty,muzzy}_decay_time
- stats.arenas.<i>.pdirty --> stats.arenas.<i>.p{dirty,muzzy}
- stats.arenas.<i>.{npurge,nmadvise,purged} -->
stats.arenas.<i>.{dirty,muzzy}_{npurge,nmadvise,purged}
This resolves #521.
2017-03-09 14:42:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
extents_dalloc(tsdn_t *tsdn, arena_t *arena, extent_hooks_t **r_extent_hooks,
|
|
|
|
extents_t *extents, extent_t *extent) {
|
|
|
|
assert(extent_base_get(extent) != NULL);
|
|
|
|
assert(extent_size_get(extent) != 0);
|
2017-09-19 08:25:57 +08:00
|
|
|
assert(extent_dumpable_get(extent));
|
2017-05-23 10:32:04 +08:00
|
|
|
witness_assert_depth_to_rank(tsdn_witness_tsdp_get(tsdn),
|
|
|
|
WITNESS_RANK_CORE, 0);
|
Implement two-phase decay-based purging.
Split decay-based purging into two phases, the first of which uses lazy
purging to convert dirty pages to "muzzy", and the second of which uses
forced purging, decommit, or unmapping to convert pages to clean or
destroy them altogether. Not all operating systems support lazy
purging, yet the application may provide extent hooks that implement
lazy purging, so care must be taken to dynamically omit the first phase
when necessary.
The mallctl interfaces change as follows:
- opt.decay_time --> opt.{dirty,muzzy}_decay_time
- arena.<i>.decay_time --> arena.<i>.{dirty,muzzy}_decay_time
- arenas.decay_time --> arenas.{dirty,muzzy}_decay_time
- stats.arenas.<i>.pdirty --> stats.arenas.<i>.p{dirty,muzzy}
- stats.arenas.<i>.{npurge,nmadvise,purged} -->
stats.arenas.<i>.{dirty,muzzy}_{npurge,nmadvise,purged}
This resolves #521.
2017-03-09 14:42:57 +08:00
|
|
|
|
|
|
|
extent_addr_set(extent, extent_base_get(extent));
|
|
|
|
extent_zeroed_set(extent, false);
|
|
|
|
|
2017-05-27 02:06:01 +08:00
|
|
|
extent_record(tsdn, arena, r_extent_hooks, extents, extent, false);
|
Implement two-phase decay-based purging.
Split decay-based purging into two phases, the first of which uses lazy
purging to convert dirty pages to "muzzy", and the second of which uses
forced purging, decommit, or unmapping to convert pages to clean or
destroy them altogether. Not all operating systems support lazy
purging, yet the application may provide extent hooks that implement
lazy purging, so care must be taken to dynamically omit the first phase
when necessary.
The mallctl interfaces change as follows:
- opt.decay_time --> opt.{dirty,muzzy}_decay_time
- arena.<i>.decay_time --> arena.<i>.{dirty,muzzy}_decay_time
- arenas.decay_time --> arenas.{dirty,muzzy}_decay_time
- stats.arenas.<i>.pdirty --> stats.arenas.<i>.p{dirty,muzzy}
- stats.arenas.<i>.{npurge,nmadvise,purged} -->
stats.arenas.<i>.{dirty,muzzy}_{npurge,nmadvise,purged}
This resolves #521.
2017-03-09 14:42:57 +08:00
|
|
|
}
|
|
|
|
|
2017-01-30 13:57:14 +08:00
|
|
|
extent_t *
|
2017-03-03 10:04:35 +08:00
|
|
|
extents_evict(tsdn_t *tsdn, arena_t *arena, extent_hooks_t **r_extent_hooks,
|
2017-12-09 04:13:50 +08:00
|
|
|
extents_t *extents, size_t npages_min) {
|
2017-03-03 10:04:35 +08:00
|
|
|
rtree_ctx_t rtree_ctx_fallback;
|
|
|
|
rtree_ctx_t *rtree_ctx = tsdn_rtree_ctx(tsdn, &rtree_ctx_fallback);
|
|
|
|
|
2017-01-30 13:57:14 +08:00
|
|
|
malloc_mutex_lock(tsdn, &extents->mtx);
|
|
|
|
|
2017-03-03 10:04:35 +08:00
|
|
|
/*
|
|
|
|
* Get the LRU coalesced extent, if any. If coalescing was delayed,
|
|
|
|
* the loop will iterate until the LRU extent is fully coalesced.
|
|
|
|
*/
|
|
|
|
extent_t *extent;
|
|
|
|
while (true) {
|
|
|
|
/* Get the LRU extent, if any. */
|
|
|
|
extent = extent_list_first(&extents->lru);
|
|
|
|
if (extent == NULL) {
|
|
|
|
goto label_return;
|
|
|
|
}
|
|
|
|
/* Check the eviction limit. */
|
2017-03-08 09:57:48 +08:00
|
|
|
size_t extents_npages = atomic_load_zu(&extents->npages,
|
|
|
|
ATOMIC_RELAXED);
|
2017-12-09 04:13:50 +08:00
|
|
|
if (extents_npages <= npages_min) {
|
2017-03-03 10:04:35 +08:00
|
|
|
extent = NULL;
|
|
|
|
goto label_return;
|
|
|
|
}
|
2018-02-23 01:40:27 +08:00
|
|
|
extents_remove_locked(tsdn, extents, extent);
|
2017-03-03 10:04:35 +08:00
|
|
|
if (!extents->delay_coalesce) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* Try to coalesce. */
|
|
|
|
if (extent_try_delayed_coalesce(tsdn, arena, r_extent_hooks,
|
|
|
|
rtree_ctx, extents, extent)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* The LRU extent was just coalesced and the result placed in
|
|
|
|
* the LRU at its neighbor's position. Start over.
|
|
|
|
*/
|
2017-01-30 13:57:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Either mark the extent active or deregister it to protect against
|
|
|
|
* concurrent operations.
|
|
|
|
*/
|
|
|
|
switch (extents_state_get(extents)) {
|
Implement two-phase decay-based purging.
Split decay-based purging into two phases, the first of which uses lazy
purging to convert dirty pages to "muzzy", and the second of which uses
forced purging, decommit, or unmapping to convert pages to clean or
destroy them altogether. Not all operating systems support lazy
purging, yet the application may provide extent hooks that implement
lazy purging, so care must be taken to dynamically omit the first phase
when necessary.
The mallctl interfaces change as follows:
- opt.decay_time --> opt.{dirty,muzzy}_decay_time
- arena.<i>.decay_time --> arena.<i>.{dirty,muzzy}_decay_time
- arenas.decay_time --> arenas.{dirty,muzzy}_decay_time
- stats.arenas.<i>.pdirty --> stats.arenas.<i>.p{dirty,muzzy}
- stats.arenas.<i>.{npurge,nmadvise,purged} -->
stats.arenas.<i>.{dirty,muzzy}_{npurge,nmadvise,purged}
This resolves #521.
2017-03-09 14:42:57 +08:00
|
|
|
case extent_state_active:
|
|
|
|
not_reached();
|
2017-01-30 13:57:14 +08:00
|
|
|
case extent_state_dirty:
|
Implement two-phase decay-based purging.
Split decay-based purging into two phases, the first of which uses lazy
purging to convert dirty pages to "muzzy", and the second of which uses
forced purging, decommit, or unmapping to convert pages to clean or
destroy them altogether. Not all operating systems support lazy
purging, yet the application may provide extent hooks that implement
lazy purging, so care must be taken to dynamically omit the first phase
when necessary.
The mallctl interfaces change as follows:
- opt.decay_time --> opt.{dirty,muzzy}_decay_time
- arena.<i>.decay_time --> arena.<i>.{dirty,muzzy}_decay_time
- arenas.decay_time --> arenas.{dirty,muzzy}_decay_time
- stats.arenas.<i>.pdirty --> stats.arenas.<i>.p{dirty,muzzy}
- stats.arenas.<i>.{npurge,nmadvise,purged} -->
stats.arenas.<i>.{dirty,muzzy}_{npurge,nmadvise,purged}
This resolves #521.
2017-03-09 14:42:57 +08:00
|
|
|
case extent_state_muzzy:
|
2017-01-30 13:57:14 +08:00
|
|
|
extent_state_set(extent, extent_state_active);
|
|
|
|
break;
|
|
|
|
case extent_state_retained:
|
|
|
|
extent_deregister(tsdn, extent);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
not_reached();
|
|
|
|
}
|
|
|
|
|
|
|
|
label_return:
|
|
|
|
malloc_mutex_unlock(tsdn, &extents->mtx);
|
|
|
|
return extent;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
extents_leak(tsdn_t *tsdn, arena_t *arena, extent_hooks_t **r_extent_hooks,
|
2017-05-27 02:06:01 +08:00
|
|
|
extents_t *extents, extent_t *extent, bool growing_retained) {
|
2017-01-30 13:57:14 +08:00
|
|
|
/*
|
|
|
|
* Leak extent after making sure its pages have already been purged, so
|
|
|
|
* that this is only a virtual memory leak.
|
|
|
|
*/
|
|
|
|
if (extents_state_get(extents) == extent_state_dirty) {
|
2017-05-27 02:06:01 +08:00
|
|
|
if (extent_purge_lazy_impl(tsdn, arena, r_extent_hooks,
|
|
|
|
extent, 0, extent_size_get(extent), growing_retained)) {
|
|
|
|
extent_purge_forced_impl(tsdn, arena, r_extent_hooks,
|
|
|
|
extent, 0, extent_size_get(extent),
|
|
|
|
growing_retained);
|
2017-01-30 13:57:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
extent_dalloc(tsdn, arena, extent);
|
|
|
|
}
|
2016-09-23 02:57:28 +08:00
|
|
|
|
2017-01-30 13:57:14 +08:00
|
|
|
void
|
|
|
|
extents_prefork(tsdn_t *tsdn, extents_t *extents) {
|
|
|
|
malloc_mutex_prefork(tsdn, &extents->mtx);
|
|
|
|
}
|
2016-09-23 02:57:28 +08:00
|
|
|
|
2017-01-30 13:57:14 +08:00
|
|
|
void
|
|
|
|
extents_postfork_parent(tsdn_t *tsdn, extents_t *extents) {
|
|
|
|
malloc_mutex_postfork_parent(tsdn, &extents->mtx);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
extents_postfork_child(tsdn_t *tsdn, extents_t *extents) {
|
|
|
|
malloc_mutex_postfork_child(tsdn, &extents->mtx);
|
2016-06-02 03:59:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-01-30 13:57:14 +08:00
|
|
|
extent_deactivate_locked(tsdn_t *tsdn, arena_t *arena, extents_t *extents,
|
2018-02-23 01:40:27 +08:00
|
|
|
extent_t *extent) {
|
2017-01-30 13:57:14 +08:00
|
|
|
assert(extent_arena_get(extent) == arena);
|
|
|
|
assert(extent_state_get(extent) == extent_state_active);
|
2016-09-23 02:57:28 +08:00
|
|
|
|
2017-01-30 13:57:14 +08:00
|
|
|
extent_state_set(extent, extents_state_get(extents));
|
2018-02-23 01:40:27 +08:00
|
|
|
extents_insert_locked(tsdn, extents, extent);
|
2017-01-30 13:57:14 +08:00
|
|
|
}
|
2016-09-23 02:57:28 +08:00
|
|
|
|
2017-01-30 13:57:14 +08:00
|
|
|
static void
|
|
|
|
extent_deactivate(tsdn_t *tsdn, arena_t *arena, extents_t *extents,
|
2018-02-23 01:40:27 +08:00
|
|
|
extent_t *extent) {
|
2017-01-30 13:57:14 +08:00
|
|
|
malloc_mutex_lock(tsdn, &extents->mtx);
|
2018-02-23 01:40:27 +08:00
|
|
|
extent_deactivate_locked(tsdn, arena, extents, extent);
|
2017-01-30 13:57:14 +08:00
|
|
|
malloc_mutex_unlock(tsdn, &extents->mtx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
extent_activate_locked(tsdn_t *tsdn, arena_t *arena, extents_t *extents,
|
2018-02-23 01:40:27 +08:00
|
|
|
extent_t *extent) {
|
2017-01-30 13:57:14 +08:00
|
|
|
assert(extent_arena_get(extent) == arena);
|
|
|
|
assert(extent_state_get(extent) == extents_state_get(extents));
|
|
|
|
|
2018-02-23 01:40:27 +08:00
|
|
|
extents_remove_locked(tsdn, extents, extent);
|
2017-01-30 13:57:14 +08:00
|
|
|
extent_state_set(extent, extent_state_active);
|
2016-06-02 03:59:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
2017-05-16 05:23:51 +08:00
|
|
|
extent_rtree_leaf_elms_lookup(tsdn_t *tsdn, rtree_ctx_t *rtree_ctx,
|
2016-06-03 09:43:10 +08:00
|
|
|
const extent_t *extent, bool dependent, bool init_missing,
|
2017-03-17 00:46:42 +08:00
|
|
|
rtree_leaf_elm_t **r_elm_a, rtree_leaf_elm_t **r_elm_b) {
|
2017-05-16 05:23:51 +08:00
|
|
|
*r_elm_a = rtree_leaf_elm_lookup(tsdn, &extents_rtree, rtree_ctx,
|
2016-06-02 03:59:02 +08:00
|
|
|
(uintptr_t)extent_base_get(extent), dependent, init_missing);
|
2017-01-16 08:56:30 +08:00
|
|
|
if (!dependent && *r_elm_a == NULL) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return true;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2016-06-02 03:59:02 +08:00
|
|
|
assert(*r_elm_a != NULL);
|
|
|
|
|
2017-05-16 05:23:51 +08:00
|
|
|
*r_elm_b = rtree_leaf_elm_lookup(tsdn, &extents_rtree, rtree_ctx,
|
|
|
|
(uintptr_t)extent_last_get(extent), dependent, init_missing);
|
|
|
|
if (!dependent && *r_elm_b == NULL) {
|
|
|
|
return true;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2017-05-16 05:23:51 +08:00
|
|
|
assert(*r_elm_b != NULL);
|
2016-06-02 03:59:02 +08:00
|
|
|
|
2017-01-20 10:15:45 +08:00
|
|
|
return false;
|
2016-06-02 03:59:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-03-17 00:46:42 +08:00
|
|
|
extent_rtree_write_acquired(tsdn_t *tsdn, rtree_leaf_elm_t *elm_a,
|
2017-03-17 08:57:52 +08:00
|
|
|
rtree_leaf_elm_t *elm_b, extent_t *extent, szind_t szind, bool slab) {
|
2017-05-16 05:23:51 +08:00
|
|
|
rtree_leaf_elm_write(tsdn, &extents_rtree, elm_a, extent, szind, slab);
|
2017-01-16 08:56:30 +08:00
|
|
|
if (elm_b != NULL) {
|
2017-05-16 05:23:51 +08:00
|
|
|
rtree_leaf_elm_write(tsdn, &extents_rtree, elm_b, extent, szind,
|
|
|
|
slab);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2016-06-02 03:59:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-03-17 08:57:52 +08:00
|
|
|
extent_interior_register(tsdn_t *tsdn, rtree_ctx_t *rtree_ctx, extent_t *extent,
|
|
|
|
szind_t szind) {
|
2016-06-02 03:59:02 +08:00
|
|
|
assert(extent_slab_get(extent));
|
|
|
|
|
2017-03-17 08:57:52 +08:00
|
|
|
/* Register interior. */
|
|
|
|
for (size_t i = 1; i < (extent_size_get(extent) >> LG_PAGE) - 1; i++) {
|
2016-06-03 09:43:10 +08:00
|
|
|
rtree_write(tsdn, &extents_rtree, rtree_ctx,
|
2016-06-02 03:59:02 +08:00
|
|
|
(uintptr_t)extent_base_get(extent) + (uintptr_t)(i <<
|
2017-03-17 08:57:52 +08:00
|
|
|
LG_PAGE), extent, szind, true);
|
2016-06-02 03:59:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-22 15:23:03 +08:00
|
|
|
static void
|
2017-01-30 13:57:14 +08:00
|
|
|
extent_gdump_add(tsdn_t *tsdn, const extent_t *extent) {
|
2016-11-22 15:23:03 +08:00
|
|
|
cassert(config_prof);
|
2017-01-30 13:57:14 +08:00
|
|
|
/* prof_gdump() requirement. */
|
2017-05-23 10:32:04 +08:00
|
|
|
witness_assert_depth_to_rank(tsdn_witness_tsdp_get(tsdn),
|
|
|
|
WITNESS_RANK_CORE, 0);
|
2016-06-02 03:59:02 +08:00
|
|
|
|
2017-01-30 13:57:14 +08:00
|
|
|
if (opt_prof && extent_state_get(extent) == extent_state_active) {
|
2016-06-06 05:43:20 +08:00
|
|
|
size_t nadd = extent_size_get(extent) >> LG_PAGE;
|
2017-04-05 09:20:42 +08:00
|
|
|
size_t cur = atomic_fetch_add_zu(&curpages, nadd,
|
|
|
|
ATOMIC_RELAXED) + nadd;
|
|
|
|
size_t high = atomic_load_zu(&highpages, ATOMIC_RELAXED);
|
|
|
|
while (cur > high && !atomic_compare_exchange_weak_zu(
|
|
|
|
&highpages, &high, cur, ATOMIC_RELAXED, ATOMIC_RELAXED)) {
|
2016-06-02 03:59:02 +08:00
|
|
|
/*
|
|
|
|
* Don't refresh cur, because it may have decreased
|
2016-06-06 05:43:20 +08:00
|
|
|
* since this thread lost the highpages update race.
|
2017-04-05 09:20:42 +08:00
|
|
|
* Note that high is updated in case of CAS failure.
|
2016-06-02 03:59:02 +08:00
|
|
|
*/
|
|
|
|
}
|
2017-01-16 08:56:30 +08:00
|
|
|
if (cur > high && prof_gdump_get_unlocked()) {
|
2016-06-02 03:59:02 +08:00
|
|
|
prof_gdump(tsdn);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2016-06-02 03:59:02 +08:00
|
|
|
}
|
2016-11-22 15:23:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-01-30 13:57:14 +08:00
|
|
|
extent_gdump_sub(tsdn_t *tsdn, const extent_t *extent) {
|
2016-11-22 15:23:03 +08:00
|
|
|
cassert(config_prof);
|
|
|
|
|
2017-01-30 13:57:14 +08:00
|
|
|
if (opt_prof && extent_state_get(extent) == extent_state_active) {
|
2016-11-22 15:23:03 +08:00
|
|
|
size_t nsub = extent_size_get(extent) >> LG_PAGE;
|
2017-04-05 09:20:42 +08:00
|
|
|
assert(atomic_load_zu(&curpages, ATOMIC_RELAXED) >= nsub);
|
|
|
|
atomic_fetch_sub_zu(&curpages, nsub, ATOMIC_RELAXED);
|
2016-11-22 15:23:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
2017-03-17 08:57:52 +08:00
|
|
|
extent_register_impl(tsdn_t *tsdn, extent_t *extent, bool gdump_add) {
|
2016-11-22 15:23:03 +08:00
|
|
|
rtree_ctx_t rtree_ctx_fallback;
|
|
|
|
rtree_ctx_t *rtree_ctx = tsdn_rtree_ctx(tsdn, &rtree_ctx_fallback);
|
2017-03-17 00:46:42 +08:00
|
|
|
rtree_leaf_elm_t *elm_a, *elm_b;
|
2016-11-22 15:23:03 +08:00
|
|
|
|
2017-05-16 05:23:51 +08:00
|
|
|
/*
|
|
|
|
* We need to hold the lock to protect against a concurrent coalesce
|
|
|
|
* operation that sees us in a partial state.
|
|
|
|
*/
|
|
|
|
extent_lock(tsdn, extent);
|
|
|
|
|
|
|
|
if (extent_rtree_leaf_elms_lookup(tsdn, rtree_ctx, extent, false, true,
|
|
|
|
&elm_a, &elm_b)) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return true;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2017-05-16 05:23:51 +08:00
|
|
|
|
2017-03-17 08:57:52 +08:00
|
|
|
szind_t szind = extent_szind_get_maybe_invalid(extent);
|
|
|
|
bool slab = extent_slab_get(extent);
|
|
|
|
extent_rtree_write_acquired(tsdn, elm_a, elm_b, extent, szind, slab);
|
|
|
|
if (slab) {
|
|
|
|
extent_interior_register(tsdn, rtree_ctx, extent, szind);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2017-05-16 05:23:51 +08:00
|
|
|
|
|
|
|
extent_unlock(tsdn, extent);
|
2016-11-22 15:23:03 +08:00
|
|
|
|
2017-02-04 16:43:32 +08:00
|
|
|
if (config_prof && gdump_add) {
|
2017-01-30 13:57:14 +08:00
|
|
|
extent_gdump_add(tsdn, extent);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2016-06-02 03:59:02 +08:00
|
|
|
|
2017-01-20 10:15:45 +08:00
|
|
|
return false;
|
2016-06-02 03:59:02 +08:00
|
|
|
}
|
|
|
|
|
2017-02-04 16:43:32 +08:00
|
|
|
static bool
|
2017-03-17 08:57:52 +08:00
|
|
|
extent_register(tsdn_t *tsdn, extent_t *extent) {
|
2017-02-04 16:43:32 +08:00
|
|
|
return extent_register_impl(tsdn, extent, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
2017-03-17 08:57:52 +08:00
|
|
|
extent_register_no_gdump_add(tsdn_t *tsdn, extent_t *extent) {
|
2017-02-04 16:43:32 +08:00
|
|
|
return extent_register_impl(tsdn, extent, false);
|
|
|
|
}
|
|
|
|
|
2016-06-06 11:39:25 +08:00
|
|
|
static void
|
2017-03-17 08:57:52 +08:00
|
|
|
extent_reregister(tsdn_t *tsdn, extent_t *extent) {
|
2016-06-06 11:39:25 +08:00
|
|
|
bool err = extent_register(tsdn, extent);
|
|
|
|
assert(!err);
|
|
|
|
}
|
|
|
|
|
2017-08-29 09:27:12 +08:00
|
|
|
/*
|
|
|
|
* Removes all pointers to the given extent from the global rtree indices for
|
|
|
|
* its interior. This is relevant for slab extents, for which we need to do
|
|
|
|
* metadata lookups at places other than the head of the extent. We deregister
|
|
|
|
* on the interior, then, when an extent moves from being an active slab to an
|
|
|
|
* inactive state.
|
|
|
|
*/
|
2016-06-02 03:59:02 +08:00
|
|
|
static void
|
2016-06-03 09:43:10 +08:00
|
|
|
extent_interior_deregister(tsdn_t *tsdn, rtree_ctx_t *rtree_ctx,
|
2017-03-17 08:57:52 +08:00
|
|
|
extent_t *extent) {
|
2016-06-02 03:59:02 +08:00
|
|
|
size_t i;
|
|
|
|
|
|
|
|
assert(extent_slab_get(extent));
|
|
|
|
|
|
|
|
for (i = 1; i < (extent_size_get(extent) >> LG_PAGE) - 1; i++) {
|
2016-06-03 09:43:10 +08:00
|
|
|
rtree_clear(tsdn, &extents_rtree, rtree_ctx,
|
2016-06-02 03:59:02 +08:00
|
|
|
(uintptr_t)extent_base_get(extent) + (uintptr_t)(i <<
|
|
|
|
LG_PAGE));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-29 09:27:12 +08:00
|
|
|
/*
|
|
|
|
* Removes all pointers to the given extent from the global rtree.
|
|
|
|
*/
|
2016-06-02 03:59:02 +08:00
|
|
|
static void
|
2017-12-09 07:06:08 +08:00
|
|
|
extent_deregister_impl(tsdn_t *tsdn, extent_t *extent, bool gdump) {
|
2016-06-03 09:43:10 +08:00
|
|
|
rtree_ctx_t rtree_ctx_fallback;
|
|
|
|
rtree_ctx_t *rtree_ctx = tsdn_rtree_ctx(tsdn, &rtree_ctx_fallback);
|
2017-03-17 00:46:42 +08:00
|
|
|
rtree_leaf_elm_t *elm_a, *elm_b;
|
2017-05-16 05:23:51 +08:00
|
|
|
extent_rtree_leaf_elms_lookup(tsdn, rtree_ctx, extent, true, false,
|
|
|
|
&elm_a, &elm_b);
|
|
|
|
|
|
|
|
extent_lock(tsdn, extent);
|
2016-06-02 03:59:02 +08:00
|
|
|
|
2017-12-15 04:46:39 +08:00
|
|
|
extent_rtree_write_acquired(tsdn, elm_a, elm_b, NULL, SC_NSIZES, false);
|
2016-06-06 11:39:25 +08:00
|
|
|
if (extent_slab_get(extent)) {
|
2016-06-03 09:43:10 +08:00
|
|
|
extent_interior_deregister(tsdn, rtree_ctx, extent);
|
2016-06-06 11:39:25 +08:00
|
|
|
extent_slab_set(extent, false);
|
|
|
|
}
|
2017-05-16 05:23:51 +08:00
|
|
|
|
|
|
|
extent_unlock(tsdn, extent);
|
2016-06-02 03:59:02 +08:00
|
|
|
|
2017-12-09 07:06:08 +08:00
|
|
|
if (config_prof && gdump) {
|
2017-01-30 13:57:14 +08:00
|
|
|
extent_gdump_sub(tsdn, extent);
|
2016-06-02 03:59:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-09 07:06:08 +08:00
|
|
|
static void
|
|
|
|
extent_deregister(tsdn_t *tsdn, extent_t *extent) {
|
|
|
|
extent_deregister_impl(tsdn, extent, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
extent_deregister_no_gdump_sub(tsdn_t *tsdn, extent_t *extent) {
|
|
|
|
extent_deregister_impl(tsdn, extent, false);
|
|
|
|
}
|
|
|
|
|
2017-08-29 09:27:12 +08:00
|
|
|
/*
|
|
|
|
* Tries to find and remove an extent from extents that can be used for the
|
|
|
|
* given allocation request.
|
|
|
|
*/
|
2016-06-02 03:59:02 +08:00
|
|
|
static extent_t *
|
2017-01-30 13:57:14 +08:00
|
|
|
extent_recycle_extract(tsdn_t *tsdn, arena_t *arena,
|
|
|
|
extent_hooks_t **r_extent_hooks, rtree_ctx_t *rtree_ctx, extents_t *extents,
|
2017-05-27 02:06:01 +08:00
|
|
|
void *new_addr, size_t size, size_t pad, size_t alignment, bool slab,
|
2017-11-17 06:27:23 +08:00
|
|
|
bool growing_retained) {
|
2017-05-23 10:32:04 +08:00
|
|
|
witness_assert_depth_to_rank(tsdn_witness_tsdp_get(tsdn),
|
2017-05-27 02:06:01 +08:00
|
|
|
WITNESS_RANK_CORE, growing_retained ? 1 : 0);
|
2016-11-04 14:49:21 +08:00
|
|
|
assert(alignment > 0);
|
2016-09-24 03:11:01 +08:00
|
|
|
if (config_debug && new_addr != NULL) {
|
|
|
|
/*
|
|
|
|
* Non-NULL new_addr has two use cases:
|
|
|
|
*
|
|
|
|
* 1) Recycle a known-extant extent, e.g. during purging.
|
|
|
|
* 2) Perform in-place expanding reallocation.
|
|
|
|
*
|
|
|
|
* Regardless of use case, new_addr must either refer to a
|
|
|
|
* non-existing extent, or to the base of an extant extent,
|
|
|
|
* since only active slabs support interior lookups (which of
|
|
|
|
* course cannot be recycled).
|
|
|
|
*/
|
|
|
|
assert(PAGE_ADDR2BASE(new_addr) == new_addr);
|
2016-10-04 05:18:55 +08:00
|
|
|
assert(pad == 0);
|
|
|
|
assert(alignment <= PAGE);
|
2016-09-24 03:11:01 +08:00
|
|
|
}
|
2016-06-02 03:59:02 +08:00
|
|
|
|
2017-03-14 08:36:57 +08:00
|
|
|
size_t esize = size + pad;
|
2017-05-27 02:06:01 +08:00
|
|
|
malloc_mutex_lock(tsdn, &extents->mtx);
|
2016-06-04 03:05:53 +08:00
|
|
|
extent_hooks_assure_initialized(arena, r_extent_hooks);
|
2017-01-30 13:57:14 +08:00
|
|
|
extent_t *extent;
|
2016-06-02 03:59:02 +08:00
|
|
|
if (new_addr != NULL) {
|
2017-05-16 05:23:51 +08:00
|
|
|
extent = extent_lock_from_addr(tsdn, rtree_ctx, new_addr);
|
|
|
|
if (extent != NULL) {
|
|
|
|
/*
|
|
|
|
* We might null-out extent to report an error, but we
|
|
|
|
* still need to unlock the associated mutex after.
|
|
|
|
*/
|
|
|
|
extent_t *unlock_extent = extent;
|
|
|
|
assert(extent_base_get(extent) == new_addr);
|
|
|
|
if (extent_arena_get(extent) != arena ||
|
|
|
|
extent_size_get(extent) < esize ||
|
|
|
|
extent_state_get(extent) !=
|
|
|
|
extents_state_get(extents)) {
|
|
|
|
extent = NULL;
|
2016-09-24 03:11:01 +08:00
|
|
|
}
|
2017-05-16 05:23:51 +08:00
|
|
|
extent_unlock(tsdn, unlock_extent);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2016-09-24 03:18:36 +08:00
|
|
|
} else {
|
2017-12-22 08:17:45 +08:00
|
|
|
extent = extents_fit_locked(tsdn, arena, extents, esize,
|
|
|
|
alignment);
|
2016-09-24 03:18:36 +08:00
|
|
|
}
|
2016-09-24 03:11:01 +08:00
|
|
|
if (extent == NULL) {
|
2017-05-27 02:06:01 +08:00
|
|
|
malloc_mutex_unlock(tsdn, &extents->mtx);
|
2017-01-20 10:15:45 +08:00
|
|
|
return NULL;
|
2016-06-02 03:59:02 +08:00
|
|
|
}
|
|
|
|
|
2018-02-23 01:40:27 +08:00
|
|
|
extent_activate_locked(tsdn, arena, extents, extent);
|
2017-05-27 02:06:01 +08:00
|
|
|
malloc_mutex_unlock(tsdn, &extents->mtx);
|
2017-01-30 13:57:14 +08:00
|
|
|
|
|
|
|
return extent;
|
|
|
|
}
|
|
|
|
|
2017-08-29 09:27:12 +08:00
|
|
|
/*
|
2017-08-30 07:50:57 +08:00
|
|
|
* Given an allocation request and an extent guaranteed to be able to satisfy
|
|
|
|
* it, this splits off lead and trail extents, leaving extent pointing to an
|
|
|
|
* extent satisfying the allocation.
|
|
|
|
* This function doesn't put lead or trail into any extents_t; it's the caller's
|
|
|
|
* job to ensure that they can be reused.
|
2017-08-29 09:27:12 +08:00
|
|
|
*/
|
2017-08-30 07:50:57 +08:00
|
|
|
typedef enum {
|
|
|
|
/*
|
|
|
|
* Split successfully. lead, extent, and trail, are modified to extents
|
|
|
|
* describing the ranges before, in, and after the given allocation.
|
|
|
|
*/
|
|
|
|
extent_split_interior_ok,
|
|
|
|
/*
|
|
|
|
* The extent can't satisfy the given allocation request. None of the
|
|
|
|
* input extent_t *s are touched.
|
|
|
|
*/
|
|
|
|
extent_split_interior_cant_alloc,
|
|
|
|
/*
|
|
|
|
* In a potentially invalid state. Must leak (if *to_leak is non-NULL),
|
|
|
|
* and salvage what's still salvageable (if *to_salvage is non-NULL).
|
|
|
|
* None of lead, extent, or trail are valid.
|
|
|
|
*/
|
|
|
|
extent_split_interior_error
|
|
|
|
} extent_split_interior_result_t;
|
|
|
|
|
|
|
|
static extent_split_interior_result_t
|
|
|
|
extent_split_interior(tsdn_t *tsdn, arena_t *arena,
|
|
|
|
extent_hooks_t **r_extent_hooks, rtree_ctx_t *rtree_ctx,
|
|
|
|
/* The result of splitting, in case of success. */
|
|
|
|
extent_t **extent, extent_t **lead, extent_t **trail,
|
|
|
|
/* The mess to clean up, in case of error. */
|
|
|
|
extent_t **to_leak, extent_t **to_salvage,
|
2017-03-14 08:36:57 +08:00
|
|
|
void *new_addr, size_t size, size_t pad, size_t alignment, bool slab,
|
2017-08-30 07:50:57 +08:00
|
|
|
szind_t szind, bool growing_retained) {
|
2017-03-14 08:36:57 +08:00
|
|
|
size_t esize = size + pad;
|
2017-08-30 07:50:57 +08:00
|
|
|
size_t leadsize = ALIGNMENT_CEILING((uintptr_t)extent_base_get(*extent),
|
|
|
|
PAGE_CEILING(alignment)) - (uintptr_t)extent_base_get(*extent);
|
2017-01-30 13:57:14 +08:00
|
|
|
assert(new_addr == NULL || leadsize == 0);
|
2017-08-30 07:50:57 +08:00
|
|
|
if (extent_size_get(*extent) < leadsize + esize) {
|
|
|
|
return extent_split_interior_cant_alloc;
|
|
|
|
}
|
|
|
|
size_t trailsize = extent_size_get(*extent) - leadsize - esize;
|
|
|
|
|
|
|
|
*lead = NULL;
|
|
|
|
*trail = NULL;
|
|
|
|
*to_leak = NULL;
|
|
|
|
*to_salvage = NULL;
|
2017-01-30 13:57:14 +08:00
|
|
|
|
2016-06-02 03:59:02 +08:00
|
|
|
/* Split the lead. */
|
|
|
|
if (leadsize != 0) {
|
2017-08-30 07:50:57 +08:00
|
|
|
*lead = *extent;
|
|
|
|
*extent = extent_split_impl(tsdn, arena, r_extent_hooks,
|
2017-12-15 04:46:39 +08:00
|
|
|
*lead, leadsize, SC_NSIZES, false, esize + trailsize, szind,
|
2017-05-27 02:06:01 +08:00
|
|
|
slab, growing_retained);
|
2017-08-30 07:50:57 +08:00
|
|
|
if (*extent == NULL) {
|
|
|
|
*to_leak = *lead;
|
|
|
|
*lead = NULL;
|
|
|
|
return extent_split_interior_error;
|
2016-06-02 03:59:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Split the trail. */
|
|
|
|
if (trailsize != 0) {
|
2017-08-30 07:50:57 +08:00
|
|
|
*trail = extent_split_impl(tsdn, arena, r_extent_hooks, *extent,
|
2017-12-15 04:46:39 +08:00
|
|
|
esize, szind, slab, trailsize, SC_NSIZES, false,
|
2017-08-30 07:50:57 +08:00
|
|
|
growing_retained);
|
|
|
|
if (*trail == NULL) {
|
|
|
|
*to_leak = *extent;
|
|
|
|
*to_salvage = *lead;
|
|
|
|
*lead = NULL;
|
|
|
|
*extent = NULL;
|
|
|
|
return extent_split_interior_error;
|
2016-06-02 03:59:02 +08:00
|
|
|
}
|
2017-08-30 07:50:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (leadsize == 0 && trailsize == 0) {
|
2016-06-02 03:59:02 +08:00
|
|
|
/*
|
2017-03-14 08:36:57 +08:00
|
|
|
* Splitting causes szind to be set as a side effect, but no
|
2016-06-02 03:59:02 +08:00
|
|
|
* splitting occurred.
|
|
|
|
*/
|
2017-08-30 07:50:57 +08:00
|
|
|
extent_szind_set(*extent, szind);
|
2017-12-15 04:46:39 +08:00
|
|
|
if (szind != SC_NSIZES) {
|
2017-03-17 08:57:52 +08:00
|
|
|
rtree_szind_slab_update(tsdn, &extents_rtree, rtree_ctx,
|
2017-08-30 07:50:57 +08:00
|
|
|
(uintptr_t)extent_addr_get(*extent), szind, slab);
|
|
|
|
if (slab && extent_size_get(*extent) > PAGE) {
|
2017-03-17 08:57:52 +08:00
|
|
|
rtree_szind_slab_update(tsdn, &extents_rtree,
|
|
|
|
rtree_ctx,
|
2017-08-30 07:50:57 +08:00
|
|
|
(uintptr_t)extent_past_get(*extent) -
|
2017-03-17 08:57:52 +08:00
|
|
|
(uintptr_t)PAGE, szind, slab);
|
|
|
|
}
|
|
|
|
}
|
2016-06-02 03:59:02 +08:00
|
|
|
}
|
|
|
|
|
2017-08-30 07:50:57 +08:00
|
|
|
return extent_split_interior_ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This fulfills the indicated allocation request out of the given extent (which
|
|
|
|
* the caller should have ensured was big enough). If there's any unused space
|
|
|
|
* before or after the resulting allocation, that space is given its own extent
|
|
|
|
* and put back into extents.
|
|
|
|
*/
|
|
|
|
static extent_t *
|
|
|
|
extent_recycle_split(tsdn_t *tsdn, arena_t *arena,
|
|
|
|
extent_hooks_t **r_extent_hooks, rtree_ctx_t *rtree_ctx, extents_t *extents,
|
|
|
|
void *new_addr, size_t size, size_t pad, size_t alignment, bool slab,
|
|
|
|
szind_t szind, extent_t *extent, bool growing_retained) {
|
|
|
|
extent_t *lead;
|
|
|
|
extent_t *trail;
|
|
|
|
extent_t *to_leak;
|
|
|
|
extent_t *to_salvage;
|
|
|
|
|
|
|
|
extent_split_interior_result_t result = extent_split_interior(
|
|
|
|
tsdn, arena, r_extent_hooks, rtree_ctx, &extent, &lead, &trail,
|
|
|
|
&to_leak, &to_salvage, new_addr, size, pad, alignment, slab, szind,
|
|
|
|
growing_retained);
|
|
|
|
|
|
|
|
if (result == extent_split_interior_ok) {
|
|
|
|
if (lead != NULL) {
|
2018-02-23 01:40:27 +08:00
|
|
|
extent_deactivate(tsdn, arena, extents, lead);
|
2017-08-30 07:50:57 +08:00
|
|
|
}
|
|
|
|
if (trail != NULL) {
|
2018-02-23 01:40:27 +08:00
|
|
|
extent_deactivate(tsdn, arena, extents, trail);
|
2017-08-30 07:50:57 +08:00
|
|
|
}
|
|
|
|
return extent;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* We should have picked an extent that was large enough to
|
|
|
|
* fulfill our allocation request.
|
|
|
|
*/
|
|
|
|
assert(result == extent_split_interior_error);
|
|
|
|
if (to_salvage != NULL) {
|
|
|
|
extent_deregister(tsdn, to_salvage);
|
|
|
|
}
|
|
|
|
if (to_leak != NULL) {
|
2017-11-29 04:21:58 +08:00
|
|
|
void *leak = extent_base_get(to_leak);
|
2017-12-09 07:06:08 +08:00
|
|
|
extent_deregister_no_gdump_sub(tsdn, to_leak);
|
2017-08-30 07:50:57 +08:00
|
|
|
extents_leak(tsdn, arena, r_extent_hooks, extents,
|
|
|
|
to_leak, growing_retained);
|
2017-11-29 04:21:58 +08:00
|
|
|
assert(extent_lock_from_addr(tsdn, rtree_ctx, leak)
|
|
|
|
== NULL);
|
2017-08-30 07:50:57 +08:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
unreachable();
|
2017-01-30 13:57:14 +08:00
|
|
|
}
|
|
|
|
|
2017-08-29 09:27:12 +08:00
|
|
|
/*
|
|
|
|
* Tries to satisfy the given allocation request by reusing one of the extents
|
|
|
|
* in the given extents_t.
|
|
|
|
*/
|
2017-01-30 13:57:14 +08:00
|
|
|
static extent_t *
|
|
|
|
extent_recycle(tsdn_t *tsdn, arena_t *arena, extent_hooks_t **r_extent_hooks,
|
2017-03-14 08:36:57 +08:00
|
|
|
extents_t *extents, void *new_addr, size_t size, size_t pad,
|
2017-05-27 02:06:01 +08:00
|
|
|
size_t alignment, bool slab, szind_t szind, bool *zero, bool *commit,
|
|
|
|
bool growing_retained) {
|
2017-05-23 10:32:04 +08:00
|
|
|
witness_assert_depth_to_rank(tsdn_witness_tsdp_get(tsdn),
|
2017-05-27 02:06:01 +08:00
|
|
|
WITNESS_RANK_CORE, growing_retained ? 1 : 0);
|
2017-01-30 13:57:14 +08:00
|
|
|
assert(new_addr == NULL || !slab);
|
|
|
|
assert(pad == 0 || !slab);
|
2017-03-14 08:36:57 +08:00
|
|
|
assert(!*zero || !slab);
|
2017-01-30 13:57:14 +08:00
|
|
|
|
|
|
|
rtree_ctx_t rtree_ctx_fallback;
|
|
|
|
rtree_ctx_t *rtree_ctx = tsdn_rtree_ctx(tsdn, &rtree_ctx_fallback);
|
|
|
|
|
|
|
|
extent_t *extent = extent_recycle_extract(tsdn, arena, r_extent_hooks,
|
2017-11-17 06:27:23 +08:00
|
|
|
rtree_ctx, extents, new_addr, size, pad, alignment, slab,
|
|
|
|
growing_retained);
|
2017-01-30 13:57:14 +08:00
|
|
|
if (extent == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
extent = extent_recycle_split(tsdn, arena, r_extent_hooks, rtree_ctx,
|
2017-05-27 02:06:01 +08:00
|
|
|
extents, new_addr, size, pad, alignment, slab, szind, extent,
|
|
|
|
growing_retained);
|
2017-01-30 13:57:14 +08:00
|
|
|
if (extent == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-11-22 15:23:03 +08:00
|
|
|
if (*commit && !extent_committed_get(extent)) {
|
2017-05-27 02:06:01 +08:00
|
|
|
if (extent_commit_impl(tsdn, arena, r_extent_hooks, extent,
|
|
|
|
0, extent_size_get(extent), growing_retained)) {
|
2017-01-30 13:57:14 +08:00
|
|
|
extent_record(tsdn, arena, r_extent_hooks, extents,
|
2017-05-27 02:06:01 +08:00
|
|
|
extent, growing_retained);
|
2017-01-20 10:15:45 +08:00
|
|
|
return NULL;
|
2016-11-22 15:23:03 +08:00
|
|
|
}
|
|
|
|
extent_zeroed_set(extent, true);
|
2016-06-02 03:59:02 +08:00
|
|
|
}
|
|
|
|
|
2017-11-17 06:27:23 +08:00
|
|
|
if (extent_committed_get(extent)) {
|
|
|
|
*commit = true;
|
|
|
|
}
|
|
|
|
if (extent_zeroed_get(extent)) {
|
|
|
|
*zero = true;
|
|
|
|
}
|
|
|
|
|
2017-01-16 08:56:30 +08:00
|
|
|
if (pad != 0) {
|
2016-06-02 03:59:02 +08:00
|
|
|
extent_addr_randomize(tsdn, extent, alignment);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2017-01-30 13:57:14 +08:00
|
|
|
assert(extent_state_get(extent) == extent_state_active);
|
2016-06-02 03:59:02 +08:00
|
|
|
if (slab) {
|
|
|
|
extent_slab_set(extent, slab);
|
2017-03-17 08:57:52 +08:00
|
|
|
extent_interior_register(tsdn, rtree_ctx, extent, szind);
|
2016-06-02 03:59:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (*zero) {
|
2017-03-14 08:36:57 +08:00
|
|
|
void *addr = extent_base_get(extent);
|
|
|
|
size_t size = extent_size_get(extent);
|
2016-06-02 03:59:02 +08:00
|
|
|
if (!extent_zeroed_get(extent)) {
|
2017-03-14 08:36:57 +08:00
|
|
|
if (pages_purge_forced(addr, size)) {
|
|
|
|
memset(addr, 0, size);
|
2017-03-10 09:20:00 +08:00
|
|
|
}
|
2016-06-02 03:59:02 +08:00
|
|
|
} else if (config_debug) {
|
2017-03-14 08:36:57 +08:00
|
|
|
size_t *p = (size_t *)(uintptr_t)addr;
|
|
|
|
for (size_t i = 0; i < size / sizeof(size_t); i++) {
|
2016-06-02 03:59:02 +08:00
|
|
|
assert(p[i] == 0);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2016-06-02 03:59:02 +08:00
|
|
|
}
|
|
|
|
}
|
2017-01-20 10:15:45 +08:00
|
|
|
return extent;
|
2016-06-02 03:59:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the caller specifies (!*zero), it is still possible to receive zeroed
|
|
|
|
* memory, in which case *zero is toggled to true. arena_extent_alloc() takes
|
|
|
|
* advantage of this to avoid demanding zeroed extents, but taking advantage of
|
|
|
|
* them if they are returned.
|
|
|
|
*/
|
|
|
|
static void *
|
|
|
|
extent_alloc_core(tsdn_t *tsdn, arena_t *arena, void *new_addr, size_t size,
|
2017-01-16 08:56:30 +08:00
|
|
|
size_t alignment, bool *zero, bool *commit, dss_prec_t dss_prec) {
|
2016-06-02 03:59:02 +08:00
|
|
|
void *ret;
|
|
|
|
|
|
|
|
assert(size != 0);
|
|
|
|
assert(alignment != 0);
|
|
|
|
|
|
|
|
/* "primary" dss. */
|
|
|
|
if (have_dss && dss_prec == dss_prec_primary && (ret =
|
|
|
|
extent_alloc_dss(tsdn, arena, new_addr, size, alignment, zero,
|
2017-01-16 08:56:30 +08:00
|
|
|
commit)) != NULL) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return ret;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2016-06-02 03:59:02 +08:00
|
|
|
/* mmap. */
|
|
|
|
if ((ret = extent_alloc_mmap(new_addr, size, alignment, zero, commit))
|
2017-01-16 08:56:30 +08:00
|
|
|
!= NULL) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return ret;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2016-06-02 03:59:02 +08:00
|
|
|
/* "secondary" dss. */
|
|
|
|
if (have_dss && dss_prec == dss_prec_secondary && (ret =
|
|
|
|
extent_alloc_dss(tsdn, arena, new_addr, size, alignment, zero,
|
2017-01-16 08:56:30 +08:00
|
|
|
commit)) != NULL) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return ret;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2016-06-02 03:59:02 +08:00
|
|
|
|
|
|
|
/* All strategies for allocation failed. */
|
2017-01-20 10:15:45 +08:00
|
|
|
return NULL;
|
2016-06-02 03:59:02 +08:00
|
|
|
}
|
|
|
|
|
2016-06-08 04:37:22 +08:00
|
|
|
static void *
|
|
|
|
extent_alloc_default_impl(tsdn_t *tsdn, arena_t *arena, void *new_addr,
|
2017-01-16 08:56:30 +08:00
|
|
|
size_t size, size_t alignment, bool *zero, bool *commit) {
|
2018-02-17 06:19:19 +08:00
|
|
|
void *ret = extent_alloc_core(tsdn, arena, new_addr, size, alignment, zero,
|
2017-04-05 08:22:24 +08:00
|
|
|
commit, (dss_prec_t)atomic_load_u(&arena->dss_prec,
|
|
|
|
ATOMIC_RELAXED));
|
2018-02-17 06:19:19 +08:00
|
|
|
if (have_madvise_huge && ret) {
|
|
|
|
pages_set_thp_state(ret, size);
|
|
|
|
}
|
2017-01-20 10:15:45 +08:00
|
|
|
return ret;
|
2016-06-08 04:37:22 +08:00
|
|
|
}
|
|
|
|
|
2016-06-02 03:59:02 +08:00
|
|
|
static void *
|
2016-06-04 03:05:53 +08:00
|
|
|
extent_alloc_default(extent_hooks_t *extent_hooks, void *new_addr, size_t size,
|
2017-01-16 08:56:30 +08:00
|
|
|
size_t alignment, bool *zero, bool *commit, unsigned arena_ind) {
|
2016-06-02 03:59:02 +08:00
|
|
|
tsdn_t *tsdn;
|
|
|
|
arena_t *arena;
|
|
|
|
|
|
|
|
tsdn = tsdn_fetch();
|
|
|
|
arena = arena_get(tsdn, arena_ind, false);
|
|
|
|
/*
|
|
|
|
* The arena we're allocating on behalf of must have been initialized
|
|
|
|
* already.
|
|
|
|
*/
|
|
|
|
assert(arena != NULL);
|
|
|
|
|
2017-01-20 10:15:45 +08:00
|
|
|
return extent_alloc_default_impl(tsdn, arena, new_addr, size,
|
|
|
|
alignment, zero, commit);
|
2016-06-02 03:59:02 +08:00
|
|
|
}
|
|
|
|
|
2017-06-23 07:18:30 +08:00
|
|
|
static void
|
|
|
|
extent_hook_pre_reentrancy(tsdn_t *tsdn, arena_t *arena) {
|
|
|
|
tsd_t *tsd = tsdn_null(tsdn) ? tsd_fetch() : tsdn_tsd(tsdn);
|
2017-08-31 07:17:04 +08:00
|
|
|
if (arena == arena_get(tsd_tsdn(tsd), 0, false)) {
|
|
|
|
/*
|
|
|
|
* The only legitimate case of customized extent hooks for a0 is
|
|
|
|
* hooks with no allocation activities. One such example is to
|
|
|
|
* place metadata on pre-allocated resources such as huge pages.
|
|
|
|
* In that case, rely on reentrancy_level checks to catch
|
|
|
|
* infinite recursions.
|
|
|
|
*/
|
|
|
|
pre_reentrancy(tsd, NULL);
|
|
|
|
} else {
|
|
|
|
pre_reentrancy(tsd, arena);
|
|
|
|
}
|
2017-06-23 07:18:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
extent_hook_post_reentrancy(tsdn_t *tsdn) {
|
|
|
|
tsd_t *tsd = tsdn_null(tsdn) ? tsd_fetch() : tsdn_tsd(tsdn);
|
|
|
|
post_reentrancy(tsd);
|
|
|
|
}
|
|
|
|
|
2016-11-22 15:23:03 +08:00
|
|
|
/*
|
|
|
|
* If virtual memory is retained, create increasingly larger extents from which
|
|
|
|
* to split requested extents in order to limit the total number of disjoint
|
|
|
|
* virtual memory ranges retained by each arena.
|
|
|
|
*/
|
|
|
|
static extent_t *
|
|
|
|
extent_grow_retained(tsdn_t *tsdn, arena_t *arena,
|
2017-05-27 02:06:01 +08:00
|
|
|
extent_hooks_t **r_extent_hooks, size_t size, size_t pad, size_t alignment,
|
|
|
|
bool slab, szind_t szind, bool *zero, bool *commit) {
|
|
|
|
malloc_mutex_assert_owner(tsdn, &arena->extent_grow_mtx);
|
2017-03-14 08:36:57 +08:00
|
|
|
assert(pad == 0 || !slab);
|
|
|
|
assert(!*zero || !slab);
|
2016-11-22 15:23:03 +08:00
|
|
|
|
2017-03-14 08:36:57 +08:00
|
|
|
size_t esize = size + pad;
|
|
|
|
size_t alloc_size_min = esize + PAGE_CEILING(alignment) - PAGE;
|
2016-11-22 15:23:03 +08:00
|
|
|
/* Beware size_t wrap-around. */
|
2017-03-14 08:36:57 +08:00
|
|
|
if (alloc_size_min < esize) {
|
2017-05-27 02:06:01 +08:00
|
|
|
goto label_err;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2017-05-27 02:06:01 +08:00
|
|
|
/*
|
|
|
|
* Find the next extent size in the series that would be large enough to
|
|
|
|
* satisfy this request.
|
|
|
|
*/
|
|
|
|
pszind_t egn_skip = 0;
|
2017-05-31 01:45:37 +08:00
|
|
|
size_t alloc_size = sz_pind2sz(arena->extent_grow_next + egn_skip);
|
2017-05-27 02:06:01 +08:00
|
|
|
while (alloc_size < alloc_size_min) {
|
|
|
|
egn_skip++;
|
2018-07-20 08:08:10 +08:00
|
|
|
if (arena->extent_grow_next + egn_skip >=
|
|
|
|
sz_psz2ind(SC_LARGE_MAXCLASS)) {
|
2017-05-27 02:06:01 +08:00
|
|
|
/* Outside legal range. */
|
|
|
|
goto label_err;
|
|
|
|
}
|
2017-05-31 01:45:37 +08:00
|
|
|
alloc_size = sz_pind2sz(arena->extent_grow_next + egn_skip);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2017-05-27 02:06:01 +08:00
|
|
|
|
2017-03-14 08:36:57 +08:00
|
|
|
extent_t *extent = extent_alloc(tsdn, arena);
|
2017-01-16 08:56:30 +08:00
|
|
|
if (extent == NULL) {
|
2017-05-27 02:06:01 +08:00
|
|
|
goto label_err;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2017-03-14 08:36:57 +08:00
|
|
|
bool zeroed = false;
|
|
|
|
bool committed = false;
|
2017-06-14 07:16:33 +08:00
|
|
|
|
|
|
|
void *ptr;
|
|
|
|
if (*r_extent_hooks == &extent_hooks_default) {
|
2018-02-17 06:19:19 +08:00
|
|
|
ptr = extent_alloc_default_impl(tsdn, arena, NULL,
|
|
|
|
alloc_size, PAGE, &zeroed, &committed);
|
2017-06-14 07:16:33 +08:00
|
|
|
} else {
|
2017-06-23 07:18:30 +08:00
|
|
|
extent_hook_pre_reentrancy(tsdn, arena);
|
2017-06-14 07:16:33 +08:00
|
|
|
ptr = (*r_extent_hooks)->alloc(*r_extent_hooks, NULL,
|
|
|
|
alloc_size, PAGE, &zeroed, &committed,
|
|
|
|
arena_ind_get(arena));
|
2017-06-23 07:18:30 +08:00
|
|
|
extent_hook_post_reentrancy(tsdn);
|
2017-06-14 07:16:33 +08:00
|
|
|
}
|
|
|
|
|
2017-12-15 04:46:39 +08:00
|
|
|
extent_init(extent, arena, ptr, alloc_size, false, SC_NSIZES,
|
2017-02-04 16:43:32 +08:00
|
|
|
arena_extent_sn_next(arena), extent_state_active, zeroed,
|
2017-09-19 08:25:57 +08:00
|
|
|
committed, true);
|
2017-05-26 09:15:41 +08:00
|
|
|
if (ptr == NULL) {
|
2016-11-22 15:23:03 +08:00
|
|
|
extent_dalloc(tsdn, arena, extent);
|
2017-05-27 02:06:01 +08:00
|
|
|
goto label_err;
|
2016-11-22 15:23:03 +08:00
|
|
|
}
|
2017-09-19 08:25:57 +08:00
|
|
|
|
2017-05-26 09:15:41 +08:00
|
|
|
if (extent_register_no_gdump_add(tsdn, extent)) {
|
|
|
|
extents_leak(tsdn, arena, r_extent_hooks,
|
2017-05-27 02:06:01 +08:00
|
|
|
&arena->extents_retained, extent, true);
|
|
|
|
goto label_err;
|
2017-05-26 09:15:41 +08:00
|
|
|
}
|
2016-11-22 15:23:03 +08:00
|
|
|
|
2017-04-20 07:14:54 +08:00
|
|
|
if (extent_zeroed_get(extent) && extent_committed_get(extent)) {
|
2016-11-22 15:23:03 +08:00
|
|
|
*zero = true;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
|
|
|
if (extent_committed_get(extent)) {
|
2016-11-22 15:23:03 +08:00
|
|
|
*commit = true;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2016-11-22 15:23:03 +08:00
|
|
|
|
2017-08-30 07:50:57 +08:00
|
|
|
rtree_ctx_t rtree_ctx_fallback;
|
|
|
|
rtree_ctx_t *rtree_ctx = tsdn_rtree_ctx(tsdn, &rtree_ctx_fallback);
|
|
|
|
|
|
|
|
extent_t *lead;
|
|
|
|
extent_t *trail;
|
|
|
|
extent_t *to_leak;
|
|
|
|
extent_t *to_salvage;
|
|
|
|
extent_split_interior_result_t result = extent_split_interior(
|
|
|
|
tsdn, arena, r_extent_hooks, rtree_ctx, &extent, &lead, &trail,
|
|
|
|
&to_leak, &to_salvage, NULL, size, pad, alignment, slab, szind,
|
|
|
|
true);
|
|
|
|
|
|
|
|
if (result == extent_split_interior_ok) {
|
|
|
|
if (lead != NULL) {
|
|
|
|
extent_record(tsdn, arena, r_extent_hooks,
|
2017-05-27 02:06:01 +08:00
|
|
|
&arena->extents_retained, lead, true);
|
2016-11-22 15:23:03 +08:00
|
|
|
}
|
2017-08-30 07:50:57 +08:00
|
|
|
if (trail != NULL) {
|
|
|
|
extent_record(tsdn, arena, r_extent_hooks,
|
|
|
|
&arena->extents_retained, trail, true);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* We should have allocated a sufficiently large extent; the
|
|
|
|
* cant_alloc case should not occur.
|
|
|
|
*/
|
|
|
|
assert(result == extent_split_interior_error);
|
2018-04-18 04:16:42 +08:00
|
|
|
if (to_salvage != NULL) {
|
|
|
|
if (config_prof) {
|
|
|
|
extent_gdump_add(tsdn, to_salvage);
|
|
|
|
}
|
|
|
|
extent_record(tsdn, arena, r_extent_hooks,
|
|
|
|
&arena->extents_retained, to_salvage, true);
|
|
|
|
}
|
2017-08-30 07:50:57 +08:00
|
|
|
if (to_leak != NULL) {
|
2017-12-09 07:06:08 +08:00
|
|
|
extent_deregister_no_gdump_sub(tsdn, to_leak);
|
2017-01-30 13:57:14 +08:00
|
|
|
extents_leak(tsdn, arena, r_extent_hooks,
|
2017-08-30 07:50:57 +08:00
|
|
|
&arena->extents_retained, to_leak, true);
|
2016-11-22 15:23:03 +08:00
|
|
|
}
|
2018-04-18 04:16:42 +08:00
|
|
|
goto label_err;
|
2016-11-22 15:23:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (*commit && !extent_committed_get(extent)) {
|
2017-05-27 02:06:01 +08:00
|
|
|
if (extent_commit_impl(tsdn, arena, r_extent_hooks, extent, 0,
|
|
|
|
extent_size_get(extent), true)) {
|
2017-01-30 13:57:14 +08:00
|
|
|
extent_record(tsdn, arena, r_extent_hooks,
|
2017-05-27 02:06:01 +08:00
|
|
|
&arena->extents_retained, extent, true);
|
|
|
|
goto label_err;
|
2016-11-22 15:23:03 +08:00
|
|
|
}
|
|
|
|
extent_zeroed_set(extent, true);
|
|
|
|
}
|
|
|
|
|
2017-05-27 02:06:01 +08:00
|
|
|
/*
|
2017-11-03 08:48:39 +08:00
|
|
|
* Increment extent_grow_next if doing so wouldn't exceed the allowed
|
2017-05-27 02:06:01 +08:00
|
|
|
* range.
|
|
|
|
*/
|
2017-11-03 08:48:39 +08:00
|
|
|
if (arena->extent_grow_next + egn_skip + 1 <=
|
|
|
|
arena->retain_grow_limit) {
|
2017-05-27 02:06:01 +08:00
|
|
|
arena->extent_grow_next += egn_skip + 1;
|
|
|
|
} else {
|
2017-11-03 08:48:39 +08:00
|
|
|
arena->extent_grow_next = arena->retain_grow_limit;
|
2017-05-27 02:06:01 +08:00
|
|
|
}
|
|
|
|
/* All opportunities for failure are past. */
|
|
|
|
malloc_mutex_unlock(tsdn, &arena->extent_grow_mtx);
|
|
|
|
|
2016-11-22 15:23:03 +08:00
|
|
|
if (config_prof) {
|
2017-01-30 13:57:14 +08:00
|
|
|
/* Adjust gdump stats now that extent is final size. */
|
|
|
|
extent_gdump_add(tsdn, extent);
|
2016-11-22 15:23:03 +08:00
|
|
|
}
|
2017-01-16 08:56:30 +08:00
|
|
|
if (pad != 0) {
|
2016-11-22 15:23:03 +08:00
|
|
|
extent_addr_randomize(tsdn, extent, alignment);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2016-11-22 15:23:03 +08:00
|
|
|
if (slab) {
|
|
|
|
rtree_ctx_t rtree_ctx_fallback;
|
|
|
|
rtree_ctx_t *rtree_ctx = tsdn_rtree_ctx(tsdn,
|
|
|
|
&rtree_ctx_fallback);
|
|
|
|
|
|
|
|
extent_slab_set(extent, true);
|
2017-03-17 08:57:52 +08:00
|
|
|
extent_interior_register(tsdn, rtree_ctx, extent, szind);
|
2016-11-22 15:23:03 +08:00
|
|
|
}
|
2017-01-16 08:56:30 +08:00
|
|
|
if (*zero && !extent_zeroed_get(extent)) {
|
2017-03-14 08:36:57 +08:00
|
|
|
void *addr = extent_base_get(extent);
|
|
|
|
size_t size = extent_size_get(extent);
|
|
|
|
if (pages_purge_forced(addr, size)) {
|
|
|
|
memset(addr, 0, size);
|
2017-03-10 09:20:00 +08:00
|
|
|
}
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2017-05-27 02:06:01 +08:00
|
|
|
|
2017-01-20 10:15:45 +08:00
|
|
|
return extent;
|
2017-05-27 02:06:01 +08:00
|
|
|
label_err:
|
|
|
|
malloc_mutex_unlock(tsdn, &arena->extent_grow_mtx);
|
|
|
|
return NULL;
|
2016-11-22 15:23:03 +08:00
|
|
|
}
|
|
|
|
|
2016-06-02 03:59:02 +08:00
|
|
|
static extent_t *
|
|
|
|
extent_alloc_retained(tsdn_t *tsdn, arena_t *arena,
|
2017-03-14 08:36:57 +08:00
|
|
|
extent_hooks_t **r_extent_hooks, void *new_addr, size_t size, size_t pad,
|
|
|
|
size_t alignment, bool slab, szind_t szind, bool *zero, bool *commit) {
|
|
|
|
assert(size != 0);
|
2016-06-02 03:59:02 +08:00
|
|
|
assert(alignment != 0);
|
|
|
|
|
2017-05-27 02:06:01 +08:00
|
|
|
malloc_mutex_lock(tsdn, &arena->extent_grow_mtx);
|
|
|
|
|
|
|
|
extent_t *extent = extent_recycle(tsdn, arena, r_extent_hooks,
|
2017-03-14 08:36:57 +08:00
|
|
|
&arena->extents_retained, new_addr, size, pad, alignment, slab,
|
2017-05-27 02:06:01 +08:00
|
|
|
szind, zero, commit, true);
|
2017-01-19 15:03:37 +08:00
|
|
|
if (extent != NULL) {
|
2017-05-27 02:06:01 +08:00
|
|
|
malloc_mutex_unlock(tsdn, &arena->extent_grow_mtx);
|
2017-01-16 08:56:30 +08:00
|
|
|
if (config_prof) {
|
2017-01-30 13:57:14 +08:00
|
|
|
extent_gdump_add(tsdn, extent);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2017-05-27 02:06:01 +08:00
|
|
|
} else if (opt_retain && new_addr == NULL) {
|
|
|
|
extent = extent_grow_retained(tsdn, arena, r_extent_hooks, size,
|
|
|
|
pad, alignment, slab, szind, zero, commit);
|
|
|
|
/* extent_grow_retained() always releases extent_grow_mtx. */
|
|
|
|
} else {
|
|
|
|
malloc_mutex_unlock(tsdn, &arena->extent_grow_mtx);
|
2016-11-22 15:23:03 +08:00
|
|
|
}
|
2017-05-27 02:06:01 +08:00
|
|
|
malloc_mutex_assert_not_owner(tsdn, &arena->extent_grow_mtx);
|
2016-06-02 03:59:02 +08:00
|
|
|
|
2017-01-20 10:15:45 +08:00
|
|
|
return extent;
|
2016-06-02 03:59:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static extent_t *
|
|
|
|
extent_alloc_wrapper_hard(tsdn_t *tsdn, arena_t *arena,
|
2017-03-14 08:36:57 +08:00
|
|
|
extent_hooks_t **r_extent_hooks, void *new_addr, size_t size, size_t pad,
|
|
|
|
size_t alignment, bool slab, szind_t szind, bool *zero, bool *commit) {
|
|
|
|
size_t esize = size + pad;
|
|
|
|
extent_t *extent = extent_alloc(tsdn, arena);
|
2017-01-16 08:56:30 +08:00
|
|
|
if (extent == NULL) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return NULL;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2017-03-14 08:36:57 +08:00
|
|
|
void *addr;
|
2016-06-08 04:37:22 +08:00
|
|
|
if (*r_extent_hooks == &extent_hooks_default) {
|
|
|
|
/* Call directly to propagate tsdn. */
|
2017-03-14 08:36:57 +08:00
|
|
|
addr = extent_alloc_default_impl(tsdn, arena, new_addr, esize,
|
2016-06-08 04:37:22 +08:00
|
|
|
alignment, zero, commit);
|
|
|
|
} else {
|
2017-06-23 07:18:30 +08:00
|
|
|
extent_hook_pre_reentrancy(tsdn, arena);
|
2017-03-14 08:36:57 +08:00
|
|
|
addr = (*r_extent_hooks)->alloc(*r_extent_hooks, new_addr,
|
|
|
|
esize, alignment, zero, commit, arena_ind_get(arena));
|
2017-06-23 07:18:30 +08:00
|
|
|
extent_hook_post_reentrancy(tsdn);
|
2016-06-08 04:37:22 +08:00
|
|
|
}
|
2016-06-02 03:59:02 +08:00
|
|
|
if (addr == NULL) {
|
|
|
|
extent_dalloc(tsdn, arena, extent);
|
2017-01-20 10:15:45 +08:00
|
|
|
return NULL;
|
2016-06-02 03:59:02 +08:00
|
|
|
}
|
2017-03-14 08:36:57 +08:00
|
|
|
extent_init(extent, arena, addr, esize, slab, szind,
|
2018-04-07 04:18:21 +08:00
|
|
|
arena_extent_sn_next(arena), extent_state_active, *zero, *commit,
|
2017-09-19 08:25:57 +08:00
|
|
|
true);
|
2017-01-16 08:56:30 +08:00
|
|
|
if (pad != 0) {
|
2016-06-02 03:59:02 +08:00
|
|
|
extent_addr_randomize(tsdn, extent, alignment);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2016-06-02 03:59:02 +08:00
|
|
|
if (extent_register(tsdn, extent)) {
|
2017-01-30 13:57:14 +08:00
|
|
|
extents_leak(tsdn, arena, r_extent_hooks,
|
2017-05-27 02:06:01 +08:00
|
|
|
&arena->extents_retained, extent, false);
|
2017-01-20 10:15:45 +08:00
|
|
|
return NULL;
|
2016-06-02 03:59:02 +08:00
|
|
|
}
|
|
|
|
|
2017-01-20 10:15:45 +08:00
|
|
|
return extent;
|
2016-06-02 03:59:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
extent_t *
|
2016-06-04 03:05:53 +08:00
|
|
|
extent_alloc_wrapper(tsdn_t *tsdn, arena_t *arena,
|
2017-03-14 08:36:57 +08:00
|
|
|
extent_hooks_t **r_extent_hooks, void *new_addr, size_t size, size_t pad,
|
|
|
|
size_t alignment, bool slab, szind_t szind, bool *zero, bool *commit) {
|
2017-05-23 10:32:04 +08:00
|
|
|
witness_assert_depth_to_rank(tsdn_witness_tsdp_get(tsdn),
|
|
|
|
WITNESS_RANK_CORE, 0);
|
2016-06-02 03:59:02 +08:00
|
|
|
|
2016-06-04 03:05:53 +08:00
|
|
|
extent_hooks_assure_initialized(arena, r_extent_hooks);
|
2016-06-02 03:59:02 +08:00
|
|
|
|
2017-01-30 13:57:14 +08:00
|
|
|
extent_t *extent = extent_alloc_retained(tsdn, arena, r_extent_hooks,
|
2017-03-14 08:36:57 +08:00
|
|
|
new_addr, size, pad, alignment, slab, szind, zero, commit);
|
2016-06-02 03:59:02 +08:00
|
|
|
if (extent == NULL) {
|
2017-08-01 04:01:07 +08:00
|
|
|
if (opt_retain && new_addr != NULL) {
|
|
|
|
/*
|
|
|
|
* When retain is enabled and new_addr is set, we do not
|
|
|
|
* attempt extent_alloc_wrapper_hard which does mmap
|
|
|
|
* that is very unlikely to succeed (unless it happens
|
|
|
|
* to be at the end).
|
|
|
|
*/
|
|
|
|
return NULL;
|
|
|
|
}
|
2016-06-04 03:05:53 +08:00
|
|
|
extent = extent_alloc_wrapper_hard(tsdn, arena, r_extent_hooks,
|
2017-03-14 08:36:57 +08:00
|
|
|
new_addr, size, pad, alignment, slab, szind, zero, commit);
|
2016-06-02 03:59:02 +08:00
|
|
|
}
|
|
|
|
|
2017-09-19 08:25:57 +08:00
|
|
|
assert(extent == NULL || extent_dumpable_get(extent));
|
2017-01-20 10:15:45 +08:00
|
|
|
return extent;
|
2016-06-02 03:59:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
2017-02-13 15:00:19 +08:00
|
|
|
extent_can_coalesce(arena_t *arena, extents_t *extents, const extent_t *inner,
|
|
|
|
const extent_t *outer) {
|
|
|
|
assert(extent_arena_get(inner) == arena);
|
|
|
|
if (extent_arena_get(outer) != arena) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return false;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2017-02-13 15:00:19 +08:00
|
|
|
|
|
|
|
assert(extent_state_get(inner) == extent_state_active);
|
|
|
|
if (extent_state_get(outer) != extents->state) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return false;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2017-02-13 15:00:19 +08:00
|
|
|
|
|
|
|
if (extent_committed_get(inner) != extent_committed_get(outer)) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return false;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2016-06-02 03:59:02 +08:00
|
|
|
|
2017-01-20 10:15:45 +08:00
|
|
|
return true;
|
2016-06-02 03:59:02 +08:00
|
|
|
}
|
|
|
|
|
2017-01-30 13:57:14 +08:00
|
|
|
static bool
|
2017-02-06 15:59:53 +08:00
|
|
|
extent_coalesce(tsdn_t *tsdn, arena_t *arena, extent_hooks_t **r_extent_hooks,
|
2017-05-27 02:06:01 +08:00
|
|
|
extents_t *extents, extent_t *inner, extent_t *outer, bool forward,
|
|
|
|
bool growing_retained) {
|
2017-02-13 15:00:19 +08:00
|
|
|
assert(extent_can_coalesce(arena, extents, inner, outer));
|
2016-06-02 03:59:02 +08:00
|
|
|
|
2018-02-23 01:40:27 +08:00
|
|
|
extent_activate_locked(tsdn, arena, extents, outer);
|
2016-06-02 03:59:02 +08:00
|
|
|
|
2017-01-30 13:57:14 +08:00
|
|
|
malloc_mutex_unlock(tsdn, &extents->mtx);
|
2017-05-27 02:06:01 +08:00
|
|
|
bool err = extent_merge_impl(tsdn, arena, r_extent_hooks,
|
|
|
|
forward ? inner : outer, forward ? outer : inner, growing_retained);
|
2017-01-30 13:57:14 +08:00
|
|
|
malloc_mutex_lock(tsdn, &extents->mtx);
|
2017-02-13 15:00:19 +08:00
|
|
|
|
2017-01-30 13:57:14 +08:00
|
|
|
if (err) {
|
2018-02-23 01:40:27 +08:00
|
|
|
extent_deactivate_locked(tsdn, arena, extents, outer);
|
2016-06-02 03:59:02 +08:00
|
|
|
}
|
|
|
|
|
2017-02-13 15:00:19 +08:00
|
|
|
return err;
|
2016-06-02 03:59:02 +08:00
|
|
|
}
|
|
|
|
|
2017-02-13 15:18:57 +08:00
|
|
|
static extent_t *
|
|
|
|
extent_try_coalesce(tsdn_t *tsdn, arena_t *arena,
|
|
|
|
extent_hooks_t **r_extent_hooks, rtree_ctx_t *rtree_ctx, extents_t *extents,
|
2017-05-27 02:06:01 +08:00
|
|
|
extent_t *extent, bool *coalesced, bool growing_retained) {
|
2017-01-30 13:57:14 +08:00
|
|
|
/*
|
|
|
|
* Continue attempting to coalesce until failure, to protect against
|
|
|
|
* races with other threads that are thwarted by this one.
|
|
|
|
*/
|
2017-03-03 10:04:35 +08:00
|
|
|
bool again;
|
2017-01-30 13:57:14 +08:00
|
|
|
do {
|
2017-03-03 10:04:35 +08:00
|
|
|
again = false;
|
2017-01-30 13:57:14 +08:00
|
|
|
|
|
|
|
/* Try to coalesce forward. */
|
2017-05-16 05:23:51 +08:00
|
|
|
extent_t *next = extent_lock_from_addr(tsdn, rtree_ctx,
|
|
|
|
extent_past_get(extent));
|
|
|
|
if (next != NULL) {
|
2017-02-06 15:59:53 +08:00
|
|
|
/*
|
|
|
|
* extents->mtx only protects against races for
|
|
|
|
* like-state extents, so call extent_can_coalesce()
|
2017-05-16 05:23:51 +08:00
|
|
|
* before releasing next's pool lock.
|
2017-02-06 15:59:53 +08:00
|
|
|
*/
|
2017-05-16 05:23:51 +08:00
|
|
|
bool can_coalesce = extent_can_coalesce(arena, extents,
|
|
|
|
extent, next);
|
|
|
|
|
|
|
|
extent_unlock(tsdn, next);
|
|
|
|
|
2017-02-06 15:59:53 +08:00
|
|
|
if (can_coalesce && !extent_coalesce(tsdn, arena,
|
2017-05-27 02:06:01 +08:00
|
|
|
r_extent_hooks, extents, extent, next, true,
|
|
|
|
growing_retained)) {
|
2017-03-03 10:04:35 +08:00
|
|
|
if (extents->delay_coalesce) {
|
|
|
|
/* Do minimal coalescing. */
|
|
|
|
*coalesced = true;
|
|
|
|
return extent;
|
|
|
|
}
|
|
|
|
again = true;
|
2017-02-06 15:59:53 +08:00
|
|
|
}
|
2017-01-30 13:57:14 +08:00
|
|
|
}
|
2016-06-02 03:59:02 +08:00
|
|
|
|
2017-01-30 13:57:14 +08:00
|
|
|
/* Try to coalesce backward. */
|
2017-05-16 05:23:51 +08:00
|
|
|
extent_t *prev = extent_lock_from_addr(tsdn, rtree_ctx,
|
|
|
|
extent_before_get(extent));
|
|
|
|
if (prev != NULL) {
|
|
|
|
bool can_coalesce = extent_can_coalesce(arena, extents,
|
|
|
|
extent, prev);
|
|
|
|
extent_unlock(tsdn, prev);
|
|
|
|
|
2017-02-06 15:59:53 +08:00
|
|
|
if (can_coalesce && !extent_coalesce(tsdn, arena,
|
2017-05-31 01:45:37 +08:00
|
|
|
r_extent_hooks, extents, extent, prev, false,
|
2017-05-27 02:06:01 +08:00
|
|
|
growing_retained)) {
|
2017-01-30 13:57:14 +08:00
|
|
|
extent = prev;
|
2017-03-03 10:04:35 +08:00
|
|
|
if (extents->delay_coalesce) {
|
|
|
|
/* Do minimal coalescing. */
|
|
|
|
*coalesced = true;
|
|
|
|
return extent;
|
|
|
|
}
|
|
|
|
again = true;
|
2017-01-30 13:57:14 +08:00
|
|
|
}
|
|
|
|
}
|
2017-03-03 10:04:35 +08:00
|
|
|
} while (again);
|
2016-06-02 03:59:02 +08:00
|
|
|
|
2017-03-03 10:04:35 +08:00
|
|
|
if (extents->delay_coalesce) {
|
|
|
|
*coalesced = false;
|
|
|
|
}
|
2017-02-13 15:18:57 +08:00
|
|
|
return extent;
|
|
|
|
}
|
|
|
|
|
2017-08-29 09:27:12 +08:00
|
|
|
/*
|
|
|
|
* Does the metadata management portions of putting an unused extent into the
|
|
|
|
* given extents_t (coalesces, deregisters slab interiors, the heap operations).
|
|
|
|
*/
|
2017-02-13 15:18:57 +08:00
|
|
|
static void
|
|
|
|
extent_record(tsdn_t *tsdn, arena_t *arena, extent_hooks_t **r_extent_hooks,
|
2017-05-27 02:06:01 +08:00
|
|
|
extents_t *extents, extent_t *extent, bool growing_retained) {
|
2017-02-13 15:18:57 +08:00
|
|
|
rtree_ctx_t rtree_ctx_fallback;
|
|
|
|
rtree_ctx_t *rtree_ctx = tsdn_rtree_ctx(tsdn, &rtree_ctx_fallback);
|
|
|
|
|
Implement two-phase decay-based purging.
Split decay-based purging into two phases, the first of which uses lazy
purging to convert dirty pages to "muzzy", and the second of which uses
forced purging, decommit, or unmapping to convert pages to clean or
destroy them altogether. Not all operating systems support lazy
purging, yet the application may provide extent hooks that implement
lazy purging, so care must be taken to dynamically omit the first phase
when necessary.
The mallctl interfaces change as follows:
- opt.decay_time --> opt.{dirty,muzzy}_decay_time
- arena.<i>.decay_time --> arena.<i>.{dirty,muzzy}_decay_time
- arenas.decay_time --> arenas.{dirty,muzzy}_decay_time
- stats.arenas.<i>.pdirty --> stats.arenas.<i>.p{dirty,muzzy}
- stats.arenas.<i>.{npurge,nmadvise,purged} -->
stats.arenas.<i>.{dirty,muzzy}_{npurge,nmadvise,purged}
This resolves #521.
2017-03-09 14:42:57 +08:00
|
|
|
assert((extents_state_get(extents) != extent_state_dirty &&
|
|
|
|
extents_state_get(extents) != extent_state_muzzy) ||
|
2017-02-13 15:18:57 +08:00
|
|
|
!extent_zeroed_get(extent));
|
|
|
|
|
|
|
|
malloc_mutex_lock(tsdn, &extents->mtx);
|
|
|
|
extent_hooks_assure_initialized(arena, r_extent_hooks);
|
|
|
|
|
2017-12-15 04:46:39 +08:00
|
|
|
extent_szind_set(extent, SC_NSIZES);
|
2017-02-13 15:18:57 +08:00
|
|
|
if (extent_slab_get(extent)) {
|
|
|
|
extent_interior_deregister(tsdn, rtree_ctx, extent);
|
|
|
|
extent_slab_set(extent, false);
|
|
|
|
}
|
|
|
|
|
2017-03-17 08:57:52 +08:00
|
|
|
assert(rtree_extent_read(tsdn, &extents_rtree, rtree_ctx,
|
|
|
|
(uintptr_t)extent_base_get(extent), true) == extent);
|
2017-02-13 15:18:57 +08:00
|
|
|
|
2017-03-03 10:04:35 +08:00
|
|
|
if (!extents->delay_coalesce) {
|
2017-02-13 15:18:57 +08:00
|
|
|
extent = extent_try_coalesce(tsdn, arena, r_extent_hooks,
|
2017-05-27 02:06:01 +08:00
|
|
|
rtree_ctx, extents, extent, NULL, growing_retained);
|
2018-07-12 07:05:58 +08:00
|
|
|
} else if (extent_size_get(extent) >= SC_LARGE_MINCLASS) {
|
2017-11-16 06:48:55 +08:00
|
|
|
/* Always coalesce large extents eagerly. */
|
|
|
|
bool coalesced;
|
|
|
|
size_t prev_size;
|
|
|
|
do {
|
|
|
|
prev_size = extent_size_get(extent);
|
|
|
|
assert(extent_state_get(extent) == extent_state_active);
|
|
|
|
extent = extent_try_coalesce(tsdn, arena,
|
|
|
|
r_extent_hooks, rtree_ctx, extents, extent,
|
|
|
|
&coalesced, growing_retained);
|
|
|
|
} while (coalesced &&
|
2017-12-15 04:46:39 +08:00
|
|
|
extent_size_get(extent)
|
2018-07-12 07:05:58 +08:00
|
|
|
>= prev_size + SC_LARGE_MINCLASS);
|
2017-02-13 15:18:57 +08:00
|
|
|
}
|
2018-02-23 01:40:27 +08:00
|
|
|
extent_deactivate_locked(tsdn, arena, extents, extent);
|
2017-02-13 15:00:19 +08:00
|
|
|
|
2017-01-30 13:57:14 +08:00
|
|
|
malloc_mutex_unlock(tsdn, &extents->mtx);
|
2016-06-02 03:59:02 +08:00
|
|
|
}
|
|
|
|
|
2016-06-06 06:27:20 +08:00
|
|
|
void
|
2017-01-16 08:56:30 +08:00
|
|
|
extent_dalloc_gap(tsdn_t *tsdn, arena_t *arena, extent_t *extent) {
|
2016-06-06 06:27:20 +08:00
|
|
|
extent_hooks_t *extent_hooks = EXTENT_HOOKS_INITIALIZER;
|
|
|
|
|
2017-05-23 10:32:04 +08:00
|
|
|
witness_assert_depth_to_rank(tsdn_witness_tsdp_get(tsdn),
|
|
|
|
WITNESS_RANK_CORE, 0);
|
2017-01-30 13:57:14 +08:00
|
|
|
|
2016-06-06 06:27:20 +08:00
|
|
|
if (extent_register(tsdn, extent)) {
|
2017-01-30 13:57:14 +08:00
|
|
|
extents_leak(tsdn, arena, &extent_hooks,
|
2017-05-27 02:06:01 +08:00
|
|
|
&arena->extents_retained, extent, false);
|
2016-06-06 06:27:20 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
extent_dalloc_wrapper(tsdn, arena, &extent_hooks, extent);
|
|
|
|
}
|
|
|
|
|
2016-06-08 04:37:22 +08:00
|
|
|
static bool
|
2017-01-16 08:56:30 +08:00
|
|
|
extent_dalloc_default_impl(void *addr, size_t size) {
|
|
|
|
if (!have_dss || !extent_in_dss(addr)) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return extent_dalloc_mmap(addr, size);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2017-01-20 10:15:45 +08:00
|
|
|
return true;
|
2016-06-08 04:37:22 +08:00
|
|
|
}
|
|
|
|
|
2016-06-02 03:59:02 +08:00
|
|
|
static bool
|
2016-06-04 03:05:53 +08:00
|
|
|
extent_dalloc_default(extent_hooks_t *extent_hooks, void *addr, size_t size,
|
2017-01-16 08:56:30 +08:00
|
|
|
bool committed, unsigned arena_ind) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return extent_dalloc_default_impl(addr, size);
|
2016-06-02 03:59:02 +08:00
|
|
|
}
|
|
|
|
|
2017-04-28 06:51:35 +08:00
|
|
|
static bool
|
2017-01-04 09:21:59 +08:00
|
|
|
extent_dalloc_wrapper_try(tsdn_t *tsdn, arena_t *arena,
|
2017-01-16 08:56:30 +08:00
|
|
|
extent_hooks_t **r_extent_hooks, extent_t *extent) {
|
2017-01-04 09:21:59 +08:00
|
|
|
bool err;
|
2016-06-02 03:59:02 +08:00
|
|
|
|
|
|
|
assert(extent_base_get(extent) != NULL);
|
|
|
|
assert(extent_size_get(extent) != 0);
|
2017-05-23 10:32:04 +08:00
|
|
|
witness_assert_depth_to_rank(tsdn_witness_tsdp_get(tsdn),
|
|
|
|
WITNESS_RANK_CORE, 0);
|
2016-06-02 03:59:02 +08:00
|
|
|
|
|
|
|
extent_addr_set(extent, extent_base_get(extent));
|
|
|
|
|
2016-06-04 03:05:53 +08:00
|
|
|
extent_hooks_assure_initialized(arena, r_extent_hooks);
|
2017-01-30 13:57:14 +08:00
|
|
|
/* Try to deallocate. */
|
2016-06-08 04:37:22 +08:00
|
|
|
if (*r_extent_hooks == &extent_hooks_default) {
|
|
|
|
/* Call directly to propagate tsdn. */
|
2016-10-14 03:18:38 +08:00
|
|
|
err = extent_dalloc_default_impl(extent_base_get(extent),
|
2016-06-08 04:37:22 +08:00
|
|
|
extent_size_get(extent));
|
|
|
|
} else {
|
2017-06-23 07:18:30 +08:00
|
|
|
extent_hook_pre_reentrancy(tsdn, arena);
|
2016-12-04 07:38:25 +08:00
|
|
|
err = ((*r_extent_hooks)->dalloc == NULL ||
|
|
|
|
(*r_extent_hooks)->dalloc(*r_extent_hooks,
|
2016-06-08 04:37:22 +08:00
|
|
|
extent_base_get(extent), extent_size_get(extent),
|
2016-12-23 06:39:10 +08:00
|
|
|
extent_committed_get(extent), arena_ind_get(arena)));
|
2017-06-23 07:18:30 +08:00
|
|
|
extent_hook_post_reentrancy(tsdn);
|
2016-06-08 04:37:22 +08:00
|
|
|
}
|
|
|
|
|
2017-01-16 08:56:30 +08:00
|
|
|
if (!err) {
|
2016-06-02 03:59:02 +08:00
|
|
|
extent_dalloc(tsdn, arena, extent);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2017-01-04 09:21:59 +08:00
|
|
|
|
2017-01-20 10:15:45 +08:00
|
|
|
return err;
|
2017-01-04 09:21:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
extent_dalloc_wrapper(tsdn_t *tsdn, arena_t *arena,
|
2017-01-16 08:56:30 +08:00
|
|
|
extent_hooks_t **r_extent_hooks, extent_t *extent) {
|
2017-09-19 08:25:57 +08:00
|
|
|
assert(extent_dumpable_get(extent));
|
2017-05-23 10:32:04 +08:00
|
|
|
witness_assert_depth_to_rank(tsdn_witness_tsdp_get(tsdn),
|
|
|
|
WITNESS_RANK_CORE, 0);
|
2017-01-04 09:21:59 +08:00
|
|
|
|
2017-01-30 13:57:14 +08:00
|
|
|
/*
|
|
|
|
* Deregister first to avoid a race with other allocating threads, and
|
|
|
|
* reregister if deallocation fails.
|
|
|
|
*/
|
|
|
|
extent_deregister(tsdn, extent);
|
2017-01-16 08:56:30 +08:00
|
|
|
if (!extent_dalloc_wrapper_try(tsdn, arena, r_extent_hooks, extent)) {
|
2016-06-02 03:59:02 +08:00
|
|
|
return;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2017-01-04 09:21:59 +08:00
|
|
|
|
2016-06-06 11:39:25 +08:00
|
|
|
extent_reregister(tsdn, extent);
|
2017-06-23 06:36:41 +08:00
|
|
|
if (*r_extent_hooks != &extent_hooks_default) {
|
2017-06-23 07:18:30 +08:00
|
|
|
extent_hook_pre_reentrancy(tsdn, arena);
|
2017-06-23 06:36:41 +08:00
|
|
|
}
|
2016-06-02 03:59:02 +08:00
|
|
|
/* Try to decommit; purge if that fails. */
|
2017-01-30 13:57:14 +08:00
|
|
|
bool zeroed;
|
2017-01-16 08:56:30 +08:00
|
|
|
if (!extent_committed_get(extent)) {
|
2016-12-04 07:38:25 +08:00
|
|
|
zeroed = true;
|
2017-01-16 08:56:30 +08:00
|
|
|
} else if (!extent_decommit_wrapper(tsdn, arena, r_extent_hooks, extent,
|
|
|
|
0, extent_size_get(extent))) {
|
2016-12-04 07:38:25 +08:00
|
|
|
zeroed = true;
|
2017-01-16 08:56:30 +08:00
|
|
|
} else if ((*r_extent_hooks)->purge_forced != NULL &&
|
2016-12-04 07:38:25 +08:00
|
|
|
!(*r_extent_hooks)->purge_forced(*r_extent_hooks,
|
|
|
|
extent_base_get(extent), extent_size_get(extent), 0,
|
2017-01-16 08:56:30 +08:00
|
|
|
extent_size_get(extent), arena_ind_get(arena))) {
|
2016-12-04 07:38:25 +08:00
|
|
|
zeroed = true;
|
Implement two-phase decay-based purging.
Split decay-based purging into two phases, the first of which uses lazy
purging to convert dirty pages to "muzzy", and the second of which uses
forced purging, decommit, or unmapping to convert pages to clean or
destroy them altogether. Not all operating systems support lazy
purging, yet the application may provide extent hooks that implement
lazy purging, so care must be taken to dynamically omit the first phase
when necessary.
The mallctl interfaces change as follows:
- opt.decay_time --> opt.{dirty,muzzy}_decay_time
- arena.<i>.decay_time --> arena.<i>.{dirty,muzzy}_decay_time
- arenas.decay_time --> arenas.{dirty,muzzy}_decay_time
- stats.arenas.<i>.pdirty --> stats.arenas.<i>.p{dirty,muzzy}
- stats.arenas.<i>.{npurge,nmadvise,purged} -->
stats.arenas.<i>.{dirty,muzzy}_{npurge,nmadvise,purged}
This resolves #521.
2017-03-09 14:42:57 +08:00
|
|
|
} else if (extent_state_get(extent) == extent_state_muzzy ||
|
|
|
|
((*r_extent_hooks)->purge_lazy != NULL &&
|
|
|
|
!(*r_extent_hooks)->purge_lazy(*r_extent_hooks,
|
|
|
|
extent_base_get(extent), extent_size_get(extent), 0,
|
|
|
|
extent_size_get(extent), arena_ind_get(arena)))) {
|
|
|
|
zeroed = false;
|
2017-01-16 08:56:30 +08:00
|
|
|
} else {
|
2016-12-04 07:38:25 +08:00
|
|
|
zeroed = false;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2017-06-23 06:36:41 +08:00
|
|
|
if (*r_extent_hooks != &extent_hooks_default) {
|
2017-06-23 07:18:30 +08:00
|
|
|
extent_hook_post_reentrancy(tsdn);
|
2017-06-23 06:36:41 +08:00
|
|
|
}
|
2016-12-04 07:38:25 +08:00
|
|
|
extent_zeroed_set(extent, zeroed);
|
2016-06-02 03:59:02 +08:00
|
|
|
|
2017-01-16 08:56:30 +08:00
|
|
|
if (config_prof) {
|
2017-01-30 13:57:14 +08:00
|
|
|
extent_gdump_sub(tsdn, extent);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2016-06-02 03:59:02 +08:00
|
|
|
|
2017-01-30 13:57:14 +08:00
|
|
|
extent_record(tsdn, arena, r_extent_hooks, &arena->extents_retained,
|
2017-05-27 02:06:01 +08:00
|
|
|
extent, false);
|
2016-06-02 03:59:02 +08:00
|
|
|
}
|
|
|
|
|
2017-04-28 06:51:35 +08:00
|
|
|
static void
|
|
|
|
extent_destroy_default_impl(void *addr, size_t size) {
|
|
|
|
if (!have_dss || !extent_in_dss(addr)) {
|
|
|
|
pages_unmap(addr, size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
extent_destroy_default(extent_hooks_t *extent_hooks, void *addr, size_t size,
|
|
|
|
bool committed, unsigned arena_ind) {
|
|
|
|
extent_destroy_default_impl(addr, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
extent_destroy_wrapper(tsdn_t *tsdn, arena_t *arena,
|
|
|
|
extent_hooks_t **r_extent_hooks, extent_t *extent) {
|
|
|
|
assert(extent_base_get(extent) != NULL);
|
|
|
|
assert(extent_size_get(extent) != 0);
|
2017-05-23 10:32:04 +08:00
|
|
|
witness_assert_depth_to_rank(tsdn_witness_tsdp_get(tsdn),
|
|
|
|
WITNESS_RANK_CORE, 0);
|
2017-04-28 06:51:35 +08:00
|
|
|
|
|
|
|
/* Deregister first to avoid a race with other allocating threads. */
|
|
|
|
extent_deregister(tsdn, extent);
|
|
|
|
|
|
|
|
extent_addr_set(extent, extent_base_get(extent));
|
|
|
|
|
|
|
|
extent_hooks_assure_initialized(arena, r_extent_hooks);
|
|
|
|
/* Try to destroy; silently fail otherwise. */
|
|
|
|
if (*r_extent_hooks == &extent_hooks_default) {
|
|
|
|
/* Call directly to propagate tsdn. */
|
|
|
|
extent_destroy_default_impl(extent_base_get(extent),
|
|
|
|
extent_size_get(extent));
|
|
|
|
} else if ((*r_extent_hooks)->destroy != NULL) {
|
2017-06-23 07:18:30 +08:00
|
|
|
extent_hook_pre_reentrancy(tsdn, arena);
|
2017-04-28 06:51:35 +08:00
|
|
|
(*r_extent_hooks)->destroy(*r_extent_hooks,
|
|
|
|
extent_base_get(extent), extent_size_get(extent),
|
|
|
|
extent_committed_get(extent), arena_ind_get(arena));
|
2017-06-23 07:18:30 +08:00
|
|
|
extent_hook_post_reentrancy(tsdn);
|
2017-04-28 06:51:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
extent_dalloc(tsdn, arena, extent);
|
|
|
|
}
|
|
|
|
|
2016-06-02 03:59:02 +08:00
|
|
|
static bool
|
2016-06-04 03:05:53 +08:00
|
|
|
extent_commit_default(extent_hooks_t *extent_hooks, void *addr, size_t size,
|
2017-01-16 08:56:30 +08:00
|
|
|
size_t offset, size_t length, unsigned arena_ind) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return pages_commit((void *)((uintptr_t)addr + (uintptr_t)offset),
|
|
|
|
length);
|
2016-06-02 03:59:02 +08:00
|
|
|
}
|
|
|
|
|
2017-05-27 02:06:01 +08:00
|
|
|
static bool
|
|
|
|
extent_commit_impl(tsdn_t *tsdn, arena_t *arena,
|
2016-06-04 03:05:53 +08:00
|
|
|
extent_hooks_t **r_extent_hooks, extent_t *extent, size_t offset,
|
2017-05-27 02:06:01 +08:00
|
|
|
size_t length, bool growing_retained) {
|
2017-05-23 10:32:04 +08:00
|
|
|
witness_assert_depth_to_rank(tsdn_witness_tsdp_get(tsdn),
|
2017-05-27 02:06:01 +08:00
|
|
|
WITNESS_RANK_CORE, growing_retained ? 1 : 0);
|
2016-06-02 03:59:02 +08:00
|
|
|
|
2016-06-04 03:05:53 +08:00
|
|
|
extent_hooks_assure_initialized(arena, r_extent_hooks);
|
2017-06-23 06:36:41 +08:00
|
|
|
if (*r_extent_hooks != &extent_hooks_default) {
|
2017-06-23 07:18:30 +08:00
|
|
|
extent_hook_pre_reentrancy(tsdn, arena);
|
2017-06-23 06:36:41 +08:00
|
|
|
}
|
2017-01-30 13:57:14 +08:00
|
|
|
bool err = ((*r_extent_hooks)->commit == NULL ||
|
2016-12-04 07:38:25 +08:00
|
|
|
(*r_extent_hooks)->commit(*r_extent_hooks, extent_base_get(extent),
|
2016-12-23 06:39:10 +08:00
|
|
|
extent_size_get(extent), offset, length, arena_ind_get(arena)));
|
2017-06-23 06:36:41 +08:00
|
|
|
if (*r_extent_hooks != &extent_hooks_default) {
|
2017-06-23 07:18:30 +08:00
|
|
|
extent_hook_post_reentrancy(tsdn);
|
2017-06-23 06:36:41 +08:00
|
|
|
}
|
2016-06-06 14:24:52 +08:00
|
|
|
extent_committed_set(extent, extent_committed_get(extent) || !err);
|
2017-01-20 10:15:45 +08:00
|
|
|
return err;
|
2016-06-02 03:59:02 +08:00
|
|
|
}
|
|
|
|
|
2017-05-27 02:06:01 +08:00
|
|
|
bool
|
|
|
|
extent_commit_wrapper(tsdn_t *tsdn, arena_t *arena,
|
|
|
|
extent_hooks_t **r_extent_hooks, extent_t *extent, size_t offset,
|
|
|
|
size_t length) {
|
|
|
|
return extent_commit_impl(tsdn, arena, r_extent_hooks, extent, offset,
|
|
|
|
length, false);
|
|
|
|
}
|
|
|
|
|
2016-06-02 03:59:02 +08:00
|
|
|
static bool
|
2016-06-04 03:05:53 +08:00
|
|
|
extent_decommit_default(extent_hooks_t *extent_hooks, void *addr, size_t size,
|
2017-01-16 08:56:30 +08:00
|
|
|
size_t offset, size_t length, unsigned arena_ind) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return pages_decommit((void *)((uintptr_t)addr + (uintptr_t)offset),
|
|
|
|
length);
|
2016-06-02 03:59:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
extent_decommit_wrapper(tsdn_t *tsdn, arena_t *arena,
|
2016-06-04 03:05:53 +08:00
|
|
|
extent_hooks_t **r_extent_hooks, extent_t *extent, size_t offset,
|
2017-01-16 08:56:30 +08:00
|
|
|
size_t length) {
|
2017-05-23 10:32:04 +08:00
|
|
|
witness_assert_depth_to_rank(tsdn_witness_tsdp_get(tsdn),
|
|
|
|
WITNESS_RANK_CORE, 0);
|
2016-06-02 03:59:02 +08:00
|
|
|
|
2016-06-04 03:05:53 +08:00
|
|
|
extent_hooks_assure_initialized(arena, r_extent_hooks);
|
2016-06-06 14:24:52 +08:00
|
|
|
|
2017-06-23 06:36:41 +08:00
|
|
|
if (*r_extent_hooks != &extent_hooks_default) {
|
2017-06-23 07:18:30 +08:00
|
|
|
extent_hook_pre_reentrancy(tsdn, arena);
|
2017-06-23 06:36:41 +08:00
|
|
|
}
|
2017-01-30 13:57:14 +08:00
|
|
|
bool err = ((*r_extent_hooks)->decommit == NULL ||
|
2016-12-04 07:38:25 +08:00
|
|
|
(*r_extent_hooks)->decommit(*r_extent_hooks,
|
2016-06-04 03:05:53 +08:00
|
|
|
extent_base_get(extent), extent_size_get(extent), offset, length,
|
2016-12-23 06:39:10 +08:00
|
|
|
arena_ind_get(arena)));
|
2017-06-23 06:36:41 +08:00
|
|
|
if (*r_extent_hooks != &extent_hooks_default) {
|
2017-06-23 07:18:30 +08:00
|
|
|
extent_hook_post_reentrancy(tsdn);
|
2017-06-23 06:36:41 +08:00
|
|
|
}
|
2016-06-06 14:24:52 +08:00
|
|
|
extent_committed_set(extent, extent_committed_get(extent) && err);
|
2017-01-20 10:15:45 +08:00
|
|
|
return err;
|
2016-06-02 03:59:02 +08:00
|
|
|
}
|
|
|
|
|
2016-12-04 07:38:25 +08:00
|
|
|
#ifdef PAGES_CAN_PURGE_LAZY
|
2016-06-02 03:59:02 +08:00
|
|
|
static bool
|
2016-12-04 07:38:25 +08:00
|
|
|
extent_purge_lazy_default(extent_hooks_t *extent_hooks, void *addr, size_t size,
|
2017-01-16 08:56:30 +08:00
|
|
|
size_t offset, size_t length, unsigned arena_ind) {
|
2016-06-02 03:59:02 +08:00
|
|
|
assert(addr != NULL);
|
|
|
|
assert((offset & PAGE_MASK) == 0);
|
|
|
|
assert(length != 0);
|
|
|
|
assert((length & PAGE_MASK) == 0);
|
|
|
|
|
2017-01-20 10:15:45 +08:00
|
|
|
return pages_purge_lazy((void *)((uintptr_t)addr + (uintptr_t)offset),
|
|
|
|
length);
|
2016-06-02 03:59:02 +08:00
|
|
|
}
|
2016-12-04 07:38:25 +08:00
|
|
|
#endif
|
2016-06-02 03:59:02 +08:00
|
|
|
|
2017-05-27 02:06:01 +08:00
|
|
|
static bool
|
|
|
|
extent_purge_lazy_impl(tsdn_t *tsdn, arena_t *arena,
|
2016-06-04 03:05:53 +08:00
|
|
|
extent_hooks_t **r_extent_hooks, extent_t *extent, size_t offset,
|
2017-05-27 02:06:01 +08:00
|
|
|
size_t length, bool growing_retained) {
|
2017-05-23 10:32:04 +08:00
|
|
|
witness_assert_depth_to_rank(tsdn_witness_tsdp_get(tsdn),
|
2017-05-27 02:06:01 +08:00
|
|
|
WITNESS_RANK_CORE, growing_retained ? 1 : 0);
|
2017-01-30 13:57:14 +08:00
|
|
|
|
2016-06-04 03:05:53 +08:00
|
|
|
extent_hooks_assure_initialized(arena, r_extent_hooks);
|
2017-06-23 06:36:41 +08:00
|
|
|
|
|
|
|
if ((*r_extent_hooks)->purge_lazy == NULL) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (*r_extent_hooks != &extent_hooks_default) {
|
2017-06-23 07:18:30 +08:00
|
|
|
extent_hook_pre_reentrancy(tsdn, arena);
|
2017-06-23 06:36:41 +08:00
|
|
|
}
|
|
|
|
bool err = (*r_extent_hooks)->purge_lazy(*r_extent_hooks,
|
2016-06-04 03:05:53 +08:00
|
|
|
extent_base_get(extent), extent_size_get(extent), offset, length,
|
2017-06-23 06:36:41 +08:00
|
|
|
arena_ind_get(arena));
|
|
|
|
if (*r_extent_hooks != &extent_hooks_default) {
|
2017-06-23 07:18:30 +08:00
|
|
|
extent_hook_post_reentrancy(tsdn);
|
2017-06-23 06:36:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
2016-06-02 03:59:02 +08:00
|
|
|
}
|
|
|
|
|
2017-05-27 02:06:01 +08:00
|
|
|
bool
|
|
|
|
extent_purge_lazy_wrapper(tsdn_t *tsdn, arena_t *arena,
|
|
|
|
extent_hooks_t **r_extent_hooks, extent_t *extent, size_t offset,
|
|
|
|
size_t length) {
|
|
|
|
return extent_purge_lazy_impl(tsdn, arena, r_extent_hooks, extent,
|
|
|
|
offset, length, false);
|
|
|
|
}
|
|
|
|
|
2016-12-04 07:38:25 +08:00
|
|
|
#ifdef PAGES_CAN_PURGE_FORCED
|
|
|
|
static bool
|
|
|
|
extent_purge_forced_default(extent_hooks_t *extent_hooks, void *addr,
|
2017-01-16 08:56:30 +08:00
|
|
|
size_t size, size_t offset, size_t length, unsigned arena_ind) {
|
2016-12-04 07:38:25 +08:00
|
|
|
assert(addr != NULL);
|
|
|
|
assert((offset & PAGE_MASK) == 0);
|
|
|
|
assert(length != 0);
|
|
|
|
assert((length & PAGE_MASK) == 0);
|
|
|
|
|
2017-01-20 10:15:45 +08:00
|
|
|
return pages_purge_forced((void *)((uintptr_t)addr +
|
|
|
|
(uintptr_t)offset), length);
|
2016-12-04 07:38:25 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-05-27 02:06:01 +08:00
|
|
|
static bool
|
|
|
|
extent_purge_forced_impl(tsdn_t *tsdn, arena_t *arena,
|
2016-12-04 07:38:25 +08:00
|
|
|
extent_hooks_t **r_extent_hooks, extent_t *extent, size_t offset,
|
2017-05-27 02:06:01 +08:00
|
|
|
size_t length, bool growing_retained) {
|
2017-05-23 10:32:04 +08:00
|
|
|
witness_assert_depth_to_rank(tsdn_witness_tsdp_get(tsdn),
|
2017-05-27 02:06:01 +08:00
|
|
|
WITNESS_RANK_CORE, growing_retained ? 1 : 0);
|
2017-01-30 13:57:14 +08:00
|
|
|
|
2016-12-04 07:38:25 +08:00
|
|
|
extent_hooks_assure_initialized(arena, r_extent_hooks);
|
2017-06-23 06:36:41 +08:00
|
|
|
|
|
|
|
if ((*r_extent_hooks)->purge_forced == NULL) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (*r_extent_hooks != &extent_hooks_default) {
|
2017-06-23 07:18:30 +08:00
|
|
|
extent_hook_pre_reentrancy(tsdn, arena);
|
2017-06-23 06:36:41 +08:00
|
|
|
}
|
|
|
|
bool err = (*r_extent_hooks)->purge_forced(*r_extent_hooks,
|
2016-12-04 07:38:25 +08:00
|
|
|
extent_base_get(extent), extent_size_get(extent), offset, length,
|
2017-06-23 06:36:41 +08:00
|
|
|
arena_ind_get(arena));
|
|
|
|
if (*r_extent_hooks != &extent_hooks_default) {
|
2017-06-23 07:18:30 +08:00
|
|
|
extent_hook_post_reentrancy(tsdn);
|
2017-06-23 06:36:41 +08:00
|
|
|
}
|
|
|
|
return err;
|
2016-12-04 07:38:25 +08:00
|
|
|
}
|
|
|
|
|
2017-05-27 02:06:01 +08:00
|
|
|
bool
|
|
|
|
extent_purge_forced_wrapper(tsdn_t *tsdn, arena_t *arena,
|
|
|
|
extent_hooks_t **r_extent_hooks, extent_t *extent, size_t offset,
|
|
|
|
size_t length) {
|
|
|
|
return extent_purge_forced_impl(tsdn, arena, r_extent_hooks, extent,
|
|
|
|
offset, length, false);
|
|
|
|
}
|
|
|
|
|
2016-12-04 07:38:25 +08:00
|
|
|
#ifdef JEMALLOC_MAPS_COALESCE
|
2016-06-02 03:59:02 +08:00
|
|
|
static bool
|
2016-06-04 03:05:53 +08:00
|
|
|
extent_split_default(extent_hooks_t *extent_hooks, void *addr, size_t size,
|
2017-01-16 08:56:30 +08:00
|
|
|
size_t size_a, size_t size_b, bool committed, unsigned arena_ind) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return !maps_coalesce;
|
2016-06-02 03:59:02 +08:00
|
|
|
}
|
2016-12-04 07:38:25 +08:00
|
|
|
#endif
|
2016-06-02 03:59:02 +08:00
|
|
|
|
2017-08-29 09:27:12 +08:00
|
|
|
/*
|
|
|
|
* Accepts the extent to split, and the characteristics of each side of the
|
|
|
|
* split. The 'a' parameters go with the 'lead' of the resulting pair of
|
|
|
|
* extents (the lower addressed portion of the split), and the 'b' parameters go
|
|
|
|
* with the trail (the higher addressed portion). This makes 'extent' the lead,
|
|
|
|
* and returns the trail (except in case of error).
|
|
|
|
*/
|
2017-05-27 02:06:01 +08:00
|
|
|
static extent_t *
|
|
|
|
extent_split_impl(tsdn_t *tsdn, arena_t *arena,
|
2016-06-04 03:05:53 +08:00
|
|
|
extent_hooks_t **r_extent_hooks, extent_t *extent, size_t size_a,
|
2017-05-27 02:06:01 +08:00
|
|
|
szind_t szind_a, bool slab_a, size_t size_b, szind_t szind_b, bool slab_b,
|
|
|
|
bool growing_retained) {
|
2017-01-30 13:57:14 +08:00
|
|
|
assert(extent_size_get(extent) == size_a + size_b);
|
2017-05-23 10:32:04 +08:00
|
|
|
witness_assert_depth_to_rank(tsdn_witness_tsdp_get(tsdn),
|
2017-05-27 02:06:01 +08:00
|
|
|
WITNESS_RANK_CORE, growing_retained ? 1 : 0);
|
2017-01-30 13:57:14 +08:00
|
|
|
|
2016-06-04 03:05:53 +08:00
|
|
|
extent_hooks_assure_initialized(arena, r_extent_hooks);
|
2016-06-02 03:59:02 +08:00
|
|
|
|
2017-01-16 08:56:30 +08:00
|
|
|
if ((*r_extent_hooks)->split == NULL) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return NULL;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2016-12-04 07:38:25 +08:00
|
|
|
|
2017-05-16 05:23:51 +08:00
|
|
|
extent_t *trail = extent_alloc(tsdn, arena);
|
2017-01-16 08:56:30 +08:00
|
|
|
if (trail == NULL) {
|
2016-06-02 03:59:02 +08:00
|
|
|
goto label_error_a;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2016-06-02 03:59:02 +08:00
|
|
|
|
2017-05-16 05:23:51 +08:00
|
|
|
extent_init(trail, arena, (void *)((uintptr_t)extent_base_get(extent) +
|
|
|
|
size_a), size_b, slab_b, szind_b, extent_sn_get(extent),
|
|
|
|
extent_state_get(extent), extent_zeroed_get(extent),
|
2017-09-19 08:25:57 +08:00
|
|
|
extent_committed_get(extent), extent_dumpable_get(extent));
|
2017-05-16 05:23:51 +08:00
|
|
|
|
|
|
|
rtree_ctx_t rtree_ctx_fallback;
|
|
|
|
rtree_ctx_t *rtree_ctx = tsdn_rtree_ctx(tsdn, &rtree_ctx_fallback);
|
|
|
|
rtree_leaf_elm_t *lead_elm_a, *lead_elm_b;
|
2016-06-02 03:59:02 +08:00
|
|
|
{
|
|
|
|
extent_t lead;
|
|
|
|
|
|
|
|
extent_init(&lead, arena, extent_addr_get(extent), size_a,
|
2017-03-17 08:57:52 +08:00
|
|
|
slab_a, szind_a, extent_sn_get(extent),
|
2017-03-14 08:36:57 +08:00
|
|
|
extent_state_get(extent), extent_zeroed_get(extent),
|
2017-09-19 08:25:57 +08:00
|
|
|
extent_committed_get(extent), extent_dumpable_get(extent));
|
2016-06-02 03:59:02 +08:00
|
|
|
|
2017-05-16 05:23:51 +08:00
|
|
|
extent_rtree_leaf_elms_lookup(tsdn, rtree_ctx, &lead, false,
|
|
|
|
true, &lead_elm_a, &lead_elm_b);
|
2016-06-02 03:59:02 +08:00
|
|
|
}
|
2017-05-16 05:23:51 +08:00
|
|
|
rtree_leaf_elm_t *trail_elm_a, *trail_elm_b;
|
|
|
|
extent_rtree_leaf_elms_lookup(tsdn, rtree_ctx, trail, false, true,
|
|
|
|
&trail_elm_a, &trail_elm_b);
|
2016-06-02 03:59:02 +08:00
|
|
|
|
2017-05-16 05:23:51 +08:00
|
|
|
if (lead_elm_a == NULL || lead_elm_b == NULL || trail_elm_a == NULL
|
|
|
|
|| trail_elm_b == NULL) {
|
|
|
|
goto label_error_b;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2016-06-02 03:59:02 +08:00
|
|
|
|
2017-05-16 05:23:51 +08:00
|
|
|
extent_lock2(tsdn, extent, trail);
|
|
|
|
|
2017-06-23 06:36:41 +08:00
|
|
|
if (*r_extent_hooks != &extent_hooks_default) {
|
2017-06-23 07:18:30 +08:00
|
|
|
extent_hook_pre_reentrancy(tsdn, arena);
|
2017-06-23 06:36:41 +08:00
|
|
|
}
|
|
|
|
bool err = (*r_extent_hooks)->split(*r_extent_hooks, extent_base_get(extent),
|
2016-06-04 03:05:53 +08:00
|
|
|
size_a + size_b, size_a, size_b, extent_committed_get(extent),
|
2017-06-23 06:36:41 +08:00
|
|
|
arena_ind_get(arena));
|
|
|
|
if (*r_extent_hooks != &extent_hooks_default) {
|
2017-06-23 07:18:30 +08:00
|
|
|
extent_hook_post_reentrancy(tsdn);
|
2017-06-23 06:36:41 +08:00
|
|
|
}
|
|
|
|
if (err) {
|
2017-05-16 05:23:51 +08:00
|
|
|
goto label_error_c;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2016-06-02 03:59:02 +08:00
|
|
|
|
|
|
|
extent_size_set(extent, size_a);
|
2017-03-14 08:36:57 +08:00
|
|
|
extent_szind_set(extent, szind_a);
|
2016-06-02 03:59:02 +08:00
|
|
|
|
2017-03-17 08:57:52 +08:00
|
|
|
extent_rtree_write_acquired(tsdn, lead_elm_a, lead_elm_b, extent,
|
|
|
|
szind_a, slab_a);
|
|
|
|
extent_rtree_write_acquired(tsdn, trail_elm_a, trail_elm_b, trail,
|
|
|
|
szind_b, slab_b);
|
2016-06-02 03:59:02 +08:00
|
|
|
|
2017-05-16 05:23:51 +08:00
|
|
|
extent_unlock2(tsdn, extent, trail);
|
2016-06-02 03:59:02 +08:00
|
|
|
|
2017-01-20 10:15:45 +08:00
|
|
|
return trail;
|
2016-06-02 03:59:02 +08:00
|
|
|
label_error_c:
|
2017-05-16 05:23:51 +08:00
|
|
|
extent_unlock2(tsdn, extent, trail);
|
2016-06-02 03:59:02 +08:00
|
|
|
label_error_b:
|
|
|
|
extent_dalloc(tsdn, arena, trail);
|
|
|
|
label_error_a:
|
2017-01-20 10:15:45 +08:00
|
|
|
return NULL;
|
2016-06-02 03:59:02 +08:00
|
|
|
}
|
|
|
|
|
2017-05-27 02:06:01 +08:00
|
|
|
extent_t *
|
|
|
|
extent_split_wrapper(tsdn_t *tsdn, arena_t *arena,
|
|
|
|
extent_hooks_t **r_extent_hooks, extent_t *extent, size_t size_a,
|
|
|
|
szind_t szind_a, bool slab_a, size_t size_b, szind_t szind_b, bool slab_b) {
|
|
|
|
return extent_split_impl(tsdn, arena, r_extent_hooks, extent, size_a,
|
|
|
|
szind_a, slab_a, size_b, szind_b, slab_b, false);
|
|
|
|
}
|
|
|
|
|
2016-06-02 03:59:02 +08:00
|
|
|
static bool
|
2017-01-16 08:56:30 +08:00
|
|
|
extent_merge_default_impl(void *addr_a, void *addr_b) {
|
|
|
|
if (!maps_coalesce) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return true;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
|
|
|
if (have_dss && !extent_dss_mergeable(addr_a, addr_b)) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return true;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2016-06-02 03:59:02 +08:00
|
|
|
|
2017-01-20 10:15:45 +08:00
|
|
|
return false;
|
2016-06-02 03:59:02 +08:00
|
|
|
}
|
|
|
|
|
2016-12-04 07:38:25 +08:00
|
|
|
#ifdef JEMALLOC_MAPS_COALESCE
|
2016-06-08 04:37:22 +08:00
|
|
|
static bool
|
|
|
|
extent_merge_default(extent_hooks_t *extent_hooks, void *addr_a, size_t size_a,
|
2017-01-16 08:56:30 +08:00
|
|
|
void *addr_b, size_t size_b, bool committed, unsigned arena_ind) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return extent_merge_default_impl(addr_a, addr_b);
|
2016-06-08 04:37:22 +08:00
|
|
|
}
|
2016-12-04 07:38:25 +08:00
|
|
|
#endif
|
2016-06-08 04:37:22 +08:00
|
|
|
|
2017-05-27 02:06:01 +08:00
|
|
|
static bool
|
|
|
|
extent_merge_impl(tsdn_t *tsdn, arena_t *arena,
|
|
|
|
extent_hooks_t **r_extent_hooks, extent_t *a, extent_t *b,
|
|
|
|
bool growing_retained) {
|
2017-05-23 10:32:04 +08:00
|
|
|
witness_assert_depth_to_rank(tsdn_witness_tsdp_get(tsdn),
|
2017-05-27 02:06:01 +08:00
|
|
|
WITNESS_RANK_CORE, growing_retained ? 1 : 0);
|
2016-06-02 03:59:02 +08:00
|
|
|
|
2016-06-04 03:05:53 +08:00
|
|
|
extent_hooks_assure_initialized(arena, r_extent_hooks);
|
2016-12-04 07:38:25 +08:00
|
|
|
|
2017-01-16 08:56:30 +08:00
|
|
|
if ((*r_extent_hooks)->merge == NULL) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return true;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2016-12-04 07:38:25 +08:00
|
|
|
|
2017-01-30 13:57:14 +08:00
|
|
|
bool err;
|
2016-06-08 04:37:22 +08:00
|
|
|
if (*r_extent_hooks == &extent_hooks_default) {
|
|
|
|
/* Call directly to propagate tsdn. */
|
2016-10-14 03:18:38 +08:00
|
|
|
err = extent_merge_default_impl(extent_base_get(a),
|
2016-06-08 04:37:22 +08:00
|
|
|
extent_base_get(b));
|
|
|
|
} else {
|
2017-06-23 07:18:30 +08:00
|
|
|
extent_hook_pre_reentrancy(tsdn, arena);
|
2016-06-08 04:37:22 +08:00
|
|
|
err = (*r_extent_hooks)->merge(*r_extent_hooks,
|
|
|
|
extent_base_get(a), extent_size_get(a), extent_base_get(b),
|
2016-12-23 06:39:10 +08:00
|
|
|
extent_size_get(b), extent_committed_get(a),
|
|
|
|
arena_ind_get(arena));
|
2017-06-23 07:18:30 +08:00
|
|
|
extent_hook_post_reentrancy(tsdn);
|
2016-06-08 04:37:22 +08:00
|
|
|
}
|
|
|
|
|
2017-01-16 08:56:30 +08:00
|
|
|
if (err) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return true;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2016-06-02 03:59:02 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The rtree writes must happen while all the relevant elements are
|
|
|
|
* owned, so the following code uses decomposed helper functions rather
|
|
|
|
* than extent_{,de}register() to do things in the right order.
|
|
|
|
*/
|
2017-01-30 13:57:14 +08:00
|
|
|
rtree_ctx_t rtree_ctx_fallback;
|
|
|
|
rtree_ctx_t *rtree_ctx = tsdn_rtree_ctx(tsdn, &rtree_ctx_fallback);
|
2017-03-17 00:46:42 +08:00
|
|
|
rtree_leaf_elm_t *a_elm_a, *a_elm_b, *b_elm_a, *b_elm_b;
|
2017-05-16 05:23:51 +08:00
|
|
|
extent_rtree_leaf_elms_lookup(tsdn, rtree_ctx, a, true, false, &a_elm_a,
|
2016-06-03 09:43:10 +08:00
|
|
|
&a_elm_b);
|
2017-05-16 05:23:51 +08:00
|
|
|
extent_rtree_leaf_elms_lookup(tsdn, rtree_ctx, b, true, false, &b_elm_a,
|
2016-06-03 09:43:10 +08:00
|
|
|
&b_elm_b);
|
2016-06-02 03:59:02 +08:00
|
|
|
|
2017-05-16 05:23:51 +08:00
|
|
|
extent_lock2(tsdn, a, b);
|
|
|
|
|
2016-06-02 03:59:02 +08:00
|
|
|
if (a_elm_b != NULL) {
|
2017-05-16 05:23:51 +08:00
|
|
|
rtree_leaf_elm_write(tsdn, &extents_rtree, a_elm_b, NULL,
|
2017-12-15 04:46:39 +08:00
|
|
|
SC_NSIZES, false);
|
2016-06-02 03:59:02 +08:00
|
|
|
}
|
|
|
|
if (b_elm_b != NULL) {
|
2017-05-16 05:23:51 +08:00
|
|
|
rtree_leaf_elm_write(tsdn, &extents_rtree, b_elm_a, NULL,
|
2017-12-15 04:46:39 +08:00
|
|
|
SC_NSIZES, false);
|
2017-01-16 08:56:30 +08:00
|
|
|
} else {
|
2016-06-02 03:59:02 +08:00
|
|
|
b_elm_b = b_elm_a;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2016-06-02 03:59:02 +08:00
|
|
|
|
|
|
|
extent_size_set(a, extent_size_get(a) + extent_size_get(b));
|
2017-12-15 04:46:39 +08:00
|
|
|
extent_szind_set(a, SC_NSIZES);
|
2016-11-16 05:07:53 +08:00
|
|
|
extent_sn_set(a, (extent_sn_get(a) < extent_sn_get(b)) ?
|
|
|
|
extent_sn_get(a) : extent_sn_get(b));
|
2016-06-02 03:59:02 +08:00
|
|
|
extent_zeroed_set(a, extent_zeroed_get(a) && extent_zeroed_get(b));
|
|
|
|
|
2017-12-15 04:46:39 +08:00
|
|
|
extent_rtree_write_acquired(tsdn, a_elm_a, b_elm_b, a, SC_NSIZES,
|
|
|
|
false);
|
2017-05-16 05:23:51 +08:00
|
|
|
|
|
|
|
extent_unlock2(tsdn, a, b);
|
2016-06-02 03:59:02 +08:00
|
|
|
|
|
|
|
extent_dalloc(tsdn, extent_arena_get(b), b);
|
|
|
|
|
2017-01-20 10:15:45 +08:00
|
|
|
return false;
|
2016-06-02 03:59:02 +08:00
|
|
|
}
|
|
|
|
|
2017-05-27 02:06:01 +08:00
|
|
|
bool
|
|
|
|
extent_merge_wrapper(tsdn_t *tsdn, arena_t *arena,
|
|
|
|
extent_hooks_t **r_extent_hooks, extent_t *a, extent_t *b) {
|
|
|
|
return extent_merge_impl(tsdn, arena, r_extent_hooks, a, b, false);
|
|
|
|
}
|
|
|
|
|
2016-06-02 03:10:39 +08:00
|
|
|
bool
|
2017-01-16 08:56:30 +08:00
|
|
|
extent_boot(void) {
|
2017-03-23 07:38:03 +08:00
|
|
|
if (rtree_new(&extents_rtree, true)) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return true;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2016-06-02 03:10:39 +08:00
|
|
|
|
2017-05-16 05:23:51 +08:00
|
|
|
if (mutex_pool_init(&extent_mutex_pool, "extent_mutex_pool",
|
|
|
|
WITNESS_RANK_EXTENT_POOL)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-01-16 08:56:30 +08:00
|
|
|
if (have_dss) {
|
2016-10-14 03:18:38 +08:00
|
|
|
extent_dss_boot();
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2016-06-02 03:59:02 +08:00
|
|
|
|
2017-01-20 10:15:45 +08:00
|
|
|
return false;
|
2016-06-02 03:10:39 +08:00
|
|
|
}
|