2017-01-20 13:41:41 +08:00
|
|
|
#define JEMALLOC_ARENA_C_
|
2017-04-11 09:17:55 +08:00
|
|
|
#include "jemalloc/internal/jemalloc_preamble.h"
|
|
|
|
#include "jemalloc/internal/jemalloc_internal_includes.h"
|
2010-01-17 01:53:50 +08:00
|
|
|
|
2017-04-12 04:31:16 +08:00
|
|
|
#include "jemalloc/internal/util.h"
|
|
|
|
|
2010-01-17 01:53:50 +08:00
|
|
|
/******************************************************************************/
|
|
|
|
/* Data. */
|
|
|
|
|
Implement per-CPU arena.
The new feature, opt.percpu_arena, determines thread-arena association
dynamically based CPU id. Three modes are supported: "percpu", "phycpu"
and disabled.
"percpu" uses the current core id (with help from sched_getcpu())
directly as the arena index, while "phycpu" will assign threads on the
same physical CPU to the same arena. In other words, "percpu" means # of
arenas == # of CPUs, while "phycpu" has # of arenas == 1/2 * (# of
CPUs). Note that no runtime check on whether hyper threading is enabled
is added yet.
When enabled, threads will be migrated between arenas when a CPU change
is detected. In the current design, to reduce overhead from reading CPU
id, each arena tracks the thread accessed most recently. When a new
thread comes in, we will read CPU id and update arena if necessary.
2017-02-03 09:02:05 +08:00
|
|
|
const char *percpu_arena_mode_names[] = {
|
|
|
|
"disabled",
|
|
|
|
"percpu",
|
|
|
|
"phycpu"
|
|
|
|
};
|
|
|
|
|
|
|
|
const char *opt_percpu_arena = OPT_PERCPU_ARENA_DEFAULT;
|
|
|
|
percpu_arena_mode_t percpu_arena_mode = PERCPU_ARENA_MODE_DEFAULT;
|
|
|
|
|
2017-04-05 08:22:24 +08:00
|
|
|
ssize_t opt_dirty_decay_time = DIRTY_DECAY_TIME_DEFAULT;
|
|
|
|
ssize_t opt_muzzy_decay_time = MUZZY_DECAY_TIME_DEFAULT;
|
|
|
|
|
|
|
|
static atomic_zd_t dirty_decay_time_default;
|
|
|
|
static atomic_zd_t muzzy_decay_time_default;
|
2016-02-20 12:09:31 +08:00
|
|
|
|
2016-04-07 20:04:12 +08:00
|
|
|
const arena_bin_info_t arena_bin_info[NBINS] = {
|
2017-01-20 13:41:41 +08:00
|
|
|
#define BIN_INFO_bin_yes(reg_size, slab_size, nregs) \
|
2016-05-30 09:34:50 +08:00
|
|
|
{reg_size, slab_size, nregs, BITMAP_INFO_INITIALIZER(nregs)},
|
2017-01-20 13:41:41 +08:00
|
|
|
#define BIN_INFO_bin_no(reg_size, slab_size, nregs)
|
|
|
|
#define SC(index, lg_grp, lg_delta, ndelta, psz, bin, pgs, \
|
2016-04-18 07:16:11 +08:00
|
|
|
lg_delta_lookup) \
|
2016-04-07 20:04:12 +08:00
|
|
|
BIN_INFO_bin_##bin((1U<<lg_grp) + (ndelta<<lg_delta), \
|
|
|
|
(pgs << LG_PAGE), (pgs << LG_PAGE) / ((1U<<lg_grp) + \
|
|
|
|
(ndelta<<lg_delta)))
|
|
|
|
SIZE_CLASSES
|
|
|
|
#undef BIN_INFO_bin_yes
|
|
|
|
#undef BIN_INFO_bin_no
|
|
|
|
#undef SC
|
|
|
|
};
|
2010-01-17 01:53:50 +08:00
|
|
|
|
|
|
|
/******************************************************************************/
|
2014-01-15 08:23:03 +08:00
|
|
|
/*
|
|
|
|
* Function prototypes for static functions that are referenced prior to
|
|
|
|
* definition.
|
|
|
|
*/
|
|
|
|
|
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 void arena_decay_to_limit(tsdn_t *tsdn, arena_t *arena,
|
|
|
|
arena_decay_t *decay, extents_t *extents, bool all, size_t npages_limit);
|
|
|
|
static void arena_decay_dirty(tsdn_t *tsdn, arena_t *arena, bool all);
|
|
|
|
static void arena_dalloc_bin_slab(tsdn_t *tsdn, arena_t *arena, extent_t *slab,
|
|
|
|
arena_bin_t *bin);
|
|
|
|
static void arena_bin_lower_slab(tsdn_t *tsdn, arena_t *arena, extent_t *slab,
|
|
|
|
arena_bin_t *bin);
|
2010-01-17 01:53:50 +08:00
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2017-02-13 09:43:33 +08:00
|
|
|
static bool
|
|
|
|
arena_stats_init(tsdn_t *tsdn, arena_stats_t *arena_stats) {
|
|
|
|
if (config_debug) {
|
|
|
|
for (size_t i = 0; i < sizeof(arena_stats_t); i++) {
|
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(((char *)arena_stats)[i] == 0);
|
2017-02-13 09:43:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifndef JEMALLOC_ATOMIC_U64
|
|
|
|
if (malloc_mutex_init(&arena_stats->mtx, "arena_stats",
|
|
|
|
WITNESS_RANK_ARENA_STATS)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
/* Memory is zeroed, so there is no need to clear stats. */
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
arena_stats_lock(tsdn_t *tsdn, arena_stats_t *arena_stats) {
|
|
|
|
#ifndef JEMALLOC_ATOMIC_U64
|
|
|
|
malloc_mutex_lock(tsdn, &arena_stats->mtx);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
arena_stats_unlock(tsdn_t *tsdn, arena_stats_t *arena_stats) {
|
|
|
|
#ifndef JEMALLOC_ATOMIC_U64
|
|
|
|
malloc_mutex_unlock(tsdn, &arena_stats->mtx);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint64_t
|
2017-03-09 07:56:31 +08:00
|
|
|
arena_stats_read_u64(tsdn_t *tsdn, arena_stats_t *arena_stats,
|
|
|
|
arena_stats_u64_t *p) {
|
2017-02-13 09:43:33 +08:00
|
|
|
#ifdef JEMALLOC_ATOMIC_U64
|
2017-03-09 07:56:31 +08:00
|
|
|
return atomic_load_u64(p, ATOMIC_RELAXED);
|
2017-02-13 09:43:33 +08:00
|
|
|
#else
|
|
|
|
malloc_mutex_assert_owner(tsdn, &arena_stats->mtx);
|
|
|
|
return *p;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-03-09 07:56:31 +08:00
|
|
|
arena_stats_add_u64(tsdn_t *tsdn, arena_stats_t *arena_stats,
|
|
|
|
arena_stats_u64_t *p, uint64_t x) {
|
2017-02-13 09:43:33 +08:00
|
|
|
#ifdef JEMALLOC_ATOMIC_U64
|
2017-03-09 07:56:31 +08:00
|
|
|
atomic_fetch_add_u64(p, x, ATOMIC_RELAXED);
|
2017-02-13 09:43:33 +08:00
|
|
|
#else
|
|
|
|
malloc_mutex_assert_owner(tsdn, &arena_stats->mtx);
|
|
|
|
*p += x;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-03-04 12:44:39 +08:00
|
|
|
UNUSED static void
|
2017-03-09 07:56:31 +08:00
|
|
|
arena_stats_sub_u64(tsdn_t *tsdn, arena_stats_t *arena_stats,
|
|
|
|
arena_stats_u64_t *p, uint64_t x) {
|
2017-02-13 09:43:33 +08:00
|
|
|
#ifdef JEMALLOC_ATOMIC_U64
|
2017-03-09 07:56:31 +08:00
|
|
|
UNUSED uint64_t r = atomic_fetch_sub_u64(p, x, ATOMIC_RELAXED);
|
|
|
|
assert(r - x <= r);
|
2017-02-13 09:43:33 +08:00
|
|
|
#else
|
|
|
|
malloc_mutex_assert_owner(tsdn, &arena_stats->mtx);
|
|
|
|
*p -= x;
|
2017-02-14 02:35:41 +08:00
|
|
|
assert(*p + x >= *p);
|
2017-02-13 09:43:33 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-03-09 07:56:31 +08:00
|
|
|
/*
|
|
|
|
* Non-atomically sets *dst += src. *dst needs external synchronization.
|
|
|
|
* This lets us avoid the cost of a fetch_add when its unnecessary (note that
|
|
|
|
* the types here are atomic).
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
arena_stats_accum_u64(arena_stats_u64_t *dst, uint64_t src) {
|
|
|
|
#ifdef JEMALLOC_ATOMIC_U64
|
|
|
|
uint64_t cur_dst = atomic_load_u64(dst, ATOMIC_RELAXED);
|
|
|
|
atomic_store_u64(dst, src + cur_dst, ATOMIC_RELAXED);
|
|
|
|
#else
|
|
|
|
*dst += src;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-02-13 09:43:33 +08:00
|
|
|
static size_t
|
2017-03-14 07:18:40 +08:00
|
|
|
arena_stats_read_zu(tsdn_t *tsdn, arena_stats_t *arena_stats, atomic_zu_t *p) {
|
2017-02-13 09:43:33 +08:00
|
|
|
#ifdef JEMALLOC_ATOMIC_U64
|
2017-03-14 07:18:40 +08:00
|
|
|
return atomic_load_zu(p, ATOMIC_RELAXED);
|
2017-02-13 09:43:33 +08:00
|
|
|
#else
|
|
|
|
malloc_mutex_assert_owner(tsdn, &arena_stats->mtx);
|
2017-03-14 07:18:40 +08:00
|
|
|
return atomic_load_zu(p, ATOMIC_RELAXED);
|
2017-02-13 09:43:33 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-03-14 07:18:40 +08:00
|
|
|
arena_stats_add_zu(tsdn_t *tsdn, arena_stats_t *arena_stats, atomic_zu_t *p,
|
2017-02-13 09:43:33 +08:00
|
|
|
size_t x) {
|
|
|
|
#ifdef JEMALLOC_ATOMIC_U64
|
2017-03-14 07:18:40 +08:00
|
|
|
atomic_fetch_add_zu(p, x, ATOMIC_RELAXED);
|
2017-02-13 09:43:33 +08:00
|
|
|
#else
|
|
|
|
malloc_mutex_assert_owner(tsdn, &arena_stats->mtx);
|
2017-03-14 07:18:40 +08:00
|
|
|
size_t cur = atomic_load_zu(p, ATOMIC_RELAXED);
|
|
|
|
atomic_store_zu(p, cur + x, ATOMIC_RELAXED);
|
2017-02-13 09:43:33 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-03-14 07:18:40 +08:00
|
|
|
arena_stats_sub_zu(tsdn_t *tsdn, arena_stats_t *arena_stats, atomic_zu_t *p,
|
2017-02-13 09:43:33 +08:00
|
|
|
size_t x) {
|
|
|
|
#ifdef JEMALLOC_ATOMIC_U64
|
2017-03-14 07:18:40 +08:00
|
|
|
UNUSED size_t r = atomic_fetch_sub_zu(p, x, ATOMIC_RELAXED);
|
|
|
|
assert(r - x <= r);
|
2017-02-13 09:43:33 +08:00
|
|
|
#else
|
|
|
|
malloc_mutex_assert_owner(tsdn, &arena_stats->mtx);
|
2017-03-14 07:18:40 +08:00
|
|
|
size_t cur = atomic_load_zu(p, ATOMIC_RELAXED);
|
|
|
|
atomic_store_zu(p, cur - x, ATOMIC_RELAXED);
|
2017-02-13 09:43:33 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-03-14 07:18:40 +08:00
|
|
|
/* Like the _u64 variant, needs an externally synchronized *dst. */
|
|
|
|
static void
|
|
|
|
arena_stats_accum_zu(atomic_zu_t *dst, size_t src) {
|
|
|
|
size_t cur_dst = atomic_load_zu(dst, ATOMIC_RELAXED);
|
|
|
|
atomic_store_zu(dst, src + cur_dst, ATOMIC_RELAXED);
|
|
|
|
}
|
|
|
|
|
2017-02-13 09:43:33 +08:00
|
|
|
void
|
|
|
|
arena_stats_large_nrequests_add(tsdn_t *tsdn, arena_stats_t *arena_stats,
|
|
|
|
szind_t szind, uint64_t nrequests) {
|
|
|
|
arena_stats_lock(tsdn, arena_stats);
|
|
|
|
arena_stats_add_u64(tsdn, arena_stats, &arena_stats->lstats[szind -
|
|
|
|
NBINS].nrequests, nrequests);
|
|
|
|
arena_stats_unlock(tsdn, arena_stats);
|
|
|
|
}
|
|
|
|
|
2017-02-14 02:35:41 +08:00
|
|
|
void
|
|
|
|
arena_stats_mapped_add(tsdn_t *tsdn, arena_stats_t *arena_stats, size_t size) {
|
|
|
|
arena_stats_lock(tsdn, arena_stats);
|
|
|
|
arena_stats_add_zu(tsdn, arena_stats, &arena_stats->mapped, size);
|
|
|
|
arena_stats_unlock(tsdn, arena_stats);
|
|
|
|
}
|
|
|
|
|
2017-02-13 09:43:33 +08:00
|
|
|
void
|
|
|
|
arena_basic_stats_merge(tsdn_t *tsdn, arena_t *arena, unsigned *nthreads,
|
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
|
|
|
const char **dss, ssize_t *dirty_decay_time, ssize_t *muzzy_decay_time,
|
|
|
|
size_t *nactive, size_t *ndirty,
|
|
|
|
size_t *nmuzzy) {
|
2017-02-13 09:43:33 +08:00
|
|
|
*nthreads += arena_nthreads_get(arena, false);
|
|
|
|
*dss = dss_prec_names[arena_dss_prec_get(arena)];
|
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
|
|
|
*dirty_decay_time = arena_dirty_decay_time_get(arena);
|
|
|
|
*muzzy_decay_time = arena_muzzy_decay_time_get(arena);
|
2017-04-05 08:22:24 +08:00
|
|
|
*nactive += atomic_load_zu(&arena->nactive, ATOMIC_RELAXED);
|
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
|
|
|
*ndirty += extents_npages_get(&arena->extents_dirty);
|
|
|
|
*nmuzzy += extents_npages_get(&arena->extents_muzzy);
|
2017-02-13 09:43:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
arena_stats_merge(tsdn_t *tsdn, arena_t *arena, unsigned *nthreads,
|
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
|
|
|
const char **dss, ssize_t *dirty_decay_time, ssize_t *muzzy_decay_time,
|
|
|
|
size_t *nactive, size_t *ndirty, size_t *nmuzzy, arena_stats_t *astats,
|
|
|
|
malloc_bin_stats_t *bstats, malloc_large_stats_t *lstats) {
|
2017-02-13 09:43:33 +08:00
|
|
|
cassert(config_stats);
|
|
|
|
|
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
|
|
|
arena_basic_stats_merge(tsdn, arena, nthreads, dss, dirty_decay_time,
|
|
|
|
muzzy_decay_time, nactive, ndirty, nmuzzy);
|
2017-02-13 09:43:33 +08:00
|
|
|
|
2017-02-14 01:44:46 +08:00
|
|
|
size_t base_allocated, base_resident, base_mapped;
|
2017-02-13 09:43:33 +08:00
|
|
|
base_stats_get(tsdn, arena->base, &base_allocated, &base_resident,
|
|
|
|
&base_mapped);
|
|
|
|
|
|
|
|
arena_stats_lock(tsdn, &arena->stats);
|
|
|
|
|
2017-03-14 07:18:40 +08:00
|
|
|
arena_stats_accum_zu(&astats->mapped, base_mapped
|
|
|
|
+ arena_stats_read_zu(tsdn, &arena->stats, &arena->stats.mapped));
|
|
|
|
arena_stats_accum_zu(&astats->retained,
|
|
|
|
extents_npages_get(&arena->extents_retained) << LG_PAGE);
|
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
|
|
|
|
|
|
|
arena_stats_accum_u64(&astats->decay_dirty.npurge,
|
|
|
|
arena_stats_read_u64(tsdn, &arena->stats,
|
|
|
|
&arena->stats.decay_dirty.npurge));
|
|
|
|
arena_stats_accum_u64(&astats->decay_dirty.nmadvise,
|
|
|
|
arena_stats_read_u64(tsdn, &arena->stats,
|
|
|
|
&arena->stats.decay_dirty.nmadvise));
|
|
|
|
arena_stats_accum_u64(&astats->decay_dirty.purged,
|
|
|
|
arena_stats_read_u64(tsdn, &arena->stats,
|
|
|
|
&arena->stats.decay_dirty.purged));
|
|
|
|
|
|
|
|
arena_stats_accum_u64(&astats->decay_muzzy.npurge,
|
|
|
|
arena_stats_read_u64(tsdn, &arena->stats,
|
|
|
|
&arena->stats.decay_muzzy.npurge));
|
|
|
|
arena_stats_accum_u64(&astats->decay_muzzy.nmadvise,
|
|
|
|
arena_stats_read_u64(tsdn, &arena->stats,
|
|
|
|
&arena->stats.decay_muzzy.nmadvise));
|
|
|
|
arena_stats_accum_u64(&astats->decay_muzzy.purged,
|
|
|
|
arena_stats_read_u64(tsdn, &arena->stats,
|
|
|
|
&arena->stats.decay_muzzy.purged));
|
|
|
|
|
2017-03-14 07:18:40 +08:00
|
|
|
arena_stats_accum_zu(&astats->base, base_allocated);
|
|
|
|
arena_stats_accum_zu(&astats->internal, arena_internal_get(arena));
|
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
|
|
|
arena_stats_accum_zu(&astats->resident, base_resident +
|
2017-04-05 08:22:24 +08:00
|
|
|
(((atomic_load_zu(&arena->nactive, ATOMIC_RELAXED) +
|
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
|
|
|
extents_npages_get(&arena->extents_dirty) +
|
|
|
|
extents_npages_get(&arena->extents_muzzy)) << LG_PAGE)));
|
2017-02-26 06:10:05 +08:00
|
|
|
|
2017-02-14 01:44:46 +08:00
|
|
|
for (szind_t i = 0; i < NSIZES - NBINS; i++) {
|
|
|
|
uint64_t nmalloc = arena_stats_read_u64(tsdn, &arena->stats,
|
2017-02-13 09:43:33 +08:00
|
|
|
&arena->stats.lstats[i].nmalloc);
|
2017-03-09 07:56:31 +08:00
|
|
|
arena_stats_accum_u64(&lstats[i].nmalloc, nmalloc);
|
|
|
|
arena_stats_accum_u64(&astats->nmalloc_large, nmalloc);
|
2017-02-14 01:44:46 +08:00
|
|
|
|
|
|
|
uint64_t ndalloc = arena_stats_read_u64(tsdn, &arena->stats,
|
2017-02-13 09:43:33 +08:00
|
|
|
&arena->stats.lstats[i].ndalloc);
|
2017-03-09 07:56:31 +08:00
|
|
|
arena_stats_accum_u64(&lstats[i].ndalloc, ndalloc);
|
|
|
|
arena_stats_accum_u64(&astats->ndalloc_large, ndalloc);
|
2017-02-14 01:44:46 +08:00
|
|
|
|
|
|
|
uint64_t nrequests = arena_stats_read_u64(tsdn, &arena->stats,
|
2017-02-13 09:43:33 +08:00
|
|
|
&arena->stats.lstats[i].nrequests);
|
2017-03-09 07:56:31 +08:00
|
|
|
arena_stats_accum_u64(&lstats[i].nrequests,
|
|
|
|
nmalloc + nrequests);
|
|
|
|
arena_stats_accum_u64(&astats->nrequests_large,
|
|
|
|
nmalloc + nrequests);
|
2017-02-14 01:44:46 +08:00
|
|
|
|
2017-03-04 12:44:39 +08:00
|
|
|
assert(nmalloc >= ndalloc);
|
|
|
|
assert(nmalloc - ndalloc <= SIZE_T_MAX);
|
|
|
|
size_t curlextents = (size_t)(nmalloc - ndalloc);
|
2017-02-14 01:44:46 +08:00
|
|
|
lstats[i].curlextents += curlextents;
|
2017-03-14 07:18:40 +08:00
|
|
|
arena_stats_accum_zu(&astats->allocated_large,
|
|
|
|
curlextents * index2size(NBINS + i));
|
2017-02-13 09:43:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
arena_stats_unlock(tsdn, &arena->stats);
|
|
|
|
|
|
|
|
if (config_tcache) {
|
|
|
|
tcache_bin_t *tbin;
|
|
|
|
tcache_t *tcache;
|
|
|
|
|
|
|
|
/* tcache_bytes counts currently cached bytes. */
|
2017-03-14 07:18:40 +08:00
|
|
|
atomic_store_zu(&astats->tcache_bytes, 0, ATOMIC_RELAXED);
|
2017-02-13 10:50:53 +08:00
|
|
|
malloc_mutex_lock(tsdn, &arena->tcache_ql_mtx);
|
2017-02-13 09:43:33 +08:00
|
|
|
ql_foreach(tcache, &arena->tcache_ql, link) {
|
2017-04-07 03:35:22 +08:00
|
|
|
szind_t i = 0;
|
|
|
|
for (; i < NBINS; i++) {
|
|
|
|
tbin = tcache_small_bin_get(tcache, i);
|
|
|
|
arena_stats_accum_zu(&astats->tcache_bytes,
|
|
|
|
tbin->ncached * index2size(i));
|
|
|
|
}
|
|
|
|
for (; i < nhbins; i++) {
|
|
|
|
tbin = tcache_large_bin_get(tcache, i);
|
2017-03-14 07:18:40 +08:00
|
|
|
arena_stats_accum_zu(&astats->tcache_bytes,
|
|
|
|
tbin->ncached * index2size(i));
|
2017-02-13 09:43:33 +08:00
|
|
|
}
|
|
|
|
}
|
2017-03-22 02:56:38 +08:00
|
|
|
malloc_mutex_prof_read(tsdn,
|
|
|
|
&astats->mutex_prof_data[arena_prof_mutex_tcache_list],
|
2017-03-11 04:14:05 +08:00
|
|
|
&arena->tcache_ql_mtx);
|
2017-02-13 10:50:53 +08:00
|
|
|
malloc_mutex_unlock(tsdn, &arena->tcache_ql_mtx);
|
2017-02-13 09:43:33 +08:00
|
|
|
}
|
|
|
|
|
2017-03-22 02:56:38 +08:00
|
|
|
#define READ_ARENA_MUTEX_PROF_DATA(mtx, ind) \
|
2017-03-12 12:28:31 +08:00
|
|
|
malloc_mutex_lock(tsdn, &arena->mtx); \
|
2017-03-22 02:56:38 +08:00
|
|
|
malloc_mutex_prof_read(tsdn, &astats->mutex_prof_data[ind], \
|
|
|
|
&arena->mtx); \
|
2017-03-12 12:28:31 +08:00
|
|
|
malloc_mutex_unlock(tsdn, &arena->mtx);
|
2017-03-11 04:14:05 +08:00
|
|
|
|
|
|
|
/* Gather per arena mutex profiling data. */
|
2017-03-22 02:56:38 +08:00
|
|
|
READ_ARENA_MUTEX_PROF_DATA(large_mtx, arena_prof_mutex_large);
|
2017-04-17 13:31:16 +08:00
|
|
|
READ_ARENA_MUTEX_PROF_DATA(extent_avail_mtx,
|
|
|
|
arena_prof_mutex_extent_avail)
|
2017-03-16 05:00:57 +08:00
|
|
|
READ_ARENA_MUTEX_PROF_DATA(extents_dirty.mtx,
|
2017-03-22 02:56:38 +08:00
|
|
|
arena_prof_mutex_extents_dirty)
|
2017-03-16 05:00:57 +08:00
|
|
|
READ_ARENA_MUTEX_PROF_DATA(extents_muzzy.mtx,
|
2017-03-22 02:56:38 +08:00
|
|
|
arena_prof_mutex_extents_muzzy)
|
2017-03-11 04:14:05 +08:00
|
|
|
READ_ARENA_MUTEX_PROF_DATA(extents_retained.mtx,
|
2017-03-22 02:56:38 +08:00
|
|
|
arena_prof_mutex_extents_retained)
|
|
|
|
READ_ARENA_MUTEX_PROF_DATA(decay_dirty.mtx,
|
|
|
|
arena_prof_mutex_decay_dirty)
|
|
|
|
READ_ARENA_MUTEX_PROF_DATA(decay_muzzy.mtx,
|
|
|
|
arena_prof_mutex_decay_muzzy)
|
2017-03-22 16:49:56 +08:00
|
|
|
READ_ARENA_MUTEX_PROF_DATA(base->mtx,
|
|
|
|
arena_prof_mutex_base)
|
2017-03-11 04:14:05 +08:00
|
|
|
#undef READ_ARENA_MUTEX_PROF_DATA
|
|
|
|
|
2017-02-14 01:44:46 +08:00
|
|
|
for (szind_t i = 0; i < NBINS; i++) {
|
2017-02-13 09:43:33 +08:00
|
|
|
arena_bin_t *bin = &arena->bins[i];
|
|
|
|
|
|
|
|
malloc_mutex_lock(tsdn, &bin->lock);
|
2017-03-14 08:29:03 +08:00
|
|
|
malloc_mutex_prof_read(tsdn, &bstats[i].mutex_data, &bin->lock);
|
2017-02-13 09:43:33 +08:00
|
|
|
bstats[i].nmalloc += bin->stats.nmalloc;
|
|
|
|
bstats[i].ndalloc += bin->stats.ndalloc;
|
|
|
|
bstats[i].nrequests += bin->stats.nrequests;
|
|
|
|
bstats[i].curregs += bin->stats.curregs;
|
|
|
|
if (config_tcache) {
|
|
|
|
bstats[i].nfills += bin->stats.nfills;
|
|
|
|
bstats[i].nflushes += bin->stats.nflushes;
|
|
|
|
}
|
|
|
|
bstats[i].nslabs += bin->stats.nslabs;
|
|
|
|
bstats[i].reslabs += bin->stats.reslabs;
|
|
|
|
bstats[i].curslabs += bin->stats.curslabs;
|
|
|
|
malloc_mutex_unlock(tsdn, &bin->lock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-19 12:02:46 +08:00
|
|
|
void
|
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
|
|
|
arena_extents_dirty_dalloc(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-30 13:57:14 +08:00
|
|
|
witness_assert_depth_to_rank(tsdn, WITNESS_RANK_CORE, 0);
|
2015-02-16 10:04:46 +08:00
|
|
|
|
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
|
|
|
extents_dalloc(tsdn, arena, r_extent_hooks, &arena->extents_dirty,
|
|
|
|
extent);
|
|
|
|
if (arena_dirty_decay_time_get(arena) == 0) {
|
|
|
|
arena_decay_dirty(tsdn, arena, true);
|
2017-03-02 07:25:48 +08:00
|
|
|
}
|
2015-02-16 10:04:46 +08:00
|
|
|
}
|
|
|
|
|
2014-10-31 07:38:08 +08:00
|
|
|
JEMALLOC_INLINE_C void *
|
2016-05-30 09:34:50 +08:00
|
|
|
arena_slab_reg_alloc(tsdn_t *tsdn, extent_t *slab,
|
2017-01-16 08:56:30 +08:00
|
|
|
const arena_bin_info_t *bin_info) {
|
2010-01-17 01:53:50 +08:00
|
|
|
void *ret;
|
2016-05-30 09:34:50 +08:00
|
|
|
arena_slab_data_t *slab_data = extent_slab_data_get(slab);
|
2016-02-26 12:51:00 +08:00
|
|
|
size_t regind;
|
2016-05-30 09:34:50 +08:00
|
|
|
|
2017-03-28 07:41:47 +08:00
|
|
|
assert(extent_nfree_get(slab) > 0);
|
2016-05-30 09:34:50 +08:00
|
|
|
assert(!bitmap_full(slab_data->bitmap, &bin_info->bitmap_info));
|
|
|
|
|
2016-11-16 15:56:29 +08:00
|
|
|
regind = bitmap_sfu(slab_data->bitmap, &bin_info->bitmap_info);
|
2016-05-30 09:34:50 +08:00
|
|
|
ret = (void *)((uintptr_t)extent_addr_get(slab) +
|
|
|
|
(uintptr_t)(bin_info->reg_size * regind));
|
2017-03-28 07:41:47 +08:00
|
|
|
extent_nfree_dec(slab);
|
2017-01-20 10:15:45 +08:00
|
|
|
return ret;
|
2010-02-11 02:37:56 +08:00
|
|
|
}
|
|
|
|
|
2016-12-22 04:33:17 +08:00
|
|
|
#ifndef JEMALLOC_JET
|
|
|
|
JEMALLOC_INLINE_C
|
|
|
|
#endif
|
|
|
|
size_t
|
2017-01-16 08:56:30 +08:00
|
|
|
arena_slab_regind(extent_t *slab, szind_t binind, const void *ptr) {
|
2016-12-22 04:33:17 +08:00
|
|
|
size_t diff, regind;
|
2016-05-26 07:21:37 +08:00
|
|
|
|
2016-05-30 09:34:50 +08:00
|
|
|
/* Freeing a pointer outside the slab can cause assertion failure. */
|
|
|
|
assert((uintptr_t)ptr >= (uintptr_t)extent_addr_get(slab));
|
|
|
|
assert((uintptr_t)ptr < (uintptr_t)extent_past_get(slab));
|
|
|
|
/* Freeing an interior pointer can cause assertion failure. */
|
|
|
|
assert(((uintptr_t)ptr - (uintptr_t)extent_addr_get(slab)) %
|
2016-12-22 04:33:17 +08:00
|
|
|
(uintptr_t)arena_bin_info[binind].reg_size == 0);
|
2016-05-26 07:21:37 +08:00
|
|
|
|
2016-12-22 04:33:17 +08:00
|
|
|
/* Avoid doing division with a variable divisor. */
|
2016-05-30 09:34:50 +08:00
|
|
|
diff = (size_t)((uintptr_t)ptr - (uintptr_t)extent_addr_get(slab));
|
2016-12-22 04:33:17 +08:00
|
|
|
switch (binind) {
|
2017-01-20 13:41:41 +08:00
|
|
|
#define REGIND_bin_yes(index, reg_size) \
|
2016-12-22 04:33:17 +08:00
|
|
|
case index: \
|
|
|
|
regind = diff / (reg_size); \
|
|
|
|
assert(diff == regind * (reg_size)); \
|
|
|
|
break;
|
2017-01-20 13:41:41 +08:00
|
|
|
#define REGIND_bin_no(index, reg_size)
|
|
|
|
#define SC(index, lg_grp, lg_delta, ndelta, psz, bin, pgs, \
|
2016-12-22 04:33:17 +08:00
|
|
|
lg_delta_lookup) \
|
|
|
|
REGIND_bin_##bin(index, (1U<<lg_grp) + (ndelta<<lg_delta))
|
|
|
|
SIZE_CLASSES
|
|
|
|
#undef REGIND_bin_yes
|
|
|
|
#undef REGIND_bin_no
|
|
|
|
#undef SC
|
|
|
|
default: not_reached();
|
2016-05-26 07:21:37 +08:00
|
|
|
}
|
2016-12-22 04:33:17 +08:00
|
|
|
|
|
|
|
assert(regind < arena_bin_info[binind].nregs);
|
2016-05-26 07:21:37 +08:00
|
|
|
|
2017-01-20 10:15:45 +08:00
|
|
|
return regind;
|
2016-05-26 07:21:37 +08:00
|
|
|
}
|
|
|
|
|
2014-10-31 07:38:08 +08:00
|
|
|
JEMALLOC_INLINE_C void
|
2016-05-30 09:34:50 +08:00
|
|
|
arena_slab_reg_dalloc(tsdn_t *tsdn, extent_t *slab,
|
2017-01-16 08:56:30 +08:00
|
|
|
arena_slab_data_t *slab_data, void *ptr) {
|
2017-03-14 08:48:26 +08:00
|
|
|
szind_t binind = extent_szind_get(slab);
|
2016-04-07 20:04:12 +08:00
|
|
|
const arena_bin_info_t *bin_info = &arena_bin_info[binind];
|
2016-12-22 04:33:17 +08:00
|
|
|
size_t regind = arena_slab_regind(slab, binind, ptr);
|
Use bitmaps to track small regions.
The previous free list implementation, which embedded singly linked
lists in available regions, had the unfortunate side effect of causing
many cache misses during thread cache fills. Fix this in two places:
- arena_run_t: Use a new bitmap implementation to track which regions
are available. Furthermore, revert to preferring the
lowest available region (as jemalloc did with its old
bitmap-based approach).
- tcache_t: Move read-only tcache_bin_t metadata into
tcache_bin_info_t, and add a contiguous array of pointers
to tcache_t in order to track cached objects. This
substantially increases the size of tcache_t, but results
in much higher data locality for common tcache operations.
As a side benefit, it is again possible to efficiently
flush the least recently used cached objects, so this
change changes flushing from MRU to LRU.
The new bitmap implementation uses a multi-level summary approach to
make finding the lowest available region very fast. In practice,
bitmaps only have one or two levels, though the implementation is
general enough to handle extremely large bitmaps, mainly so that large
page sizes can still be entertained.
Fix tcache_bin_flush_large() to always flush statistics, in the same way
that tcache_bin_flush_small() was recently fixed.
Use JEMALLOC_DEBUG rather than NDEBUG.
Add dassert(), and use it for debug-only asserts.
2011-03-17 01:30:13 +08:00
|
|
|
|
2017-03-28 07:41:47 +08:00
|
|
|
assert(extent_nfree_get(slab) < bin_info->nregs);
|
Use bitmaps to track small regions.
The previous free list implementation, which embedded singly linked
lists in available regions, had the unfortunate side effect of causing
many cache misses during thread cache fills. Fix this in two places:
- arena_run_t: Use a new bitmap implementation to track which regions
are available. Furthermore, revert to preferring the
lowest available region (as jemalloc did with its old
bitmap-based approach).
- tcache_t: Move read-only tcache_bin_t metadata into
tcache_bin_info_t, and add a contiguous array of pointers
to tcache_t in order to track cached objects. This
substantially increases the size of tcache_t, but results
in much higher data locality for common tcache operations.
As a side benefit, it is again possible to efficiently
flush the least recently used cached objects, so this
change changes flushing from MRU to LRU.
The new bitmap implementation uses a multi-level summary approach to
make finding the lowest available region very fast. In practice,
bitmaps only have one or two levels, though the implementation is
general enough to handle extremely large bitmaps, mainly so that large
page sizes can still be entertained.
Fix tcache_bin_flush_large() to always flush statistics, in the same way
that tcache_bin_flush_small() was recently fixed.
Use JEMALLOC_DEBUG rather than NDEBUG.
Add dassert(), and use it for debug-only asserts.
2011-03-17 01:30:13 +08:00
|
|
|
/* Freeing an unallocated pointer can cause assertion failure. */
|
2016-05-30 09:34:50 +08:00
|
|
|
assert(bitmap_get(slab_data->bitmap, &bin_info->bitmap_info, regind));
|
2013-01-22 12:04:42 +08:00
|
|
|
|
2016-05-30 09:34:50 +08:00
|
|
|
bitmap_unset(slab_data->bitmap, &bin_info->bitmap_info, regind);
|
2017-03-28 07:41:47 +08:00
|
|
|
extent_nfree_inc(slab);
|
2010-10-19 08:45:40 +08:00
|
|
|
}
|
|
|
|
|
2010-01-17 01:53:50 +08:00
|
|
|
static void
|
2017-01-16 08:56:30 +08:00
|
|
|
arena_nactive_add(arena_t *arena, size_t add_pages) {
|
2017-04-05 08:22:24 +08:00
|
|
|
atomic_fetch_add_zu(&arena->nactive, add_pages, ATOMIC_RELAXED);
|
2016-02-27 09:29:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-01-16 08:56:30 +08:00
|
|
|
arena_nactive_sub(arena_t *arena, size_t sub_pages) {
|
2017-04-05 08:22:24 +08:00
|
|
|
assert(atomic_load_zu(&arena->nactive, ATOMIC_RELAXED) >= sub_pages);
|
|
|
|
atomic_fetch_sub_zu(&arena->nactive, sub_pages, ATOMIC_RELAXED);
|
2014-01-15 08:23:03 +08:00
|
|
|
}
|
|
|
|
|
2014-10-15 13:20:00 +08:00
|
|
|
static void
|
2017-02-13 09:43:33 +08:00
|
|
|
arena_large_malloc_stats_update(tsdn_t *tsdn, arena_t *arena, size_t usize) {
|
2017-01-07 10:56:02 +08:00
|
|
|
szind_t index, hindex;
|
2014-10-15 13:20:00 +08:00
|
|
|
|
|
|
|
cassert(config_stats);
|
|
|
|
|
2017-01-16 08:56:30 +08:00
|
|
|
if (usize < LARGE_MINCLASS) {
|
2017-01-07 10:56:02 +08:00
|
|
|
usize = LARGE_MINCLASS;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2017-01-07 10:56:02 +08:00
|
|
|
index = size2index(usize);
|
|
|
|
hindex = (index >= NBINS) ? index - NBINS : 0;
|
|
|
|
|
2017-02-13 09:43:33 +08:00
|
|
|
arena_stats_add_u64(tsdn, &arena->stats,
|
|
|
|
&arena->stats.lstats[hindex].nmalloc, 1);
|
2014-10-15 13:20:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-02-13 09:43:33 +08:00
|
|
|
arena_large_dalloc_stats_update(tsdn_t *tsdn, arena_t *arena, size_t usize) {
|
2017-01-07 10:56:02 +08:00
|
|
|
szind_t index, hindex;
|
2014-10-15 13:20:00 +08:00
|
|
|
|
|
|
|
cassert(config_stats);
|
|
|
|
|
2017-01-16 08:56:30 +08:00
|
|
|
if (usize < LARGE_MINCLASS) {
|
2017-01-07 10:56:02 +08:00
|
|
|
usize = LARGE_MINCLASS;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2017-01-07 10:56:02 +08:00
|
|
|
index = size2index(usize);
|
|
|
|
hindex = (index >= NBINS) ? index - NBINS : 0;
|
|
|
|
|
2017-02-13 09:43:33 +08:00
|
|
|
arena_stats_add_u64(tsdn, &arena->stats,
|
|
|
|
&arena->stats.lstats[hindex].ndalloc, 1);
|
2016-04-26 04:26:54 +08:00
|
|
|
}
|
|
|
|
|
2014-10-15 13:20:00 +08:00
|
|
|
static void
|
2017-02-13 09:43:33 +08:00
|
|
|
arena_large_ralloc_stats_update(tsdn_t *tsdn, arena_t *arena, size_t oldusize,
|
|
|
|
size_t usize) {
|
|
|
|
arena_large_dalloc_stats_update(tsdn, arena, oldusize);
|
|
|
|
arena_large_malloc_stats_update(tsdn, arena, usize);
|
2015-02-19 08:40:53 +08:00
|
|
|
}
|
|
|
|
|
2016-05-19 12:02:46 +08:00
|
|
|
extent_t *
|
2016-06-02 03:59:02 +08:00
|
|
|
arena_extent_alloc_large(tsdn_t *tsdn, arena_t *arena, size_t usize,
|
2017-01-16 08:56:30 +08:00
|
|
|
size_t alignment, bool *zero) {
|
2016-06-04 03:05:53 +08:00
|
|
|
extent_hooks_t *extent_hooks = EXTENT_HOOKS_INITIALIZER;
|
2014-05-16 13:22:27 +08:00
|
|
|
|
2017-01-30 13:57:14 +08:00
|
|
|
witness_assert_depth_to_rank(tsdn, WITNESS_RANK_CORE, 0);
|
|
|
|
|
2017-03-14 08:36:57 +08:00
|
|
|
szind_t szind = size2index(usize);
|
2017-02-14 02:35:41 +08:00
|
|
|
size_t mapped_add;
|
2017-01-30 13:57:14 +08:00
|
|
|
bool commit = true;
|
2017-03-14 08:36:57 +08:00
|
|
|
extent_t *extent = extents_alloc(tsdn, arena, &extent_hooks,
|
|
|
|
&arena->extents_dirty, NULL, usize, large_pad, alignment, false,
|
|
|
|
szind, zero, &commit);
|
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
|
|
|
if (extent == NULL) {
|
|
|
|
extent = extents_alloc(tsdn, arena, &extent_hooks,
|
|
|
|
&arena->extents_muzzy, NULL, usize, large_pad, alignment,
|
2017-03-14 08:36:57 +08:00
|
|
|
false, szind, zero, &commit);
|
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-02-14 02:35:41 +08:00
|
|
|
size_t size = usize + large_pad;
|
2016-05-19 12:02:46 +08:00
|
|
|
if (extent == NULL) {
|
2017-02-13 09:43:33 +08:00
|
|
|
extent = extent_alloc_wrapper(tsdn, arena, &extent_hooks, NULL,
|
2017-03-14 08:36:57 +08:00
|
|
|
usize, large_pad, alignment, false, szind, zero, &commit);
|
2017-02-14 02:35:41 +08:00
|
|
|
if (config_stats) {
|
|
|
|
/*
|
|
|
|
* extent may be NULL on OOM, but in that case
|
|
|
|
* mapped_add isn't used below, so there's no need to
|
|
|
|
* conditionlly set it to 0 here.
|
|
|
|
*/
|
|
|
|
mapped_add = size;
|
|
|
|
}
|
|
|
|
} else if (config_stats) {
|
|
|
|
mapped_add = 0;
|
2017-02-13 09:43:33 +08:00
|
|
|
}
|
|
|
|
|
2017-02-14 02:35:41 +08:00
|
|
|
if (extent != NULL) {
|
|
|
|
if (config_stats) {
|
|
|
|
arena_stats_lock(tsdn, &arena->stats);
|
|
|
|
arena_large_malloc_stats_update(tsdn, arena, usize);
|
|
|
|
if (mapped_add != 0) {
|
|
|
|
arena_stats_add_zu(tsdn, &arena->stats,
|
|
|
|
&arena->stats.mapped, mapped_add);
|
|
|
|
}
|
|
|
|
arena_stats_unlock(tsdn, &arena->stats);
|
|
|
|
}
|
|
|
|
arena_nactive_add(arena, size >> LG_PAGE);
|
2014-10-15 13:20:00 +08:00
|
|
|
}
|
|
|
|
|
2017-01-20 10:15:45 +08:00
|
|
|
return extent;
|
2014-05-16 13:22:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-02-13 09:43:33 +08:00
|
|
|
arena_extent_dalloc_large_prep(tsdn_t *tsdn, arena_t *arena, extent_t *extent) {
|
2014-05-16 13:22:27 +08:00
|
|
|
if (config_stats) {
|
2017-02-13 09:43:33 +08:00
|
|
|
arena_stats_lock(tsdn, &arena->stats);
|
|
|
|
arena_large_dalloc_stats_update(tsdn, arena,
|
2016-06-01 05:50:21 +08:00
|
|
|
extent_usize_get(extent));
|
2017-02-13 09:43:33 +08:00
|
|
|
arena_stats_unlock(tsdn, &arena->stats);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2017-01-30 13:57:14 +08:00
|
|
|
arena_nactive_sub(arena, extent_size_get(extent) >> LG_PAGE);
|
|
|
|
}
|
|
|
|
|
2014-10-15 13:20:00 +08:00
|
|
|
void
|
2016-06-02 03:59:02 +08:00
|
|
|
arena_extent_ralloc_large_shrink(tsdn_t *tsdn, arena_t *arena, extent_t *extent,
|
2017-01-16 08:56:30 +08:00
|
|
|
size_t oldusize) {
|
2016-05-28 15:17:28 +08:00
|
|
|
size_t usize = extent_usize_get(extent);
|
|
|
|
size_t udiff = oldusize - usize;
|
2010-03-15 10:43:56 +08:00
|
|
|
|
2014-10-15 13:20:00 +08:00
|
|
|
if (config_stats) {
|
2017-02-13 09:43:33 +08:00
|
|
|
arena_stats_lock(tsdn, &arena->stats);
|
|
|
|
arena_large_ralloc_stats_update(tsdn, arena, oldusize, usize);
|
|
|
|
arena_stats_unlock(tsdn, &arena->stats);
|
2014-10-15 13:20:00 +08:00
|
|
|
}
|
2016-02-28 04:34:50 +08:00
|
|
|
arena_nactive_sub(arena, udiff >> LG_PAGE);
|
2015-02-19 08:40:53 +08:00
|
|
|
}
|
|
|
|
|
2016-05-19 12:02:46 +08:00
|
|
|
void
|
2016-06-02 03:59:02 +08:00
|
|
|
arena_extent_ralloc_large_expand(tsdn_t *tsdn, arena_t *arena, extent_t *extent,
|
2017-01-16 08:56:30 +08:00
|
|
|
size_t oldusize) {
|
2016-05-28 15:17:28 +08:00
|
|
|
size_t usize = extent_usize_get(extent);
|
|
|
|
size_t udiff = usize - oldusize;
|
2014-10-15 13:20:00 +08:00
|
|
|
|
|
|
|
if (config_stats) {
|
2017-02-13 09:43:33 +08:00
|
|
|
arena_stats_lock(tsdn, &arena->stats);
|
|
|
|
arena_large_ralloc_stats_update(tsdn, arena, oldusize, usize);
|
|
|
|
arena_stats_unlock(tsdn, &arena->stats);
|
2014-10-15 13:20:00 +08:00
|
|
|
}
|
2016-02-28 04:34:50 +08:00
|
|
|
arena_nactive_add(arena, udiff >> LG_PAGE);
|
2010-01-17 01:53:50 +08:00
|
|
|
}
|
|
|
|
|
2017-03-02 03:21:18 +08:00
|
|
|
static ssize_t
|
2017-03-08 01:22:33 +08:00
|
|
|
arena_decay_time_read(arena_decay_t *decay) {
|
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
|
|
|
return atomic_load_zd(&decay->time, ATOMIC_RELAXED);
|
2017-03-02 03:21:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-03-08 01:22:33 +08:00
|
|
|
arena_decay_time_write(arena_decay_t *decay, ssize_t decay_time) {
|
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
|
|
|
atomic_store_zd(&decay->time, decay_time, ATOMIC_RELAXED);
|
2017-03-02 03:21:18 +08:00
|
|
|
}
|
|
|
|
|
2016-02-20 12:09:31 +08:00
|
|
|
static void
|
2017-03-08 01:22:33 +08:00
|
|
|
arena_decay_deadline_init(arena_decay_t *decay) {
|
2016-02-20 12:09:31 +08:00
|
|
|
/*
|
|
|
|
* Generate a new deadline that is uniformly random within the next
|
|
|
|
* epoch after the current one.
|
|
|
|
*/
|
2017-03-08 01:22:33 +08:00
|
|
|
nstime_copy(&decay->deadline, &decay->epoch);
|
|
|
|
nstime_add(&decay->deadline, &decay->interval);
|
|
|
|
if (arena_decay_time_read(decay) > 0) {
|
2016-02-22 03:25:02 +08:00
|
|
|
nstime_t jitter;
|
|
|
|
|
2017-03-08 01:22:33 +08:00
|
|
|
nstime_init(&jitter, prng_range_u64(&decay->jitter_state,
|
|
|
|
nstime_ns(&decay->interval)));
|
|
|
|
nstime_add(&decay->deadline, &jitter);
|
2016-02-20 12:09:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
2017-03-08 01:22:33 +08:00
|
|
|
arena_decay_deadline_reached(const arena_decay_t *decay, const nstime_t *time) {
|
|
|
|
return (nstime_compare(&decay->deadline, time) <= 0);
|
2016-02-20 12:09:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static size_t
|
2017-03-08 01:22:33 +08:00
|
|
|
arena_decay_backlog_npages_limit(const arena_decay_t *decay) {
|
2016-02-20 12:09:31 +08:00
|
|
|
static const uint64_t h_steps[] = {
|
2017-01-20 13:41:41 +08:00
|
|
|
#define STEP(step, h, x, y) \
|
2016-02-20 12:09:31 +08:00
|
|
|
h,
|
|
|
|
SMOOTHSTEP
|
|
|
|
#undef STEP
|
|
|
|
};
|
|
|
|
uint64_t sum;
|
|
|
|
size_t npages_limit_backlog;
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For each element of decay_backlog, multiply by the corresponding
|
|
|
|
* fixed-point smoothstep decay factor. Sum the products, then divide
|
|
|
|
* to round down to the nearest whole number of pages.
|
|
|
|
*/
|
|
|
|
sum = 0;
|
2017-01-16 08:56:30 +08:00
|
|
|
for (i = 0; i < SMOOTHSTEP_NSTEPS; i++) {
|
2017-03-08 01:22:33 +08:00
|
|
|
sum += decay->backlog[i] * h_steps[i];
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2016-04-12 15:50:54 +08:00
|
|
|
npages_limit_backlog = (size_t)(sum >> SMOOTHSTEP_BFP);
|
2016-02-20 12:09:31 +08:00
|
|
|
|
2017-01-20 10:15:45 +08:00
|
|
|
return npages_limit_backlog;
|
2016-02-20 12:09:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-03-08 01:22:33 +08:00
|
|
|
arena_decay_backlog_update_last(arena_decay_t *decay, extents_t *extents) {
|
|
|
|
size_t ndirty = extents_npages_get(extents);
|
|
|
|
size_t ndirty_delta = (ndirty > decay->nunpurged) ? ndirty -
|
|
|
|
decay->nunpurged : 0;
|
|
|
|
decay->backlog[SMOOTHSTEP_NSTEPS-1] = ndirty_delta;
|
2016-10-12 06:30:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-03-08 01:22:33 +08:00
|
|
|
arena_decay_backlog_update(arena_decay_t *decay, extents_t *extents,
|
|
|
|
uint64_t nadvance_u64) {
|
2016-10-12 06:30:01 +08:00
|
|
|
if (nadvance_u64 >= SMOOTHSTEP_NSTEPS) {
|
2017-03-08 01:22:33 +08:00
|
|
|
memset(decay->backlog, 0, (SMOOTHSTEP_NSTEPS-1) *
|
2016-10-12 06:30:01 +08:00
|
|
|
sizeof(size_t));
|
|
|
|
} else {
|
|
|
|
size_t nadvance_z = (size_t)nadvance_u64;
|
|
|
|
|
|
|
|
assert((uint64_t)nadvance_z == nadvance_u64);
|
|
|
|
|
2017-03-08 01:22:33 +08:00
|
|
|
memmove(decay->backlog, &decay->backlog[nadvance_z],
|
2016-10-12 06:30:01 +08:00
|
|
|
(SMOOTHSTEP_NSTEPS - nadvance_z) * sizeof(size_t));
|
|
|
|
if (nadvance_z > 1) {
|
2017-03-08 01:22:33 +08:00
|
|
|
memset(&decay->backlog[SMOOTHSTEP_NSTEPS -
|
2016-10-12 06:30:01 +08:00
|
|
|
nadvance_z], 0, (nadvance_z-1) * sizeof(size_t));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-08 01:22:33 +08:00
|
|
|
arena_decay_backlog_update_last(decay, extents);
|
2016-10-12 06:30:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-03-08 01:22:33 +08:00
|
|
|
arena_decay_epoch_advance_helper(arena_decay_t *decay, extents_t *extents,
|
|
|
|
const nstime_t *time) {
|
2016-04-12 15:50:54 +08:00
|
|
|
uint64_t nadvance_u64;
|
2016-02-22 03:25:02 +08:00
|
|
|
nstime_t delta;
|
2016-02-20 12:09:31 +08:00
|
|
|
|
2017-03-08 01:22:33 +08:00
|
|
|
assert(arena_decay_deadline_reached(decay, time));
|
2016-02-20 12:09:31 +08:00
|
|
|
|
2016-02-22 03:25:02 +08:00
|
|
|
nstime_copy(&delta, time);
|
2017-03-08 01:22:33 +08:00
|
|
|
nstime_subtract(&delta, &decay->epoch);
|
|
|
|
nadvance_u64 = nstime_divide(&delta, &decay->interval);
|
2016-04-12 15:50:54 +08:00
|
|
|
assert(nadvance_u64 > 0);
|
2016-02-20 12:09:31 +08:00
|
|
|
|
2016-04-12 15:50:54 +08:00
|
|
|
/* Add nadvance_u64 decay intervals to epoch. */
|
2017-03-08 01:22:33 +08:00
|
|
|
nstime_copy(&delta, &decay->interval);
|
2016-04-12 15:50:54 +08:00
|
|
|
nstime_imultiply(&delta, nadvance_u64);
|
2017-03-08 01:22:33 +08:00
|
|
|
nstime_add(&decay->epoch, &delta);
|
2016-02-20 12:09:31 +08:00
|
|
|
|
|
|
|
/* Set a new deadline. */
|
2017-03-08 01:22:33 +08:00
|
|
|
arena_decay_deadline_init(decay);
|
2016-02-20 12:09:31 +08:00
|
|
|
|
|
|
|
/* Update the backlog. */
|
2017-03-08 01:22:33 +08:00
|
|
|
arena_decay_backlog_update(decay, extents, nadvance_u64);
|
2016-10-12 06:30:01 +08:00
|
|
|
}
|
2016-04-12 15:50:54 +08:00
|
|
|
|
2016-10-12 06:30:01 +08:00
|
|
|
static void
|
2017-03-08 01:22:33 +08:00
|
|
|
arena_decay_epoch_advance_purge(tsdn_t *tsdn, arena_t *arena,
|
|
|
|
arena_decay_t *decay, extents_t *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
|
|
|
size_t npages_limit = arena_decay_backlog_npages_limit(decay);
|
2016-04-12 15:50:54 +08:00
|
|
|
|
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
|
|
|
if (extents_npages_get(extents) > npages_limit) {
|
|
|
|
arena_decay_to_limit(tsdn, arena, decay, extents, false,
|
|
|
|
npages_limit);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2017-01-30 13:57:14 +08:00
|
|
|
/*
|
|
|
|
* There may be concurrent ndirty fluctuation between the purge above
|
|
|
|
* and the nunpurged update below, but this is inconsequential to decay
|
|
|
|
* machinery correctness.
|
|
|
|
*/
|
2017-03-08 01:22:33 +08:00
|
|
|
decay->nunpurged = extents_npages_get(extents);
|
2016-02-20 12:09:31 +08:00
|
|
|
}
|
|
|
|
|
2016-10-12 06:30:01 +08:00
|
|
|
static void
|
2017-03-08 01:22:33 +08:00
|
|
|
arena_decay_epoch_advance(tsdn_t *tsdn, arena_t *arena, arena_decay_t *decay,
|
|
|
|
extents_t *extents, const nstime_t *time) {
|
|
|
|
arena_decay_epoch_advance_helper(decay, extents, time);
|
|
|
|
arena_decay_epoch_advance_purge(tsdn, arena, decay, extents);
|
2016-02-20 12:09:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-03-08 01:22:33 +08:00
|
|
|
arena_decay_reinit(arena_decay_t *decay, extents_t *extents,
|
|
|
|
ssize_t decay_time) {
|
|
|
|
arena_decay_time_write(decay, decay_time);
|
2016-02-20 12:09:31 +08:00
|
|
|
if (decay_time > 0) {
|
2017-03-08 01:22:33 +08:00
|
|
|
nstime_init2(&decay->interval, decay_time, 0);
|
|
|
|
nstime_idivide(&decay->interval, SMOOTHSTEP_NSTEPS);
|
2016-02-20 12:09:31 +08:00
|
|
|
}
|
|
|
|
|
2017-03-08 01:22:33 +08:00
|
|
|
nstime_init(&decay->epoch, 0);
|
|
|
|
nstime_update(&decay->epoch);
|
|
|
|
decay->jitter_state = (uint64_t)(uintptr_t)decay;
|
|
|
|
arena_decay_deadline_init(decay);
|
|
|
|
decay->nunpurged = extents_npages_get(extents);
|
|
|
|
memset(decay->backlog, 0, SMOOTHSTEP_NSTEPS * sizeof(size_t));
|
2016-02-20 12:09:31 +08:00
|
|
|
}
|
|
|
|
|
2017-02-14 03:02:32 +08:00
|
|
|
static bool
|
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
|
|
|
arena_decay_init(arena_decay_t *decay, extents_t *extents, ssize_t decay_time,
|
|
|
|
decay_stats_t *stats) {
|
|
|
|
if (config_debug) {
|
|
|
|
for (size_t i = 0; i < sizeof(arena_decay_t); i++) {
|
|
|
|
assert(((char *)decay)[i] == 0);
|
|
|
|
}
|
|
|
|
}
|
2017-03-08 01:22:33 +08:00
|
|
|
if (malloc_mutex_init(&decay->mtx, "decay", WITNESS_RANK_DECAY)) {
|
2017-02-14 03:02:32 +08:00
|
|
|
return true;
|
|
|
|
}
|
2017-03-08 11:52:57 +08:00
|
|
|
decay->purging = false;
|
2017-03-08 01:22:33 +08:00
|
|
|
arena_decay_reinit(decay, extents, decay_time);
|
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
|
|
|
/* Memory is zeroed, so there is no need to clear stats. */
|
|
|
|
if (config_stats) {
|
|
|
|
decay->stats = stats;
|
|
|
|
}
|
2017-02-14 03:02:32 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-02-20 12:09:31 +08:00
|
|
|
static bool
|
2017-01-16 08:56:30 +08:00
|
|
|
arena_decay_time_valid(ssize_t decay_time) {
|
|
|
|
if (decay_time < -1) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return false;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
|
|
|
if (decay_time == -1 || (uint64_t)decay_time <= NSTIME_SEC_MAX) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return true;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2017-01-20 10:15:45 +08:00
|
|
|
return false;
|
2016-02-20 12:09:31 +08:00
|
|
|
}
|
|
|
|
|
2017-03-02 07:25:48 +08:00
|
|
|
static void
|
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
|
|
|
arena_maybe_decay(tsdn_t *tsdn, arena_t *arena, arena_decay_t *decay,
|
2017-03-08 01:22:33 +08:00
|
|
|
extents_t *extents) {
|
|
|
|
malloc_mutex_assert_owner(tsdn, &decay->mtx);
|
2016-02-20 12:09:31 +08:00
|
|
|
|
|
|
|
/* Purge all or nothing if the option is disabled. */
|
2017-03-08 01:22:33 +08:00
|
|
|
ssize_t decay_time = arena_decay_time_read(decay);
|
2017-03-02 03:21:18 +08:00
|
|
|
if (decay_time <= 0) {
|
|
|
|
if (decay_time == 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
|
|
|
arena_decay_to_limit(tsdn, arena, decay, extents, false,
|
|
|
|
0);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2016-02-20 12:09:31 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-30 13:57:14 +08:00
|
|
|
nstime_t time;
|
2016-10-11 13:15:10 +08:00
|
|
|
nstime_init(&time, 0);
|
|
|
|
nstime_update(&time);
|
2017-03-08 01:22:33 +08:00
|
|
|
if (unlikely(!nstime_monotonic() && nstime_compare(&decay->epoch, &time)
|
|
|
|
> 0)) {
|
2016-10-11 13:15:10 +08:00
|
|
|
/*
|
2016-10-12 06:30:01 +08:00
|
|
|
* Time went backwards. Move the epoch back in time and
|
|
|
|
* generate a new deadline, with the expectation that time
|
|
|
|
* typically flows forward for long enough periods of time that
|
|
|
|
* epochs complete. Unfortunately, this strategy is susceptible
|
|
|
|
* to clock jitter triggering premature epoch advances, but
|
|
|
|
* clock jitter estimation and compensation isn't feasible here
|
|
|
|
* because calls into this code are event-driven.
|
2016-10-11 13:15:10 +08:00
|
|
|
*/
|
2017-03-08 01:22:33 +08:00
|
|
|
nstime_copy(&decay->epoch, &time);
|
|
|
|
arena_decay_deadline_init(decay);
|
2016-10-11 13:15:10 +08:00
|
|
|
} else {
|
|
|
|
/* Verify that time does not go backwards. */
|
2017-03-08 01:22:33 +08:00
|
|
|
assert(nstime_compare(&decay->epoch, &time) <= 0);
|
2016-02-20 12:09:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2016-10-12 06:30:01 +08:00
|
|
|
* If the deadline has been reached, advance to the current epoch and
|
|
|
|
* purge to the new limit if necessary. Note that dirty pages created
|
|
|
|
* during the current epoch are not subject to purge until a future
|
|
|
|
* epoch, so as a result purging only happens during epoch advances.
|
2016-02-20 12:09:31 +08:00
|
|
|
*/
|
2017-03-08 01:22:33 +08:00
|
|
|
if (arena_decay_deadline_reached(decay, &time)) {
|
|
|
|
arena_decay_epoch_advance(tsdn, arena, decay, extents, &time);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2016-02-20 12:09:31 +08:00
|
|
|
}
|
|
|
|
|
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 ssize_t
|
|
|
|
arena_decay_time_get(arena_decay_t *decay) {
|
|
|
|
return arena_decay_time_read(decay);
|
|
|
|
}
|
|
|
|
|
2017-03-02 07:25:48 +08:00
|
|
|
ssize_t
|
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
|
|
|
arena_dirty_decay_time_get(arena_t *arena) {
|
|
|
|
return arena_decay_time_get(&arena->decay_dirty);
|
2017-03-02 07:25:48 +08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
ssize_t
|
|
|
|
arena_muzzy_decay_time_get(arena_t *arena) {
|
|
|
|
return arena_decay_time_get(&arena->decay_muzzy);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
arena_decay_time_set(tsdn_t *tsdn, arena_t *arena, arena_decay_t *decay,
|
|
|
|
extents_t *extents, ssize_t decay_time) {
|
2017-03-02 07:25:48 +08:00
|
|
|
if (!arena_decay_time_valid(decay_time)) {
|
|
|
|
return 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
|
|
|
malloc_mutex_lock(tsdn, &decay->mtx);
|
2017-03-02 07:25:48 +08:00
|
|
|
/*
|
|
|
|
* Restart decay backlog from scratch, which may cause many dirty pages
|
|
|
|
* to be immediately purged. It would conceptually be possible to map
|
|
|
|
* the old backlog onto the new backlog, but there is no justification
|
|
|
|
* for such complexity since decay_time changes are intended to be
|
|
|
|
* infrequent, either between the {-1, 0, >0} states, or a one-time
|
|
|
|
* arbitrary change during initial arena configuration.
|
|
|
|
*/
|
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
|
|
|
arena_decay_reinit(decay, extents, decay_time);
|
|
|
|
arena_maybe_decay(tsdn, arena, decay, extents);
|
|
|
|
malloc_mutex_unlock(tsdn, &decay->mtx);
|
2017-03-02 07:25:48 +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
|
|
|
bool
|
|
|
|
arena_dirty_decay_time_set(tsdn_t *tsdn, arena_t *arena, ssize_t decay_time) {
|
|
|
|
return arena_decay_time_set(tsdn, arena, &arena->decay_dirty,
|
|
|
|
&arena->extents_dirty, decay_time);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
arena_muzzy_decay_time_set(tsdn_t *tsdn, arena_t *arena, ssize_t decay_time) {
|
|
|
|
return arena_decay_time_set(tsdn, arena, &arena->decay_muzzy,
|
|
|
|
&arena->extents_muzzy, decay_time);
|
|
|
|
}
|
|
|
|
|
2014-01-15 08:23:03 +08:00
|
|
|
static size_t
|
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
|
|
|
arena_stash_decayed(tsdn_t *tsdn, arena_t *arena,
|
|
|
|
extent_hooks_t **r_extent_hooks, extents_t *extents, size_t npages_limit,
|
|
|
|
extent_list_t *decay_extents) {
|
2017-01-30 13:57:14 +08:00
|
|
|
witness_assert_depth_to_rank(tsdn, WITNESS_RANK_CORE, 0);
|
2016-09-23 02:57:28 +08:00
|
|
|
|
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
|
|
|
/* Stash extents according to npages_limit. */
|
2017-01-30 13:57:14 +08:00
|
|
|
size_t nstashed = 0;
|
2017-03-03 10:04:35 +08:00
|
|
|
extent_t *extent;
|
2017-03-08 01:22:33 +08:00
|
|
|
while ((extent = extents_evict(tsdn, arena, r_extent_hooks, 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
|
|
|
npages_limit)) != NULL) {
|
|
|
|
extent_list_append(decay_extents, extent);
|
2017-01-30 13:57:14 +08:00
|
|
|
nstashed += extent_size_get(extent) >> LG_PAGE;
|
2010-03-15 08:36:10 +08:00
|
|
|
}
|
2017-01-20 10:15:45 +08:00
|
|
|
return nstashed;
|
2014-01-15 08:23:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static size_t
|
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
|
|
|
arena_decay_stashed(tsdn_t *tsdn, arena_t *arena,
|
|
|
|
extent_hooks_t **r_extent_hooks, arena_decay_t *decay, extents_t *extents,
|
|
|
|
bool all, extent_list_t *decay_extents) {
|
|
|
|
UNUSED size_t nmadvise, nunmapped;
|
2016-05-30 09:34:50 +08:00
|
|
|
size_t npurged;
|
2010-03-15 08:36:10 +08:00
|
|
|
|
2017-01-16 08:56:30 +08:00
|
|
|
if (config_stats) {
|
2012-02-11 12:22:09 +08:00
|
|
|
nmadvise = 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
|
|
|
nunmapped = 0;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2012-10-31 06:42:37 +08:00
|
|
|
npurged = 0;
|
2014-07-22 09:09:04 +08:00
|
|
|
|
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
|
|
|
ssize_t muzzy_decay_time = arena_muzzy_decay_time_get(arena);
|
|
|
|
for (extent_t *extent = extent_list_first(decay_extents); extent !=
|
|
|
|
NULL; extent = extent_list_first(decay_extents)) {
|
2017-01-16 08:56:30 +08:00
|
|
|
if (config_stats) {
|
2012-02-11 12:22:09 +08:00
|
|
|
nmadvise++;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
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
|
|
|
size_t npages = extent_size_get(extent) >> LG_PAGE;
|
|
|
|
npurged += npages;
|
|
|
|
extent_list_remove(decay_extents, extent);
|
|
|
|
switch (extents_state_get(extents)) {
|
|
|
|
case extent_state_active:
|
|
|
|
not_reached();
|
|
|
|
case extent_state_dirty:
|
|
|
|
if (!all && muzzy_decay_time != 0 &&
|
|
|
|
!extent_purge_lazy_wrapper(tsdn, arena,
|
|
|
|
r_extent_hooks, extent, 0,
|
|
|
|
extent_size_get(extent))) {
|
|
|
|
extents_dalloc(tsdn, arena, r_extent_hooks,
|
|
|
|
&arena->extents_muzzy, extent);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* Fall through. */
|
|
|
|
case extent_state_muzzy:
|
|
|
|
extent_dalloc_wrapper(tsdn, arena, r_extent_hooks,
|
|
|
|
extent);
|
|
|
|
if (config_stats) {
|
|
|
|
nunmapped += npages;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case extent_state_retained:
|
|
|
|
default:
|
|
|
|
not_reached();
|
|
|
|
}
|
2010-03-15 08:36:10 +08:00
|
|
|
}
|
2014-07-22 09:09:04 +08:00
|
|
|
|
|
|
|
if (config_stats) {
|
2017-02-13 09:43:33 +08:00
|
|
|
arena_stats_lock(tsdn, &arena->stats);
|
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
|
|
|
arena_stats_add_u64(tsdn, &arena->stats, &decay->stats->npurge,
|
|
|
|
1);
|
|
|
|
arena_stats_add_u64(tsdn, &arena->stats,
|
|
|
|
&decay->stats->nmadvise, nmadvise);
|
|
|
|
arena_stats_add_u64(tsdn, &arena->stats, &decay->stats->purged,
|
2017-02-13 09:43:33 +08:00
|
|
|
npurged);
|
2017-02-14 02:35:41 +08:00
|
|
|
arena_stats_sub_zu(tsdn, &arena->stats, &arena->stats.mapped,
|
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
|
|
|
nunmapped);
|
2017-02-13 09:43:33 +08:00
|
|
|
arena_stats_unlock(tsdn, &arena->stats);
|
2014-07-22 09:09:04 +08:00
|
|
|
}
|
2010-03-15 08:36:10 +08:00
|
|
|
|
2017-01-20 10:15:45 +08:00
|
|
|
return npurged;
|
2014-01-15 08:23:03 +08:00
|
|
|
}
|
|
|
|
|
2016-02-20 12:09:31 +08:00
|
|
|
/*
|
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
|
|
|
* npages_limit: Decay as many dirty extents as possible without violating the
|
|
|
|
* invariant: (extents_npages_get(extents) >= npages_limit)
|
2016-02-20 12:09:31 +08:00
|
|
|
*/
|
2015-03-19 09:55:33 +08:00
|
|
|
static void
|
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
|
|
|
arena_decay_to_limit(tsdn_t *tsdn, arena_t *arena, arena_decay_t *decay,
|
|
|
|
extents_t *extents, bool all, size_t npages_limit) {
|
2017-01-30 13:57:14 +08:00
|
|
|
witness_assert_depth_to_rank(tsdn, WITNESS_RANK_CORE, 1);
|
2017-03-08 01:22:33 +08:00
|
|
|
malloc_mutex_assert_owner(tsdn, &decay->mtx);
|
2017-01-30 13:57:14 +08:00
|
|
|
|
2017-03-08 11:52:57 +08:00
|
|
|
if (decay->purging) {
|
2017-01-30 13:57:14 +08:00
|
|
|
return;
|
|
|
|
}
|
2017-03-08 11:52:57 +08:00
|
|
|
decay->purging = 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
|
|
|
malloc_mutex_unlock(tsdn, &decay->mtx);
|
2017-01-30 13:57:14 +08:00
|
|
|
|
2016-06-04 03:05:53 +08:00
|
|
|
extent_hooks_t *extent_hooks = extent_hooks_get(arena);
|
2014-07-22 09:09:04 +08:00
|
|
|
|
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_list_t decay_extents;
|
|
|
|
extent_list_init(&decay_extents);
|
2015-06-23 09:50:32 +08:00
|
|
|
|
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
|
|
|
size_t npurge = arena_stash_decayed(tsdn, arena, &extent_hooks, extents,
|
|
|
|
npages_limit, &decay_extents);
|
|
|
|
if (npurge != 0) {
|
|
|
|
UNUSED size_t npurged = arena_decay_stashed(tsdn, arena,
|
|
|
|
&extent_hooks, decay, extents, all, &decay_extents);
|
|
|
|
assert(npurged == npurge);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2015-06-23 09:50:32 +08:00
|
|
|
|
2017-03-08 01:22:33 +08:00
|
|
|
malloc_mutex_lock(tsdn, &decay->mtx);
|
2017-03-08 11:52:57 +08:00
|
|
|
decay->purging = false;
|
2010-01-17 01:53:50 +08:00
|
|
|
}
|
|
|
|
|
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 void
|
|
|
|
arena_decay_impl(tsdn_t *tsdn, arena_t *arena, arena_decay_t *decay,
|
|
|
|
extents_t *extents, bool all) {
|
|
|
|
malloc_mutex_lock(tsdn, &decay->mtx);
|
2017-01-16 08:56:30 +08:00
|
|
|
if (all) {
|
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
|
|
|
arena_decay_to_limit(tsdn, arena, decay, extents, all, 0);
|
2017-01-16 08:56:30 +08:00
|
|
|
} else {
|
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
|
|
|
arena_maybe_decay(tsdn, arena, decay, extents);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
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
|
|
|
malloc_mutex_unlock(tsdn, &decay->mtx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
arena_decay_dirty(tsdn_t *tsdn, arena_t *arena, bool all) {
|
|
|
|
arena_decay_impl(tsdn, arena, &arena->decay_dirty,
|
|
|
|
&arena->extents_dirty, all);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
arena_decay_muzzy(tsdn_t *tsdn, arena_t *arena, bool all) {
|
|
|
|
arena_decay_impl(tsdn, arena, &arena->decay_muzzy,
|
|
|
|
&arena->extents_muzzy, all);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
arena_decay(tsdn_t *tsdn, arena_t *arena, bool all) {
|
|
|
|
arena_decay_dirty(tsdn, arena, all);
|
|
|
|
arena_decay_muzzy(tsdn, arena, all);
|
2010-10-01 07:55:08 +08:00
|
|
|
}
|
|
|
|
|
2016-05-30 09:34:50 +08:00
|
|
|
static void
|
2017-01-16 08:56:30 +08:00
|
|
|
arena_slab_dalloc(tsdn_t *tsdn, arena_t *arena, extent_t *slab) {
|
2017-02-14 02:35:41 +08:00
|
|
|
arena_nactive_sub(arena, extent_size_get(slab) >> LG_PAGE);
|
2017-01-30 13:57:14 +08:00
|
|
|
|
2017-02-14 02:35:41 +08:00
|
|
|
extent_hooks_t *extent_hooks = EXTENT_HOOKS_INITIALIZER;
|
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
|
|
|
arena_extents_dirty_dalloc(tsdn, arena, &extent_hooks, slab);
|
2016-05-30 09:34:50 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 02:31:06 +08:00
|
|
|
static void
|
2017-01-16 08:56:30 +08:00
|
|
|
arena_bin_slabs_nonfull_insert(arena_bin_t *bin, extent_t *slab) {
|
2017-03-28 07:41:47 +08:00
|
|
|
assert(extent_nfree_get(slab) > 0);
|
2016-11-16 02:31:06 +08:00
|
|
|
extent_heap_insert(&bin->slabs_nonfull, slab);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-01-16 08:56:30 +08:00
|
|
|
arena_bin_slabs_nonfull_remove(arena_bin_t *bin, extent_t *slab) {
|
2016-11-16 02:31:06 +08:00
|
|
|
extent_heap_remove(&bin->slabs_nonfull, slab);
|
|
|
|
}
|
|
|
|
|
|
|
|
static extent_t *
|
2017-01-16 08:56:30 +08:00
|
|
|
arena_bin_slabs_nonfull_tryget(arena_bin_t *bin) {
|
2016-11-16 02:31:06 +08:00
|
|
|
extent_t *slab = extent_heap_remove_first(&bin->slabs_nonfull);
|
2017-01-16 08:56:30 +08:00
|
|
|
if (slab == NULL) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return NULL;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
|
|
|
if (config_stats) {
|
2016-11-16 02:31:06 +08:00
|
|
|
bin->stats.reslabs++;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2017-01-20 10:15:45 +08:00
|
|
|
return slab;
|
2016-11-16 02:31:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-01-16 08:56:30 +08:00
|
|
|
arena_bin_slabs_full_insert(arena_bin_t *bin, extent_t *slab) {
|
2017-03-28 07:41:47 +08:00
|
|
|
assert(extent_nfree_get(slab) == 0);
|
2017-01-30 13:57:14 +08:00
|
|
|
extent_list_append(&bin->slabs_full, slab);
|
2016-11-16 02:31:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-01-30 13:57:14 +08:00
|
|
|
arena_bin_slabs_full_remove(arena_bin_t *bin, extent_t *slab) {
|
|
|
|
extent_list_remove(&bin->slabs_full, slab);
|
2016-11-16 02:31:06 +08:00
|
|
|
}
|
|
|
|
|
2016-04-23 05:37:17 +08:00
|
|
|
void
|
2017-01-16 08:56:30 +08:00
|
|
|
arena_reset(tsd_t *tsd, arena_t *arena) {
|
2016-04-23 05:37:17 +08:00
|
|
|
/*
|
|
|
|
* Locking in this function is unintuitive. The caller guarantees that
|
|
|
|
* no concurrent operations are happening in this arena, but there are
|
|
|
|
* still reasons that some locking is necessary:
|
|
|
|
*
|
|
|
|
* - Some of the functions in the transitive closure of calls assume
|
|
|
|
* appropriate locks are held, and in some cases these locks are
|
|
|
|
* temporarily dropped to avoid lock order reversal or deadlock due to
|
|
|
|
* reentry.
|
|
|
|
* - mallctl("epoch", ...) may concurrently refresh stats. While
|
|
|
|
* strictly speaking this is a "concurrent operation", disallowing
|
|
|
|
* stats refreshes would impose an inconvenient burden.
|
|
|
|
*/
|
|
|
|
|
2016-06-01 05:50:21 +08:00
|
|
|
/* Large allocations. */
|
|
|
|
malloc_mutex_lock(tsd_tsdn(tsd), &arena->large_mtx);
|
2017-01-30 13:57:14 +08:00
|
|
|
|
|
|
|
for (extent_t *extent = extent_list_first(&arena->large); extent !=
|
|
|
|
NULL; extent = extent_list_first(&arena->large)) {
|
2016-05-28 09:57:15 +08:00
|
|
|
void *ptr = extent_base_get(extent);
|
2016-04-26 04:26:54 +08:00
|
|
|
size_t usize;
|
2016-04-23 05:37:17 +08:00
|
|
|
|
2016-06-01 05:50:21 +08:00
|
|
|
malloc_mutex_unlock(tsd_tsdn(tsd), &arena->large_mtx);
|
2017-04-12 09:13:10 +08:00
|
|
|
alloc_ctx_t alloc_ctx;
|
|
|
|
rtree_ctx_t *rtree_ctx = tsd_rtree_ctx(tsd);
|
|
|
|
rtree_szind_slab_read(tsd_tsdn(tsd), &extents_rtree, rtree_ctx,
|
|
|
|
(uintptr_t)ptr, true, &alloc_ctx.szind, &alloc_ctx.slab);
|
|
|
|
assert(alloc_ctx.szind != NSIZES);
|
|
|
|
|
2017-01-16 08:56:30 +08:00
|
|
|
if (config_stats || (config_prof && opt_prof)) {
|
2017-04-12 09:13:10 +08:00
|
|
|
usize = index2size(alloc_ctx.szind);
|
|
|
|
assert(usize == isalloc(tsd_tsdn(tsd), ptr));
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2016-06-01 05:50:21 +08:00
|
|
|
/* Remove large allocation from prof sample set. */
|
2017-01-16 08:56:30 +08:00
|
|
|
if (config_prof && opt_prof) {
|
2017-04-12 09:13:10 +08:00
|
|
|
prof_free(tsd, ptr, usize, &alloc_ctx);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2016-06-01 05:50:21 +08:00
|
|
|
large_dalloc(tsd_tsdn(tsd), extent);
|
|
|
|
malloc_mutex_lock(tsd_tsdn(tsd), &arena->large_mtx);
|
2016-04-23 05:37:17 +08:00
|
|
|
}
|
2016-06-01 05:50:21 +08:00
|
|
|
malloc_mutex_unlock(tsd_tsdn(tsd), &arena->large_mtx);
|
2016-04-23 05:37:17 +08:00
|
|
|
|
|
|
|
/* Bins. */
|
2017-01-30 13:57:14 +08:00
|
|
|
for (unsigned i = 0; i < NBINS; i++) {
|
2016-06-04 10:25:13 +08:00
|
|
|
extent_t *slab;
|
2016-04-23 05:37:17 +08:00
|
|
|
arena_bin_t *bin = &arena->bins[i];
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_lock(tsd_tsdn(tsd), &bin->lock);
|
2016-05-30 09:34:50 +08:00
|
|
|
if (bin->slabcur != NULL) {
|
2016-06-04 10:25:13 +08:00
|
|
|
slab = bin->slabcur;
|
2016-05-30 09:34:50 +08:00
|
|
|
bin->slabcur = NULL;
|
2016-06-04 10:25:13 +08:00
|
|
|
malloc_mutex_unlock(tsd_tsdn(tsd), &bin->lock);
|
|
|
|
arena_slab_dalloc(tsd_tsdn(tsd), arena, slab);
|
|
|
|
malloc_mutex_lock(tsd_tsdn(tsd), &bin->lock);
|
2016-05-30 09:34:50 +08:00
|
|
|
}
|
|
|
|
while ((slab = extent_heap_remove_first(&bin->slabs_nonfull)) !=
|
2016-06-04 10:25:13 +08:00
|
|
|
NULL) {
|
|
|
|
malloc_mutex_unlock(tsd_tsdn(tsd), &bin->lock);
|
2016-05-30 09:34:50 +08:00
|
|
|
arena_slab_dalloc(tsd_tsdn(tsd), arena, slab);
|
2016-06-04 10:25:13 +08:00
|
|
|
malloc_mutex_lock(tsd_tsdn(tsd), &bin->lock);
|
|
|
|
}
|
2017-01-30 13:57:14 +08:00
|
|
|
for (slab = extent_list_first(&bin->slabs_full); slab != NULL;
|
|
|
|
slab = extent_list_first(&bin->slabs_full)) {
|
|
|
|
arena_bin_slabs_full_remove(bin, slab);
|
2016-06-04 10:25:13 +08:00
|
|
|
malloc_mutex_unlock(tsd_tsdn(tsd), &bin->lock);
|
2016-05-30 09:34:50 +08:00
|
|
|
arena_slab_dalloc(tsd_tsdn(tsd), arena, slab);
|
2016-06-04 10:25:13 +08:00
|
|
|
malloc_mutex_lock(tsd_tsdn(tsd), &bin->lock);
|
2016-05-30 09:34:50 +08:00
|
|
|
}
|
2016-04-23 05:37:17 +08:00
|
|
|
if (config_stats) {
|
|
|
|
bin->stats.curregs = 0;
|
2016-05-30 09:34:50 +08:00
|
|
|
bin->stats.curslabs = 0;
|
2016-04-23 05:37:17 +08:00
|
|
|
}
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_unlock(tsd_tsdn(tsd), &bin->lock);
|
2016-04-23 05:37:17 +08:00
|
|
|
}
|
|
|
|
|
2017-04-05 08:22:24 +08:00
|
|
|
atomic_store_zu(&arena->nactive, 0, ATOMIC_RELAXED);
|
2016-04-23 05:37:17 +08:00
|
|
|
}
|
|
|
|
|
2017-01-04 09:21:59 +08:00
|
|
|
static void
|
2017-01-16 08:56:30 +08:00
|
|
|
arena_destroy_retained(tsdn_t *tsdn, arena_t *arena) {
|
2017-01-04 09:21:59 +08:00
|
|
|
/*
|
|
|
|
* Iterate over the retained extents and blindly attempt to deallocate
|
|
|
|
* them. This gives the extent allocator underlying the extent hooks an
|
|
|
|
* opportunity to unmap all retained memory without having to keep its
|
|
|
|
* own metadata structures, but if deallocation fails, that is the
|
|
|
|
* application's decision/problem. In practice, retained extents are
|
|
|
|
* leaked here if !config_munmap unless the application provided custom
|
2017-01-17 23:19:17 +08:00
|
|
|
* extent hooks, so best practice is to either enable munmap (and avoid
|
|
|
|
* dss for arenas to be destroyed), or provide custom extent hooks that
|
2017-01-04 09:21:59 +08:00
|
|
|
* either unmap retained extents or track them for later use.
|
|
|
|
*/
|
2017-01-30 13:57:14 +08:00
|
|
|
extent_hooks_t *extent_hooks = extent_hooks_get(arena);
|
2017-03-03 10:04:35 +08:00
|
|
|
extent_t *extent;
|
|
|
|
while ((extent = extents_evict(tsdn, arena, &extent_hooks,
|
|
|
|
&arena->extents_retained, 0)) != NULL) {
|
2017-01-30 13:57:14 +08:00
|
|
|
extent_dalloc_wrapper_try(tsdn, arena, &extent_hooks, extent);
|
2017-01-04 09:21:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-01-16 08:56:30 +08:00
|
|
|
arena_destroy(tsd_t *tsd, arena_t *arena) {
|
2017-01-04 09:21:59 +08:00
|
|
|
assert(base_ind_get(arena->base) >= narenas_auto);
|
|
|
|
assert(arena_nthreads_get(arena, false) == 0);
|
|
|
|
assert(arena_nthreads_get(arena, true) == 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* No allocations have occurred since arena_reset() was called.
|
|
|
|
* Furthermore, the caller (arena_i_destroy_ctl()) purged all cached
|
|
|
|
* extents, so only retained extents may remain.
|
|
|
|
*/
|
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_npages_get(&arena->extents_dirty) == 0);
|
2017-01-04 09:21:59 +08:00
|
|
|
|
|
|
|
/* Attempt to deallocate retained memory. */
|
|
|
|
arena_destroy_retained(tsd_tsdn(tsd), arena);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove the arena pointer from the arenas array. We rely on the fact
|
|
|
|
* that there is no way for the application to get a dirty read from the
|
|
|
|
* arenas array unless there is an inherent race in the application
|
|
|
|
* involving access of an arena being concurrently destroyed. The
|
|
|
|
* application must synchronize knowledge of the arena's validity, so as
|
|
|
|
* long as we use an atomic write to update the arenas array, the
|
|
|
|
* application will get a clean read any time after it synchronizes
|
|
|
|
* knowledge that the arena is no longer valid.
|
|
|
|
*/
|
|
|
|
arena_set(base_ind_get(arena->base), NULL);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Destroy the base allocator, which manages all metadata ever mapped by
|
|
|
|
* this arena.
|
|
|
|
*/
|
|
|
|
base_delete(arena->base);
|
|
|
|
}
|
|
|
|
|
2016-05-30 09:34:50 +08:00
|
|
|
static extent_t *
|
2016-06-01 06:03:51 +08:00
|
|
|
arena_slab_alloc_hard(tsdn_t *tsdn, arena_t *arena,
|
2017-03-14 08:36:57 +08:00
|
|
|
extent_hooks_t **r_extent_hooks, const arena_bin_info_t *bin_info,
|
|
|
|
szind_t szind) {
|
2016-05-30 09:34:50 +08:00
|
|
|
extent_t *slab;
|
|
|
|
bool zero, commit;
|
|
|
|
|
2017-01-30 13:57:14 +08:00
|
|
|
witness_assert_depth_to_rank(tsdn, WITNESS_RANK_CORE, 0);
|
|
|
|
|
2016-05-30 09:34:50 +08:00
|
|
|
zero = false;
|
|
|
|
commit = true;
|
2016-06-04 03:05:53 +08:00
|
|
|
slab = extent_alloc_wrapper(tsdn, arena, r_extent_hooks, NULL,
|
2017-03-14 08:36:57 +08:00
|
|
|
bin_info->slab_size, 0, PAGE, true, szind, &zero, &commit);
|
2012-02-14 09:36:52 +08:00
|
|
|
|
2017-02-14 02:35:41 +08:00
|
|
|
if (config_stats && slab != NULL) {
|
|
|
|
arena_stats_mapped_add(tsdn, &arena->stats,
|
|
|
|
bin_info->slab_size);
|
|
|
|
}
|
|
|
|
|
2017-01-20 10:15:45 +08:00
|
|
|
return slab;
|
2012-02-14 09:36:52 +08:00
|
|
|
}
|
|
|
|
|
2016-05-30 09:34:50 +08:00
|
|
|
static extent_t *
|
|
|
|
arena_slab_alloc(tsdn_t *tsdn, arena_t *arena, szind_t binind,
|
2017-01-16 08:56:30 +08:00
|
|
|
const arena_bin_info_t *bin_info) {
|
2017-01-30 13:57:14 +08:00
|
|
|
witness_assert_depth_to_rank(tsdn, WITNESS_RANK_CORE, 0);
|
|
|
|
|
2016-06-04 03:05:53 +08:00
|
|
|
extent_hooks_t *extent_hooks = EXTENT_HOOKS_INITIALIZER;
|
2017-03-14 08:36:57 +08:00
|
|
|
szind_t szind = size2index(bin_info->reg_size);
|
2016-11-04 08:25:54 +08:00
|
|
|
bool zero = false;
|
2017-01-30 13:57:14 +08:00
|
|
|
bool commit = 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
|
|
|
extent_t *slab = extents_alloc(tsdn, arena, &extent_hooks,
|
2017-03-14 08:36:57 +08:00
|
|
|
&arena->extents_dirty, NULL, bin_info->slab_size, 0, PAGE, true,
|
|
|
|
binind, &zero, &commit);
|
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
|
|
|
if (slab == NULL) {
|
|
|
|
slab = extents_alloc(tsdn, arena, &extent_hooks,
|
|
|
|
&arena->extents_muzzy, NULL, bin_info->slab_size, 0, PAGE,
|
2017-03-14 08:36:57 +08:00
|
|
|
true, binind, &zero, &commit);
|
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
|
|
|
}
|
2016-05-30 09:34:50 +08:00
|
|
|
if (slab == NULL) {
|
2016-06-01 06:03:51 +08:00
|
|
|
slab = arena_slab_alloc_hard(tsdn, arena, &extent_hooks,
|
2017-03-14 08:36:57 +08:00
|
|
|
bin_info, szind);
|
2017-01-16 08:56:30 +08:00
|
|
|
if (slab == NULL) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return NULL;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2016-05-30 09:34:50 +08:00
|
|
|
}
|
|
|
|
assert(extent_slab_get(slab));
|
|
|
|
|
|
|
|
/* Initialize slab internals. */
|
2017-01-30 13:57:14 +08:00
|
|
|
arena_slab_data_t *slab_data = extent_slab_data_get(slab);
|
2017-03-28 07:41:47 +08:00
|
|
|
extent_nfree_set(slab, bin_info->nregs);
|
2017-03-24 08:59:47 +08:00
|
|
|
bitmap_init(slab_data->bitmap, &bin_info->bitmap_info, false);
|
2016-03-27 08:30:37 +08:00
|
|
|
|
2017-02-14 02:35:41 +08:00
|
|
|
arena_nactive_add(arena, extent_size_get(slab) >> LG_PAGE);
|
2016-03-27 08:30:37 +08:00
|
|
|
|
2017-01-20 10:15:45 +08:00
|
|
|
return slab;
|
2012-02-14 09:36:52 +08:00
|
|
|
}
|
|
|
|
|
2016-05-30 09:34:50 +08:00
|
|
|
static extent_t *
|
|
|
|
arena_bin_nonfull_slab_get(tsdn_t *tsdn, arena_t *arena, arena_bin_t *bin,
|
2017-01-16 08:56:30 +08:00
|
|
|
szind_t binind) {
|
2016-05-30 09:34:50 +08:00
|
|
|
extent_t *slab;
|
2016-04-07 20:04:12 +08:00
|
|
|
const arena_bin_info_t *bin_info;
|
2012-02-14 09:36:52 +08:00
|
|
|
|
2016-05-30 09:34:50 +08:00
|
|
|
/* Look for a usable slab. */
|
|
|
|
slab = arena_bin_slabs_nonfull_tryget(bin);
|
2017-01-16 08:56:30 +08:00
|
|
|
if (slab != NULL) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return slab;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2016-05-30 09:34:50 +08:00
|
|
|
/* No existing slabs have any space available. */
|
2010-01-17 01:53:50 +08:00
|
|
|
|
2011-03-16 04:59:15 +08:00
|
|
|
bin_info = &arena_bin_info[binind];
|
|
|
|
|
2016-05-30 09:34:50 +08:00
|
|
|
/* Allocate a new slab. */
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_unlock(tsdn, &bin->lock);
|
2010-03-16 13:25:23 +08:00
|
|
|
/******************************/
|
2016-05-30 09:34:50 +08:00
|
|
|
slab = arena_slab_alloc(tsdn, arena, binind, bin_info);
|
2010-03-16 13:25:23 +08:00
|
|
|
/********************************/
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_lock(tsdn, &bin->lock);
|
2016-05-30 09:34:50 +08:00
|
|
|
if (slab != NULL) {
|
2012-02-11 12:22:09 +08:00
|
|
|
if (config_stats) {
|
2016-05-30 09:34:50 +08:00
|
|
|
bin->stats.nslabs++;
|
|
|
|
bin->stats.curslabs++;
|
2012-02-11 12:22:09 +08:00
|
|
|
}
|
2017-01-20 10:15:45 +08:00
|
|
|
return slab;
|
2010-03-15 10:43:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2016-05-30 09:34:50 +08:00
|
|
|
* arena_slab_alloc() failed, but another thread may have made
|
Fix numerous arena bugs.
In arena_ralloc_large_grow(), update the map element for the end of the
newly grown run, rather than the interior map element that was the
beginning of the appended run. This is a long-standing bug, and it had
the potential to cause massive corruption, but triggering it required
roughly the following sequence of events:
1) Large in-place growing realloc(), with left-over space in the run
that followed the large object.
2) Allocation of the remainder run left over from (1).
3) Deallocation of the remainder run *before* deallocation of the
large run, with unfortunate interior map state left over from
previous run allocation/deallocation activity, such that one or
more pages of allocated memory would be treated as part of the
remainder run during run coalescing.
In summary, this was a bad bug, but it was difficult to trigger.
In arena_bin_malloc_hard(), if another thread wins the race to allocate
a bin run, dispose of the spare run via arena_bin_lower_run() rather
than arena_run_dalloc(), since the run has already been prepared for use
as a bin run. This bug has existed since March 14, 2010:
e00572b384c81bd2aba57fac32f7077a34388915
mmap()/munmap() without arena->lock or bin->lock.
Fix bugs in arena_dalloc_bin_run(), arena_trim_head(),
arena_trim_tail(), and arena_ralloc_large_grow() that could cause the
CHUNK_MAP_UNZEROED map bit to become corrupted. These are all
long-standing bugs, but the chances of them actually causing problems
was much lower before the CHUNK_MAP_ZEROED --> CHUNK_MAP_UNZEROED
conversion.
Fix a large run statistics regression in arena_ralloc_large_grow() that
was introduced on September 17, 2010:
8e3c3c61b5bb676a705450708e7e79698cdc9e0c
Add {,r,s,d}allocm().
Add debug code to validate that supposedly pre-zeroed memory really is.
2010-10-18 08:51:37 +08:00
|
|
|
* sufficient memory available while this one dropped bin->lock above,
|
2010-03-15 10:43:56 +08:00
|
|
|
* so search one more time.
|
|
|
|
*/
|
2016-05-30 09:34:50 +08:00
|
|
|
slab = arena_bin_slabs_nonfull_tryget(bin);
|
2017-01-16 08:56:30 +08:00
|
|
|
if (slab != NULL) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return slab;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2010-03-15 10:43:56 +08:00
|
|
|
|
2017-01-20 10:15:45 +08:00
|
|
|
return NULL;
|
2010-01-17 01:53:50 +08:00
|
|
|
}
|
|
|
|
|
2016-05-30 09:34:50 +08:00
|
|
|
/* Re-fill bin->slabcur, then call arena_slab_reg_alloc(). */
|
2010-01-17 01:53:50 +08:00
|
|
|
static void *
|
2016-05-30 09:34:50 +08:00
|
|
|
arena_bin_malloc_hard(tsdn_t *tsdn, arena_t *arena, arena_bin_t *bin,
|
2017-01-16 08:56:30 +08:00
|
|
|
szind_t binind) {
|
2016-04-07 20:04:12 +08:00
|
|
|
const arena_bin_info_t *bin_info;
|
2016-05-30 09:34:50 +08:00
|
|
|
extent_t *slab;
|
|
|
|
|
2011-03-16 04:59:15 +08:00
|
|
|
bin_info = &arena_bin_info[binind];
|
2016-05-30 09:34:50 +08:00
|
|
|
if (bin->slabcur != NULL) {
|
|
|
|
arena_bin_slabs_full_insert(bin, bin->slabcur);
|
|
|
|
bin->slabcur = NULL;
|
|
|
|
}
|
|
|
|
slab = arena_bin_nonfull_slab_get(tsdn, arena, bin, binind);
|
|
|
|
if (bin->slabcur != NULL) {
|
2010-03-15 10:43:56 +08:00
|
|
|
/*
|
2016-05-30 09:34:50 +08:00
|
|
|
* Another thread updated slabcur while this one ran without the
|
|
|
|
* bin lock in arena_bin_nonfull_slab_get().
|
2010-03-15 10:43:56 +08:00
|
|
|
*/
|
2017-03-28 07:41:47 +08:00
|
|
|
if (extent_nfree_get(bin->slabcur) > 0) {
|
2016-05-30 09:34:50 +08:00
|
|
|
void *ret = arena_slab_reg_alloc(tsdn, bin->slabcur,
|
|
|
|
bin_info);
|
|
|
|
if (slab != NULL) {
|
|
|
|
/*
|
|
|
|
* arena_slab_alloc() may have allocated slab,
|
|
|
|
* or it may have been pulled from
|
|
|
|
* slabs_nonfull. Therefore it is unsafe to
|
|
|
|
* make any assumptions about how slab has
|
|
|
|
* previously been used, and
|
|
|
|
* arena_bin_lower_slab() must be called, as if
|
|
|
|
* a region were just deallocated from the slab.
|
|
|
|
*/
|
2017-03-28 07:41:47 +08:00
|
|
|
if (extent_nfree_get(slab) == bin_info->nregs) {
|
2016-05-30 09:34:50 +08:00
|
|
|
arena_dalloc_bin_slab(tsdn, arena, slab,
|
|
|
|
bin);
|
|
|
|
} else {
|
|
|
|
arena_bin_lower_slab(tsdn, arena, slab,
|
|
|
|
bin);
|
|
|
|
}
|
2016-05-26 07:21:37 +08:00
|
|
|
}
|
2017-01-20 10:15:45 +08:00
|
|
|
return ret;
|
2010-03-15 10:43:56 +08:00
|
|
|
}
|
2016-05-30 09:34:50 +08:00
|
|
|
|
|
|
|
arena_bin_slabs_full_insert(bin, bin->slabcur);
|
|
|
|
bin->slabcur = NULL;
|
2010-03-15 10:43:56 +08:00
|
|
|
}
|
|
|
|
|
2017-01-16 08:56:30 +08:00
|
|
|
if (slab == NULL) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return NULL;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2016-05-30 09:34:50 +08:00
|
|
|
bin->slabcur = slab;
|
2010-03-15 10:43:56 +08:00
|
|
|
|
2017-03-28 07:41:47 +08:00
|
|
|
assert(extent_nfree_get(bin->slabcur) > 0);
|
2010-01-17 01:53:50 +08:00
|
|
|
|
2017-01-20 10:15:45 +08:00
|
|
|
return arena_slab_reg_alloc(tsdn, slab, bin_info);
|
2010-01-17 01:53:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-04-07 03:35:22 +08:00
|
|
|
arena_tcache_fill_small(tsdn_t *tsdn, arena_t *arena, tcache_t *tcache,
|
|
|
|
tcache_bin_t *tbin, szind_t binind, uint64_t prof_accumbytes) {
|
2010-01-17 01:53:50 +08:00
|
|
|
unsigned i, nfill;
|
|
|
|
arena_bin_t *bin;
|
|
|
|
|
|
|
|
assert(tbin->ncached == 0);
|
|
|
|
|
2017-01-16 08:56:30 +08:00
|
|
|
if (config_prof && arena_prof_accum(tsdn, arena, prof_accumbytes)) {
|
2016-05-11 13:21:10 +08:00
|
|
|
prof_idump(tsdn);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2010-03-16 13:25:23 +08:00
|
|
|
bin = &arena->bins[binind];
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_lock(tsdn, &bin->lock);
|
2011-03-21 15:18:17 +08:00
|
|
|
for (i = 0, nfill = (tcache_bin_info[binind].ncached_max >>
|
2017-04-07 03:35:22 +08:00
|
|
|
tcache->lg_fill_div[binind]); i < nfill; i++) {
|
2016-05-30 09:34:50 +08:00
|
|
|
extent_t *slab;
|
2015-09-04 18:15:28 +08:00
|
|
|
void *ptr;
|
2017-03-28 07:41:47 +08:00
|
|
|
if ((slab = bin->slabcur) != NULL && extent_nfree_get(slab) >
|
|
|
|
0) {
|
2016-05-30 09:34:50 +08:00
|
|
|
ptr = arena_slab_reg_alloc(tsdn, slab,
|
2016-05-26 07:21:37 +08:00
|
|
|
&arena_bin_info[binind]);
|
2017-01-16 08:56:30 +08:00
|
|
|
} else {
|
2016-05-30 09:34:50 +08:00
|
|
|
ptr = arena_bin_malloc_hard(tsdn, arena, bin, binind);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2014-10-06 04:05:10 +08:00
|
|
|
if (ptr == NULL) {
|
|
|
|
/*
|
|
|
|
* OOM. tbin->avail isn't yet filled down to its first
|
|
|
|
* element, so the successful allocations (if any) must
|
2015-10-28 06:12:10 +08:00
|
|
|
* be moved just before tbin->avail before bailing out.
|
2014-10-06 04:05:10 +08:00
|
|
|
*/
|
|
|
|
if (i > 0) {
|
2015-10-28 06:12:10 +08:00
|
|
|
memmove(tbin->avail - i, tbin->avail - nfill,
|
2014-10-06 04:05:10 +08:00
|
|
|
i * sizeof(void *));
|
|
|
|
}
|
2010-01-17 01:53:50 +08:00
|
|
|
break;
|
2014-10-06 04:05:10 +08:00
|
|
|
}
|
2014-12-09 05:12:41 +08:00
|
|
|
if (config_fill && unlikely(opt_junk_alloc)) {
|
2012-04-06 15:35:09 +08:00
|
|
|
arena_alloc_junk_small(ptr, &arena_bin_info[binind],
|
|
|
|
true);
|
|
|
|
}
|
2011-03-19 01:53:15 +08:00
|
|
|
/* Insert such that low regions get used first. */
|
2015-10-28 06:12:10 +08:00
|
|
|
*(tbin->avail - nfill + i) = ptr;
|
2010-01-17 01:53:50 +08:00
|
|
|
}
|
2012-02-11 12:22:09 +08:00
|
|
|
if (config_stats) {
|
|
|
|
bin->stats.nmalloc += i;
|
|
|
|
bin->stats.nrequests += tbin->tstats.nrequests;
|
2014-10-13 13:53:59 +08:00
|
|
|
bin->stats.curregs += i;
|
2012-02-11 12:22:09 +08:00
|
|
|
bin->stats.nfills++;
|
|
|
|
tbin->tstats.nrequests = 0;
|
|
|
|
}
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_unlock(tsdn, &bin->lock);
|
2010-01-17 01:53:50 +08:00
|
|
|
tbin->ncached = i;
|
2016-05-11 13:21:10 +08:00
|
|
|
arena_decay_tick(tsdn, arena);
|
2010-01-17 01:53:50 +08:00
|
|
|
}
|
|
|
|
|
2012-04-06 15:35:09 +08:00
|
|
|
void
|
2017-01-16 08:56:30 +08:00
|
|
|
arena_alloc_junk_small(void *ptr, const arena_bin_info_t *bin_info, bool zero) {
|
|
|
|
if (!zero) {
|
2016-04-06 09:18:15 +08:00
|
|
|
memset(ptr, JEMALLOC_ALLOC_JUNK, bin_info->reg_size);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2013-12-18 07:14:36 +08:00
|
|
|
}
|
|
|
|
|
2014-01-08 08:47:56 +08:00
|
|
|
#ifdef JEMALLOC_JET
|
|
|
|
#undef arena_dalloc_junk_small
|
2017-01-20 13:41:41 +08:00
|
|
|
#define arena_dalloc_junk_small JEMALLOC_N(n_arena_dalloc_junk_small)
|
2014-01-08 08:47:56 +08:00
|
|
|
#endif
|
2013-12-18 07:14:36 +08:00
|
|
|
void
|
2017-01-16 08:56:30 +08:00
|
|
|
arena_dalloc_junk_small(void *ptr, const arena_bin_info_t *bin_info) {
|
2016-04-06 09:18:15 +08:00
|
|
|
memset(ptr, JEMALLOC_FREE_JUNK, bin_info->reg_size);
|
2012-04-06 15:35:09 +08:00
|
|
|
}
|
2014-01-08 08:47:56 +08:00
|
|
|
#ifdef JEMALLOC_JET
|
|
|
|
#undef arena_dalloc_junk_small
|
2017-01-20 13:41:41 +08:00
|
|
|
#define arena_dalloc_junk_small JEMALLOC_N(arena_dalloc_junk_small)
|
2014-01-08 08:47:56 +08:00
|
|
|
arena_dalloc_junk_small_t *arena_dalloc_junk_small =
|
2016-04-19 06:11:20 +08:00
|
|
|
JEMALLOC_N(n_arena_dalloc_junk_small);
|
2014-01-08 08:47:56 +08:00
|
|
|
#endif
|
2012-04-06 15:35:09 +08:00
|
|
|
|
2016-02-20 10:40:03 +08:00
|
|
|
static void *
|
2017-01-16 08:56:30 +08:00
|
|
|
arena_malloc_small(tsdn_t *tsdn, arena_t *arena, szind_t binind, bool zero) {
|
2010-01-17 01:53:50 +08:00
|
|
|
void *ret;
|
|
|
|
arena_bin_t *bin;
|
2016-02-26 07:29:49 +08:00
|
|
|
size_t usize;
|
2016-05-30 09:34:50 +08:00
|
|
|
extent_t *slab;
|
2010-01-17 01:53:50 +08:00
|
|
|
|
2012-02-29 08:50:47 +08:00
|
|
|
assert(binind < NBINS);
|
2010-01-17 01:53:50 +08:00
|
|
|
bin = &arena->bins[binind];
|
2016-02-26 07:29:49 +08:00
|
|
|
usize = index2size(binind);
|
2010-01-17 01:53:50 +08:00
|
|
|
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_lock(tsdn, &bin->lock);
|
2017-03-28 07:41:47 +08:00
|
|
|
if ((slab = bin->slabcur) != NULL && extent_nfree_get(slab) > 0) {
|
2016-05-30 09:34:50 +08:00
|
|
|
ret = arena_slab_reg_alloc(tsdn, slab, &arena_bin_info[binind]);
|
2017-01-16 08:56:30 +08:00
|
|
|
} else {
|
2016-05-30 09:34:50 +08:00
|
|
|
ret = arena_bin_malloc_hard(tsdn, arena, bin, binind);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2010-01-17 01:53:50 +08:00
|
|
|
|
|
|
|
if (ret == NULL) {
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_unlock(tsdn, &bin->lock);
|
2017-01-20 10:15:45 +08:00
|
|
|
return NULL;
|
2010-01-17 01:53:50 +08:00
|
|
|
}
|
|
|
|
|
2012-02-11 12:22:09 +08:00
|
|
|
if (config_stats) {
|
|
|
|
bin->stats.nmalloc++;
|
|
|
|
bin->stats.nrequests++;
|
2014-10-13 13:53:59 +08:00
|
|
|
bin->stats.curregs++;
|
2012-02-11 12:22:09 +08:00
|
|
|
}
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_unlock(tsdn, &bin->lock);
|
2017-01-16 08:56:30 +08:00
|
|
|
if (config_prof && arena_prof_accum(tsdn, arena, usize)) {
|
2016-05-11 13:21:10 +08:00
|
|
|
prof_idump(tsdn);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2010-01-17 01:53:50 +08:00
|
|
|
|
2014-10-04 01:16:09 +08:00
|
|
|
if (!zero) {
|
2012-02-11 12:22:09 +08:00
|
|
|
if (config_fill) {
|
2014-12-09 05:12:41 +08:00
|
|
|
if (unlikely(opt_junk_alloc)) {
|
2012-04-06 15:35:09 +08:00
|
|
|
arena_alloc_junk_small(ret,
|
|
|
|
&arena_bin_info[binind], false);
|
2017-01-16 08:56:30 +08:00
|
|
|
} else if (unlikely(opt_zero)) {
|
2016-02-26 07:29:49 +08:00
|
|
|
memset(ret, 0, usize);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2012-02-11 12:22:09 +08:00
|
|
|
}
|
2012-04-06 15:35:09 +08:00
|
|
|
} else {
|
2014-12-09 05:12:41 +08:00
|
|
|
if (config_fill && unlikely(opt_junk_alloc)) {
|
2012-04-06 15:35:09 +08:00
|
|
|
arena_alloc_junk_small(ret, &arena_bin_info[binind],
|
|
|
|
true);
|
|
|
|
}
|
2016-02-26 07:29:49 +08:00
|
|
|
memset(ret, 0, usize);
|
2012-04-06 15:35:09 +08:00
|
|
|
}
|
2010-01-17 01:53:50 +08:00
|
|
|
|
2016-05-11 13:21:10 +08:00
|
|
|
arena_decay_tick(tsdn, arena);
|
2017-01-20 10:15:45 +08:00
|
|
|
return ret;
|
2010-01-17 01:53:50 +08:00
|
|
|
}
|
|
|
|
|
2016-02-20 10:40:03 +08:00
|
|
|
void *
|
2016-05-11 13:21:10 +08:00
|
|
|
arena_malloc_hard(tsdn_t *tsdn, arena_t *arena, size_t size, szind_t ind,
|
2017-01-16 08:56:30 +08:00
|
|
|
bool zero) {
|
2016-05-11 13:21:10 +08:00
|
|
|
assert(!tsdn_null(tsdn) || arena != NULL);
|
|
|
|
|
2017-01-16 08:56:30 +08:00
|
|
|
if (likely(!tsdn_null(tsdn))) {
|
2016-05-11 13:21:10 +08:00
|
|
|
arena = arena_choose(tsdn_tsd(tsdn), arena);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
|
|
|
if (unlikely(arena == NULL)) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return NULL;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2016-02-20 10:40:03 +08:00
|
|
|
|
2017-01-16 08:56:30 +08:00
|
|
|
if (likely(size <= SMALL_MAXCLASS)) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return arena_malloc_small(tsdn, arena, ind, zero);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2017-01-20 10:15:45 +08:00
|
|
|
return large_malloc(tsdn, arena, index2size(ind), zero);
|
2016-02-20 10:40:03 +08:00
|
|
|
}
|
|
|
|
|
2015-02-13 06:06:37 +08:00
|
|
|
void *
|
2016-05-11 13:21:10 +08:00
|
|
|
arena_palloc(tsdn_t *tsdn, arena_t *arena, size_t usize, size_t alignment,
|
2017-01-16 08:56:30 +08:00
|
|
|
bool zero, tcache_t *tcache) {
|
2015-02-13 06:06:37 +08:00
|
|
|
void *ret;
|
|
|
|
|
2015-05-05 00:58:36 +08:00
|
|
|
if (usize <= SMALL_MAXCLASS && (alignment < PAGE || (alignment == PAGE
|
2015-05-20 08:42:31 +08:00
|
|
|
&& (usize & PAGE_MASK) == 0))) {
|
2016-05-30 09:34:50 +08:00
|
|
|
/* Small; alignment doesn't require special slab placement. */
|
2016-05-11 13:21:10 +08:00
|
|
|
ret = arena_malloc(tsdn, arena, usize, size2index(usize), zero,
|
2015-10-28 06:12:10 +08:00
|
|
|
tcache, true);
|
2015-05-20 08:42:31 +08:00
|
|
|
} else {
|
2017-01-16 08:56:30 +08:00
|
|
|
if (likely(alignment <= CACHELINE)) {
|
2016-06-01 05:50:21 +08:00
|
|
|
ret = large_malloc(tsdn, arena, usize, zero);
|
2017-01-16 08:56:30 +08:00
|
|
|
} else {
|
2016-06-01 05:50:21 +08:00
|
|
|
ret = large_palloc(tsdn, arena, usize, alignment, zero);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2015-02-13 06:06:37 +08:00
|
|
|
}
|
2017-01-20 10:15:45 +08:00
|
|
|
return ret;
|
2015-02-13 06:06:37 +08:00
|
|
|
}
|
|
|
|
|
2010-04-01 07:45:04 +08:00
|
|
|
void
|
2017-03-21 02:00:07 +08:00
|
|
|
arena_prof_promote(tsdn_t *tsdn, const void *ptr, size_t usize) {
|
2012-04-19 04:38:40 +08:00
|
|
|
cassert(config_prof);
|
2010-04-01 07:45:04 +08:00
|
|
|
assert(ptr != NULL);
|
2017-03-17 16:25:12 +08:00
|
|
|
assert(isalloc(tsdn, ptr) == LARGE_MINCLASS);
|
2016-05-28 15:17:28 +08:00
|
|
|
assert(usize <= SMALL_MAXCLASS);
|
2010-04-01 07:45:04 +08:00
|
|
|
|
2017-03-17 08:57:52 +08:00
|
|
|
rtree_ctx_t rtree_ctx_fallback;
|
|
|
|
rtree_ctx_t *rtree_ctx = tsdn_rtree_ctx(tsdn, &rtree_ctx_fallback);
|
2017-03-21 02:00:07 +08:00
|
|
|
|
|
|
|
extent_t *extent = rtree_extent_read(tsdn, &extents_rtree, rtree_ctx,
|
|
|
|
(uintptr_t)ptr, true);
|
|
|
|
arena_t *arena = extent_arena_get(extent);
|
|
|
|
|
|
|
|
szind_t szind = size2index(usize);
|
|
|
|
extent_szind_set(extent, szind);
|
2017-03-17 08:57:52 +08:00
|
|
|
rtree_szind_slab_update(tsdn, &extents_rtree, rtree_ctx, (uintptr_t)ptr,
|
|
|
|
szind, false);
|
2010-04-01 07:45:04 +08:00
|
|
|
|
2017-02-13 09:03:46 +08:00
|
|
|
prof_accum_cancel(tsdn, &arena->prof_accum, usize);
|
2016-05-29 08:29:03 +08:00
|
|
|
|
2017-03-17 16:25:12 +08:00
|
|
|
assert(isalloc(tsdn, ptr) == usize);
|
2016-05-28 15:17:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static size_t
|
2017-01-16 08:56:30 +08:00
|
|
|
arena_prof_demote(tsdn_t *tsdn, extent_t *extent, const void *ptr) {
|
2016-05-28 15:17:28 +08:00
|
|
|
cassert(config_prof);
|
|
|
|
assert(ptr != NULL);
|
|
|
|
|
2017-03-14 08:36:57 +08:00
|
|
|
extent_szind_set(extent, NBINS);
|
2017-03-17 08:57:52 +08:00
|
|
|
rtree_ctx_t rtree_ctx_fallback;
|
|
|
|
rtree_ctx_t *rtree_ctx = tsdn_rtree_ctx(tsdn, &rtree_ctx_fallback);
|
|
|
|
rtree_szind_slab_update(tsdn, &extents_rtree, rtree_ctx, (uintptr_t)ptr,
|
|
|
|
NBINS, false);
|
2016-05-28 15:17:28 +08:00
|
|
|
|
2017-03-17 16:25:12 +08:00
|
|
|
assert(isalloc(tsdn, ptr) == LARGE_MINCLASS);
|
2016-05-28 15:17:28 +08:00
|
|
|
|
2017-01-20 10:15:45 +08:00
|
|
|
return LARGE_MINCLASS;
|
2016-05-28 15:17:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-03-21 02:00:07 +08:00
|
|
|
arena_dalloc_promoted(tsdn_t *tsdn, void *ptr, tcache_t *tcache,
|
|
|
|
bool slow_path) {
|
2016-05-28 15:17:28 +08:00
|
|
|
cassert(config_prof);
|
|
|
|
assert(opt_prof);
|
|
|
|
|
2017-03-21 02:00:07 +08:00
|
|
|
extent_t *extent = iealloc(tsdn, ptr);
|
|
|
|
size_t usize = arena_prof_demote(tsdn, extent, ptr);
|
2016-05-28 15:17:28 +08:00
|
|
|
if (usize <= tcache_maxclass) {
|
2017-03-14 08:36:57 +08:00
|
|
|
tcache_dalloc_large(tsdn_tsd(tsdn), tcache, ptr,
|
|
|
|
size2index(usize), slow_path);
|
2017-01-16 08:56:30 +08:00
|
|
|
} else {
|
2016-06-01 05:50:21 +08:00
|
|
|
large_dalloc(tsdn, extent);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2010-04-01 07:45:04 +08:00
|
|
|
}
|
2010-02-11 02:37:56 +08:00
|
|
|
|
2010-01-17 01:53:50 +08:00
|
|
|
static void
|
2017-01-16 08:56:30 +08:00
|
|
|
arena_dissociate_bin_slab(extent_t *slab, arena_bin_t *bin) {
|
2016-05-30 09:34:50 +08:00
|
|
|
/* Dissociate slab from bin. */
|
2017-01-16 08:56:30 +08:00
|
|
|
if (slab == bin->slabcur) {
|
2016-05-30 09:34:50 +08:00
|
|
|
bin->slabcur = NULL;
|
2017-01-16 08:56:30 +08:00
|
|
|
} else {
|
2017-03-14 08:48:26 +08:00
|
|
|
szind_t binind = extent_szind_get(slab);
|
2016-04-07 20:04:12 +08:00
|
|
|
const arena_bin_info_t *bin_info = &arena_bin_info[binind];
|
2011-03-16 04:59:15 +08:00
|
|
|
|
2016-03-27 08:30:37 +08:00
|
|
|
/*
|
|
|
|
* The following block's conditional is necessary because if the
|
2016-05-30 09:34:50 +08:00
|
|
|
* slab only contains one region, then it never gets inserted
|
|
|
|
* into the non-full slabs heap.
|
2016-03-27 08:30:37 +08:00
|
|
|
*/
|
2017-01-16 08:56:30 +08:00
|
|
|
if (bin_info->nregs == 1) {
|
2017-01-30 13:57:14 +08:00
|
|
|
arena_bin_slabs_full_remove(bin, slab);
|
2017-01-16 08:56:30 +08:00
|
|
|
} else {
|
2016-05-30 09:34:50 +08:00
|
|
|
arena_bin_slabs_nonfull_remove(bin, slab);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2010-01-17 01:53:50 +08:00
|
|
|
}
|
2010-10-18 15:04:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-05-30 09:34:50 +08:00
|
|
|
arena_dalloc_bin_slab(tsdn_t *tsdn, arena_t *arena, extent_t *slab,
|
2017-01-16 08:56:30 +08:00
|
|
|
arena_bin_t *bin) {
|
2016-05-30 09:34:50 +08:00
|
|
|
assert(slab != bin->slabcur);
|
2010-03-14 12:32:56 +08:00
|
|
|
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_unlock(tsdn, &bin->lock);
|
2010-03-15 10:43:56 +08:00
|
|
|
/******************************/
|
2016-05-30 09:34:50 +08:00
|
|
|
arena_slab_dalloc(tsdn, arena, slab);
|
2010-03-15 10:43:56 +08:00
|
|
|
/****************************/
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_lock(tsdn, &bin->lock);
|
2017-01-16 08:56:30 +08:00
|
|
|
if (config_stats) {
|
2016-05-30 09:34:50 +08:00
|
|
|
bin->stats.curslabs--;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2010-01-17 01:53:50 +08:00
|
|
|
}
|
|
|
|
|
Fix numerous arena bugs.
In arena_ralloc_large_grow(), update the map element for the end of the
newly grown run, rather than the interior map element that was the
beginning of the appended run. This is a long-standing bug, and it had
the potential to cause massive corruption, but triggering it required
roughly the following sequence of events:
1) Large in-place growing realloc(), with left-over space in the run
that followed the large object.
2) Allocation of the remainder run left over from (1).
3) Deallocation of the remainder run *before* deallocation of the
large run, with unfortunate interior map state left over from
previous run allocation/deallocation activity, such that one or
more pages of allocated memory would be treated as part of the
remainder run during run coalescing.
In summary, this was a bad bug, but it was difficult to trigger.
In arena_bin_malloc_hard(), if another thread wins the race to allocate
a bin run, dispose of the spare run via arena_bin_lower_run() rather
than arena_run_dalloc(), since the run has already been prepared for use
as a bin run. This bug has existed since March 14, 2010:
e00572b384c81bd2aba57fac32f7077a34388915
mmap()/munmap() without arena->lock or bin->lock.
Fix bugs in arena_dalloc_bin_run(), arena_trim_head(),
arena_trim_tail(), and arena_ralloc_large_grow() that could cause the
CHUNK_MAP_UNZEROED map bit to become corrupted. These are all
long-standing bugs, but the chances of them actually causing problems
was much lower before the CHUNK_MAP_ZEROED --> CHUNK_MAP_UNZEROED
conversion.
Fix a large run statistics regression in arena_ralloc_large_grow() that
was introduced on September 17, 2010:
8e3c3c61b5bb676a705450708e7e79698cdc9e0c
Add {,r,s,d}allocm().
Add debug code to validate that supposedly pre-zeroed memory really is.
2010-10-18 08:51:37 +08:00
|
|
|
static void
|
2016-05-30 09:34:50 +08:00
|
|
|
arena_bin_lower_slab(tsdn_t *tsdn, arena_t *arena, extent_t *slab,
|
2017-01-16 08:56:30 +08:00
|
|
|
arena_bin_t *bin) {
|
2017-03-28 07:41:47 +08:00
|
|
|
assert(extent_nfree_get(slab) > 0);
|
2016-05-30 09:34:50 +08:00
|
|
|
|
2010-10-18 11:57:30 +08:00
|
|
|
/*
|
2016-11-16 05:07:53 +08:00
|
|
|
* Make sure that if bin->slabcur is non-NULL, it refers to the
|
|
|
|
* oldest/lowest non-full slab. It is okay to NULL slabcur out rather
|
|
|
|
* than proactively keeping it pointing at the oldest/lowest non-full
|
|
|
|
* slab.
|
2010-10-18 11:57:30 +08:00
|
|
|
*/
|
2016-11-16 05:07:53 +08:00
|
|
|
if (bin->slabcur != NULL && extent_snad_comp(bin->slabcur, slab) > 0) {
|
2016-05-30 09:34:50 +08:00
|
|
|
/* Switch slabcur. */
|
2017-03-28 07:41:47 +08:00
|
|
|
if (extent_nfree_get(bin->slabcur) > 0) {
|
2016-05-30 09:34:50 +08:00
|
|
|
arena_bin_slabs_nonfull_insert(bin, bin->slabcur);
|
2017-01-16 08:56:30 +08:00
|
|
|
} else {
|
2016-05-30 09:34:50 +08:00
|
|
|
arena_bin_slabs_full_insert(bin, bin->slabcur);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2016-05-30 09:34:50 +08:00
|
|
|
bin->slabcur = slab;
|
2017-01-16 08:56:30 +08:00
|
|
|
if (config_stats) {
|
2016-05-30 09:34:50 +08:00
|
|
|
bin->stats.reslabs++;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
|
|
|
} else {
|
2016-05-30 09:34:50 +08:00
|
|
|
arena_bin_slabs_nonfull_insert(bin, slab);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
Fix numerous arena bugs.
In arena_ralloc_large_grow(), update the map element for the end of the
newly grown run, rather than the interior map element that was the
beginning of the appended run. This is a long-standing bug, and it had
the potential to cause massive corruption, but triggering it required
roughly the following sequence of events:
1) Large in-place growing realloc(), with left-over space in the run
that followed the large object.
2) Allocation of the remainder run left over from (1).
3) Deallocation of the remainder run *before* deallocation of the
large run, with unfortunate interior map state left over from
previous run allocation/deallocation activity, such that one or
more pages of allocated memory would be treated as part of the
remainder run during run coalescing.
In summary, this was a bad bug, but it was difficult to trigger.
In arena_bin_malloc_hard(), if another thread wins the race to allocate
a bin run, dispose of the spare run via arena_bin_lower_run() rather
than arena_run_dalloc(), since the run has already been prepared for use
as a bin run. This bug has existed since March 14, 2010:
e00572b384c81bd2aba57fac32f7077a34388915
mmap()/munmap() without arena->lock or bin->lock.
Fix bugs in arena_dalloc_bin_run(), arena_trim_head(),
arena_trim_tail(), and arena_ralloc_large_grow() that could cause the
CHUNK_MAP_UNZEROED map bit to become corrupted. These are all
long-standing bugs, but the chances of them actually causing problems
was much lower before the CHUNK_MAP_ZEROED --> CHUNK_MAP_UNZEROED
conversion.
Fix a large run statistics regression in arena_ralloc_large_grow() that
was introduced on September 17, 2010:
8e3c3c61b5bb676a705450708e7e79698cdc9e0c
Add {,r,s,d}allocm().
Add debug code to validate that supposedly pre-zeroed memory really is.
2010-10-18 08:51:37 +08:00
|
|
|
}
|
|
|
|
|
2014-10-10 08:54:06 +08:00
|
|
|
static void
|
2016-05-30 09:34:50 +08:00
|
|
|
arena_dalloc_bin_locked_impl(tsdn_t *tsdn, arena_t *arena, extent_t *slab,
|
2017-01-16 08:56:30 +08:00
|
|
|
void *ptr, bool junked) {
|
2016-05-30 09:34:50 +08:00
|
|
|
arena_slab_data_t *slab_data = extent_slab_data_get(slab);
|
2017-03-14 08:48:26 +08:00
|
|
|
szind_t binind = extent_szind_get(slab);
|
2016-05-30 09:34:50 +08:00
|
|
|
arena_bin_t *bin = &arena->bins[binind];
|
|
|
|
const arena_bin_info_t *bin_info = &arena_bin_info[binind];
|
Fix numerous arena bugs.
In arena_ralloc_large_grow(), update the map element for the end of the
newly grown run, rather than the interior map element that was the
beginning of the appended run. This is a long-standing bug, and it had
the potential to cause massive corruption, but triggering it required
roughly the following sequence of events:
1) Large in-place growing realloc(), with left-over space in the run
that followed the large object.
2) Allocation of the remainder run left over from (1).
3) Deallocation of the remainder run *before* deallocation of the
large run, with unfortunate interior map state left over from
previous run allocation/deallocation activity, such that one or
more pages of allocated memory would be treated as part of the
remainder run during run coalescing.
In summary, this was a bad bug, but it was difficult to trigger.
In arena_bin_malloc_hard(), if another thread wins the race to allocate
a bin run, dispose of the spare run via arena_bin_lower_run() rather
than arena_run_dalloc(), since the run has already been prepared for use
as a bin run. This bug has existed since March 14, 2010:
e00572b384c81bd2aba57fac32f7077a34388915
mmap()/munmap() without arena->lock or bin->lock.
Fix bugs in arena_dalloc_bin_run(), arena_trim_head(),
arena_trim_tail(), and arena_ralloc_large_grow() that could cause the
CHUNK_MAP_UNZEROED map bit to become corrupted. These are all
long-standing bugs, but the chances of them actually causing problems
was much lower before the CHUNK_MAP_ZEROED --> CHUNK_MAP_UNZEROED
conversion.
Fix a large run statistics regression in arena_ralloc_large_grow() that
was introduced on September 17, 2010:
8e3c3c61b5bb676a705450708e7e79698cdc9e0c
Add {,r,s,d}allocm().
Add debug code to validate that supposedly pre-zeroed memory really is.
2010-10-18 08:51:37 +08:00
|
|
|
|
2017-01-16 08:56:30 +08:00
|
|
|
if (!junked && config_fill && unlikely(opt_junk_free)) {
|
2012-04-06 15:35:09 +08:00
|
|
|
arena_dalloc_junk_small(ptr, bin_info);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
Fix numerous arena bugs.
In arena_ralloc_large_grow(), update the map element for the end of the
newly grown run, rather than the interior map element that was the
beginning of the appended run. This is a long-standing bug, and it had
the potential to cause massive corruption, but triggering it required
roughly the following sequence of events:
1) Large in-place growing realloc(), with left-over space in the run
that followed the large object.
2) Allocation of the remainder run left over from (1).
3) Deallocation of the remainder run *before* deallocation of the
large run, with unfortunate interior map state left over from
previous run allocation/deallocation activity, such that one or
more pages of allocated memory would be treated as part of the
remainder run during run coalescing.
In summary, this was a bad bug, but it was difficult to trigger.
In arena_bin_malloc_hard(), if another thread wins the race to allocate
a bin run, dispose of the spare run via arena_bin_lower_run() rather
than arena_run_dalloc(), since the run has already been prepared for use
as a bin run. This bug has existed since March 14, 2010:
e00572b384c81bd2aba57fac32f7077a34388915
mmap()/munmap() without arena->lock or bin->lock.
Fix bugs in arena_dalloc_bin_run(), arena_trim_head(),
arena_trim_tail(), and arena_ralloc_large_grow() that could cause the
CHUNK_MAP_UNZEROED map bit to become corrupted. These are all
long-standing bugs, but the chances of them actually causing problems
was much lower before the CHUNK_MAP_ZEROED --> CHUNK_MAP_UNZEROED
conversion.
Fix a large run statistics regression in arena_ralloc_large_grow() that
was introduced on September 17, 2010:
8e3c3c61b5bb676a705450708e7e79698cdc9e0c
Add {,r,s,d}allocm().
Add debug code to validate that supposedly pre-zeroed memory really is.
2010-10-18 08:51:37 +08:00
|
|
|
|
2016-05-30 09:34:50 +08:00
|
|
|
arena_slab_reg_dalloc(tsdn, slab, slab_data, ptr);
|
2017-03-28 07:41:47 +08:00
|
|
|
unsigned nfree = extent_nfree_get(slab);
|
|
|
|
if (nfree == bin_info->nregs) {
|
2016-05-30 09:34:50 +08:00
|
|
|
arena_dissociate_bin_slab(slab, bin);
|
|
|
|
arena_dalloc_bin_slab(tsdn, arena, slab, bin);
|
2017-03-28 07:41:47 +08:00
|
|
|
} else if (nfree == 1 && slab != bin->slabcur) {
|
2017-01-30 13:57:14 +08:00
|
|
|
arena_bin_slabs_full_remove(bin, slab);
|
2016-05-30 09:34:50 +08:00
|
|
|
arena_bin_lower_slab(tsdn, arena, slab, bin);
|
|
|
|
}
|
2010-01-17 01:53:50 +08:00
|
|
|
|
2012-02-11 12:22:09 +08:00
|
|
|
if (config_stats) {
|
|
|
|
bin->stats.ndalloc++;
|
2014-10-13 13:53:59 +08:00
|
|
|
bin->stats.curregs--;
|
2012-02-11 12:22:09 +08:00
|
|
|
}
|
2010-01-17 01:53:50 +08:00
|
|
|
}
|
|
|
|
|
2014-10-10 08:54:06 +08:00
|
|
|
void
|
2016-05-30 09:34:50 +08:00
|
|
|
arena_dalloc_bin_junked_locked(tsdn_t *tsdn, arena_t *arena, extent_t *extent,
|
2017-01-16 08:56:30 +08:00
|
|
|
void *ptr) {
|
2016-05-30 09:34:50 +08:00
|
|
|
arena_dalloc_bin_locked_impl(tsdn, arena, extent, ptr, true);
|
2014-10-10 08:54:06 +08:00
|
|
|
}
|
|
|
|
|
2016-03-24 11:29:33 +08:00
|
|
|
static void
|
2017-01-16 08:56:30 +08:00
|
|
|
arena_dalloc_bin(tsdn_t *tsdn, arena_t *arena, extent_t *extent, void *ptr) {
|
2017-03-14 08:48:26 +08:00
|
|
|
szind_t binind = extent_szind_get(extent);
|
|
|
|
arena_bin_t *bin = &arena->bins[binind];
|
2012-05-02 15:30:36 +08:00
|
|
|
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_lock(tsdn, &bin->lock);
|
2016-05-30 09:34:50 +08:00
|
|
|
arena_dalloc_bin_locked_impl(tsdn, arena, extent, ptr, false);
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_unlock(tsdn, &bin->lock);
|
2012-05-02 15:30:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-03-21 02:00:07 +08:00
|
|
|
arena_dalloc_small(tsdn_t *tsdn, void *ptr) {
|
|
|
|
extent_t *extent = iealloc(tsdn, ptr);
|
|
|
|
arena_t *arena = extent_arena_get(extent);
|
|
|
|
|
2016-05-30 09:34:50 +08:00
|
|
|
arena_dalloc_bin(tsdn, arena, extent, ptr);
|
2016-05-11 13:21:10 +08:00
|
|
|
arena_decay_tick(tsdn, arena);
|
2012-05-02 15:30:36 +08:00
|
|
|
}
|
2010-01-17 01:53:50 +08:00
|
|
|
|
2014-01-13 07:05:44 +08:00
|
|
|
bool
|
2017-03-21 02:00:07 +08:00
|
|
|
arena_ralloc_no_move(tsdn_t *tsdn, void *ptr, size_t oldsize, size_t size,
|
|
|
|
size_t extra, bool zero) {
|
2016-02-26 07:29:49 +08:00
|
|
|
/* Calls with non-zero extra had to clamp extra. */
|
2016-06-01 05:50:21 +08:00
|
|
|
assert(extra == 0 || size + extra <= LARGE_MAXCLASS);
|
2016-02-26 07:29:49 +08:00
|
|
|
|
2017-01-16 08:56:30 +08:00
|
|
|
if (unlikely(size > LARGE_MAXCLASS)) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return true;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2016-02-26 07:29:49 +08:00
|
|
|
|
2017-03-21 02:00:07 +08:00
|
|
|
extent_t *extent = iealloc(tsdn, ptr);
|
|
|
|
size_t usize_min = s2u(size);
|
|
|
|
size_t usize_max = s2u(size + extra);
|
2016-05-28 15:17:28 +08:00
|
|
|
if (likely(oldsize <= SMALL_MAXCLASS && usize_min <= SMALL_MAXCLASS)) {
|
2015-02-13 06:06:37 +08:00
|
|
|
/*
|
|
|
|
* Avoid moving the allocation if the size class can be left the
|
|
|
|
* same.
|
|
|
|
*/
|
2016-05-28 15:17:28 +08:00
|
|
|
assert(arena_bin_info[size2index(oldsize)].reg_size ==
|
|
|
|
oldsize);
|
|
|
|
if ((usize_max > SMALL_MAXCLASS || size2index(usize_max) !=
|
|
|
|
size2index(oldsize)) && (size > oldsize || usize_max <
|
2017-01-16 08:56:30 +08:00
|
|
|
oldsize)) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return true;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2010-01-17 01:53:50 +08:00
|
|
|
|
2016-03-24 11:29:33 +08:00
|
|
|
arena_decay_tick(tsdn, extent_arena_get(extent));
|
2017-01-20 10:15:45 +08:00
|
|
|
return false;
|
2016-05-28 15:17:28 +08:00
|
|
|
} else if (oldsize >= LARGE_MINCLASS && usize_max >= LARGE_MINCLASS) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return large_ralloc_no_move(tsdn, extent, usize_min, usize_max,
|
|
|
|
zero);
|
2015-09-12 07:18:53 +08:00
|
|
|
}
|
2016-05-19 12:02:46 +08:00
|
|
|
|
2017-01-20 10:15:45 +08:00
|
|
|
return true;
|
2015-09-12 07:18:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void *
|
2016-05-11 13:21:10 +08:00
|
|
|
arena_ralloc_move_helper(tsdn_t *tsdn, arena_t *arena, size_t usize,
|
2017-01-16 08:56:30 +08:00
|
|
|
size_t alignment, bool zero, tcache_t *tcache) {
|
|
|
|
if (alignment == 0) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return arena_malloc(tsdn, arena, usize, size2index(usize),
|
|
|
|
zero, tcache, true);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2015-09-12 07:18:53 +08:00
|
|
|
usize = sa2u(usize, alignment);
|
2017-01-16 08:56:30 +08:00
|
|
|
if (unlikely(usize == 0 || usize > LARGE_MAXCLASS)) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return NULL;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2017-01-20 10:15:45 +08:00
|
|
|
return ipalloct(tsdn, usize, alignment, zero, tcache, arena);
|
Add {,r,s,d}allocm().
Add allocm(), rallocm(), sallocm(), and dallocm(), which are a
functional superset of malloc(), calloc(), posix_memalign(),
malloc_usable_size(), and free().
2010-09-18 06:46:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
2017-03-21 02:00:07 +08:00
|
|
|
arena_ralloc(tsdn_t *tsdn, arena_t *arena, void *ptr, size_t oldsize,
|
|
|
|
size_t size, size_t alignment, bool zero, tcache_t *tcache) {
|
|
|
|
size_t usize = s2u(size);
|
2017-01-16 08:56:30 +08:00
|
|
|
if (unlikely(usize == 0 || size > LARGE_MAXCLASS)) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return NULL;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
Add {,r,s,d}allocm().
Add allocm(), rallocm(), sallocm(), and dallocm(), which are a
functional superset of malloc(), calloc(), posix_memalign(),
malloc_usable_size(), and free().
2010-09-18 06:46:18 +08:00
|
|
|
|
2016-05-28 15:17:28 +08:00
|
|
|
if (likely(usize <= SMALL_MAXCLASS)) {
|
2015-02-13 06:06:37 +08:00
|
|
|
/* Try to avoid moving the allocation. */
|
2017-03-21 02:00:07 +08:00
|
|
|
if (!arena_ralloc_no_move(tsdn, ptr, oldsize, usize, 0, zero)) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return ptr;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2016-05-19 12:02:46 +08:00
|
|
|
}
|
2010-01-17 01:53:50 +08:00
|
|
|
|
2016-05-28 15:17:28 +08:00
|
|
|
if (oldsize >= LARGE_MINCLASS && usize >= LARGE_MINCLASS) {
|
2017-03-21 02:00:07 +08:00
|
|
|
return large_ralloc(tsdn, arena, iealloc(tsdn, ptr), usize,
|
|
|
|
alignment, zero, tcache);
|
2016-05-19 12:02:46 +08:00
|
|
|
}
|
Add {,r,s,d}allocm().
Add allocm(), rallocm(), sallocm(), and dallocm(), which are a
functional superset of malloc(), calloc(), posix_memalign(),
malloc_usable_size(), and free().
2010-09-18 06:46:18 +08:00
|
|
|
|
2016-05-19 12:02:46 +08:00
|
|
|
/*
|
|
|
|
* size and oldsize are different enough that we need to move the
|
|
|
|
* object. In that case, fall back to allocating new space and copying.
|
|
|
|
*/
|
2017-03-21 02:00:07 +08:00
|
|
|
void *ret = arena_ralloc_move_helper(tsdn, arena, usize, alignment,
|
|
|
|
zero, tcache);
|
2017-01-16 08:56:30 +08:00
|
|
|
if (ret == NULL) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return NULL;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2015-02-13 06:06:37 +08:00
|
|
|
|
2016-05-19 12:02:46 +08:00
|
|
|
/*
|
|
|
|
* Junk/zero-filling were already done by
|
|
|
|
* ipalloc()/arena_malloc().
|
|
|
|
*/
|
|
|
|
|
2017-03-21 02:00:07 +08:00
|
|
|
size_t copysize = (usize < oldsize) ? usize : oldsize;
|
2016-05-19 12:02:46 +08:00
|
|
|
memcpy(ret, ptr, copysize);
|
2017-04-12 05:56:43 +08:00
|
|
|
isdalloct(tsdn, ptr, oldsize, tcache, NULL, true);
|
2017-01-20 10:15:45 +08:00
|
|
|
return ret;
|
2010-01-17 01:53:50 +08:00
|
|
|
}
|
|
|
|
|
2012-10-12 04:53:15 +08:00
|
|
|
dss_prec_t
|
2017-02-13 08:34:36 +08:00
|
|
|
arena_dss_prec_get(arena_t *arena) {
|
2017-04-05 08:22:24 +08:00
|
|
|
return (dss_prec_t)atomic_load_u(&arena->dss_prec, ATOMIC_ACQUIRE);
|
2012-10-12 04:53:15 +08:00
|
|
|
}
|
|
|
|
|
2014-04-16 03:09:48 +08:00
|
|
|
bool
|
2017-02-13 08:34:36 +08:00
|
|
|
arena_dss_prec_set(arena_t *arena, dss_prec_t dss_prec) {
|
2017-01-16 08:56:30 +08:00
|
|
|
if (!have_dss) {
|
2014-04-16 03:09:48 +08:00
|
|
|
return (dss_prec != dss_prec_disabled);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2017-04-05 08:22:24 +08:00
|
|
|
atomic_store_u(&arena->dss_prec, (unsigned)dss_prec, ATOMIC_RELEASE);
|
2017-01-20 10:15:45 +08:00
|
|
|
return false;
|
2012-10-12 04:53:15 +08:00
|
|
|
}
|
|
|
|
|
2016-02-20 12:09:31 +08:00
|
|
|
ssize_t
|
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
|
|
|
arena_dirty_decay_time_default_get(void) {
|
2017-04-05 08:22:24 +08:00
|
|
|
return atomic_load_zd(&dirty_decay_time_default, ATOMIC_RELAXED);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
arena_dirty_decay_time_default_set(ssize_t decay_time) {
|
|
|
|
if (!arena_decay_time_valid(decay_time)) {
|
|
|
|
return true;
|
|
|
|
}
|
2017-04-05 08:22:24 +08:00
|
|
|
atomic_store_zd(&dirty_decay_time_default, decay_time, ATOMIC_RELAXED);
|
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
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t
|
|
|
|
arena_muzzy_decay_time_default_get(void) {
|
2017-04-05 08:22:24 +08:00
|
|
|
return atomic_load_zd(&muzzy_decay_time_default, ATOMIC_RELAXED);
|
2016-02-20 12:09:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
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
|
|
|
arena_muzzy_decay_time_default_set(ssize_t decay_time) {
|
2017-01-16 08:56:30 +08:00
|
|
|
if (!arena_decay_time_valid(decay_time)) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return true;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2017-04-05 08:22:24 +08:00
|
|
|
atomic_store_zd(&muzzy_decay_time_default, decay_time, ATOMIC_RELAXED);
|
2017-01-20 10:15:45 +08:00
|
|
|
return false;
|
2016-02-20 12:09:31 +08:00
|
|
|
}
|
|
|
|
|
2016-02-25 15:58:10 +08:00
|
|
|
unsigned
|
2017-01-16 08:56:30 +08:00
|
|
|
arena_nthreads_get(arena_t *arena, bool internal) {
|
2017-04-05 08:22:24 +08:00
|
|
|
return atomic_load_u(&arena->nthreads[internal], ATOMIC_RELAXED);
|
2016-02-25 15:58:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-01-16 08:56:30 +08:00
|
|
|
arena_nthreads_inc(arena_t *arena, bool internal) {
|
2017-04-05 08:22:24 +08:00
|
|
|
atomic_fetch_add_u(&arena->nthreads[internal], 1, ATOMIC_RELAXED);
|
2016-02-25 15:58:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-01-16 08:56:30 +08:00
|
|
|
arena_nthreads_dec(arena_t *arena, bool internal) {
|
2017-04-05 08:22:24 +08:00
|
|
|
atomic_fetch_sub_u(&arena->nthreads[internal], 1, ATOMIC_RELAXED);
|
2016-02-25 15:58:10 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 05:07:53 +08:00
|
|
|
size_t
|
2017-01-16 08:56:30 +08:00
|
|
|
arena_extent_sn_next(arena_t *arena) {
|
2017-04-05 08:22:24 +08:00
|
|
|
return atomic_fetch_add_zu(&arena->extent_sn_next, 1, ATOMIC_RELAXED);
|
2016-11-16 05:07:53 +08:00
|
|
|
}
|
|
|
|
|
Refactor/fix arenas manipulation.
Abstract arenas access to use arena_get() (or a0get() where appropriate)
rather than directly reading e.g. arenas[ind]. Prior to the addition of
the arenas.extend mallctl, the worst possible outcome of directly
accessing arenas was a stale read, but arenas.extend may allocate and
assign a new array to arenas.
Add a tsd-based arenas_cache, which amortizes arenas reads. This
introduces some subtle bootstrapping issues, with tsd_boot() now being
split into tsd_boot[01]() to support tsd wrapper allocation
bootstrapping, as well as an arenas_cache_bypass tsd variable which
dynamically terminates allocation of arenas_cache itself.
Promote a0malloc(), a0calloc(), and a0free() to be generally useful for
internal allocation, and use them in several places (more may be
appropriate).
Abstract arena->nthreads management and fix a missing decrement during
thread destruction (recent tsd refactoring left arenas_cleanup()
unused).
Change arena_choose() to propagate OOM, and handle OOM in all callers.
This is important for providing consistent allocation behavior when the
MALLOCX_ARENA() flag is being used. Prior to this fix, it was possible
for an OOM to result in allocation silently allocating from a different
arena than the one specified.
2014-10-08 14:14:57 +08:00
|
|
|
arena_t *
|
2017-01-16 08:56:30 +08:00
|
|
|
arena_new(tsdn_t *tsdn, unsigned ind, extent_hooks_t *extent_hooks) {
|
Refactor/fix arenas manipulation.
Abstract arenas access to use arena_get() (or a0get() where appropriate)
rather than directly reading e.g. arenas[ind]. Prior to the addition of
the arenas.extend mallctl, the worst possible outcome of directly
accessing arenas was a stale read, but arenas.extend may allocate and
assign a new array to arenas.
Add a tsd-based arenas_cache, which amortizes arenas reads. This
introduces some subtle bootstrapping issues, with tsd_boot() now being
split into tsd_boot[01]() to support tsd wrapper allocation
bootstrapping, as well as an arenas_cache_bypass tsd variable which
dynamically terminates allocation of arenas_cache itself.
Promote a0malloc(), a0calloc(), and a0free() to be generally useful for
internal allocation, and use them in several places (more may be
appropriate).
Abstract arena->nthreads management and fix a missing decrement during
thread destruction (recent tsd refactoring left arenas_cleanup()
unused).
Change arena_choose() to propagate OOM, and handle OOM in all callers.
This is important for providing consistent allocation behavior when the
MALLOCX_ARENA() flag is being used. Prior to this fix, it was possible
for an OOM to result in allocation silently allocating from a different
arena than the one specified.
2014-10-08 14:14:57 +08:00
|
|
|
arena_t *arena;
|
2016-12-23 06:39:10 +08:00
|
|
|
base_t *base;
|
2010-01-17 01:53:50 +08:00
|
|
|
unsigned i;
|
|
|
|
|
2017-01-16 08:56:30 +08:00
|
|
|
if (ind == 0) {
|
2016-12-23 06:39:10 +08:00
|
|
|
base = b0get();
|
2017-01-16 08:56:30 +08:00
|
|
|
} else {
|
2016-12-23 06:39:10 +08:00
|
|
|
base = base_new(tsdn, ind, extent_hooks);
|
2017-01-16 08:56:30 +08:00
|
|
|
if (base == NULL) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return NULL;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2016-12-23 06:39:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
arena = (arena_t *)base_alloc(tsdn, base, sizeof(arena_t), CACHELINE);
|
2017-01-16 08:56:30 +08:00
|
|
|
if (arena == NULL) {
|
2016-12-23 06:39:10 +08:00
|
|
|
goto label_error;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
Refactor/fix arenas manipulation.
Abstract arenas access to use arena_get() (or a0get() where appropriate)
rather than directly reading e.g. arenas[ind]. Prior to the addition of
the arenas.extend mallctl, the worst possible outcome of directly
accessing arenas was a stale read, but arenas.extend may allocate and
assign a new array to arenas.
Add a tsd-based arenas_cache, which amortizes arenas reads. This
introduces some subtle bootstrapping issues, with tsd_boot() now being
split into tsd_boot[01]() to support tsd wrapper allocation
bootstrapping, as well as an arenas_cache_bypass tsd variable which
dynamically terminates allocation of arenas_cache itself.
Promote a0malloc(), a0calloc(), and a0free() to be generally useful for
internal allocation, and use them in several places (more may be
appropriate).
Abstract arena->nthreads management and fix a missing decrement during
thread destruction (recent tsd refactoring left arenas_cleanup()
unused).
Change arena_choose() to propagate OOM, and handle OOM in all callers.
This is important for providing consistent allocation behavior when the
MALLOCX_ARENA() flag is being used. Prior to this fix, it was possible
for an OOM to result in allocation silently allocating from a different
arena than the one specified.
2014-10-08 14:14:57 +08:00
|
|
|
|
2017-04-05 08:22:24 +08:00
|
|
|
atomic_store_u(&arena->nthreads[0], 0, ATOMIC_RELAXED);
|
|
|
|
atomic_store_u(&arena->nthreads[1], 0, ATOMIC_RELAXED);
|
Implement per-CPU arena.
The new feature, opt.percpu_arena, determines thread-arena association
dynamically based CPU id. Three modes are supported: "percpu", "phycpu"
and disabled.
"percpu" uses the current core id (with help from sched_getcpu())
directly as the arena index, while "phycpu" will assign threads on the
same physical CPU to the same arena. In other words, "percpu" means # of
arenas == # of CPUs, while "phycpu" has # of arenas == 1/2 * (# of
CPUs). Note that no runtime check on whether hyper threading is enabled
is added yet.
When enabled, threads will be migrated between arenas when a CPU change
is detected. In the current design, to reduce overhead from reading CPU
id, each arena tracks the thread accessed most recently. When a new
thread comes in, we will read CPU id and update arena if necessary.
2017-02-03 09:02:05 +08:00
|
|
|
arena->last_thd = NULL;
|
2010-01-17 01:53:50 +08:00
|
|
|
|
2017-02-13 09:43:33 +08:00
|
|
|
if (config_stats) {
|
|
|
|
if (arena_stats_init(tsdn, &arena->stats)) {
|
|
|
|
goto label_error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-16 08:56:30 +08:00
|
|
|
if (config_stats && config_tcache) {
|
2016-05-28 15:17:28 +08:00
|
|
|
ql_new(&arena->tcache_ql);
|
2017-02-13 10:50:53 +08:00
|
|
|
if (malloc_mutex_init(&arena->tcache_ql_mtx, "tcache_ql",
|
|
|
|
WITNESS_RANK_TCACHE_QL)) {
|
|
|
|
goto label_error;
|
|
|
|
}
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2010-01-17 01:53:50 +08:00
|
|
|
|
2017-01-16 08:56:30 +08:00
|
|
|
if (config_prof) {
|
2017-02-13 09:03:46 +08:00
|
|
|
if (prof_accum_init(tsdn, &arena->prof_accum)) {
|
|
|
|
goto label_error;
|
|
|
|
}
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2010-02-12 05:19:21 +08:00
|
|
|
|
2015-05-05 00:58:36 +08:00
|
|
|
if (config_cache_oblivious) {
|
|
|
|
/*
|
|
|
|
* A nondeterministic seed based on the address of arena reduces
|
|
|
|
* the likelihood of lockstep non-uniform cache index
|
|
|
|
* utilization among identical concurrent processes, but at the
|
|
|
|
* cost of test repeatability. For debug builds, instead use a
|
|
|
|
* deterministic seed.
|
|
|
|
*/
|
2017-04-04 09:18:40 +08:00
|
|
|
atomic_store_zu(&arena->offset_state, config_debug ? ind :
|
|
|
|
(size_t)(uintptr_t)arena, ATOMIC_RELAXED);
|
2015-05-05 00:58:36 +08:00
|
|
|
}
|
|
|
|
|
2017-04-05 08:22:24 +08:00
|
|
|
atomic_store_zu(&arena->extent_sn_next, 0, ATOMIC_RELAXED);
|
2016-11-16 05:07:53 +08:00
|
|
|
|
2017-04-05 08:22:24 +08:00
|
|
|
atomic_store_u(&arena->dss_prec, (unsigned)extent_dss_prec_get(),
|
|
|
|
ATOMIC_RELAXED);
|
2012-10-12 04:53:15 +08:00
|
|
|
|
2017-04-05 08:22:24 +08:00
|
|
|
atomic_store_zu(&arena->nactive, 0, ATOMIC_RELAXED);
|
2010-01-17 01:53:50 +08:00
|
|
|
|
2017-01-30 13:57:14 +08:00
|
|
|
extent_list_init(&arena->large);
|
2016-06-01 05:50:21 +08:00
|
|
|
if (malloc_mutex_init(&arena->large_mtx, "arena_large",
|
2017-01-16 08:56:30 +08:00
|
|
|
WITNESS_RANK_ARENA_LARGE)) {
|
2016-12-23 06:39:10 +08:00
|
|
|
goto label_error;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2015-02-16 10:04:46 +08:00
|
|
|
|
2017-03-03 10:04:35 +08:00
|
|
|
/*
|
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
|
|
|
* Delay coalescing for dirty extents despite the disruptive effect on
|
2017-03-03 10:04:35 +08:00
|
|
|
* memory layout for best-fit extent allocation, since cached extents
|
|
|
|
* are likely to be reused soon after deallocation, and the cost of
|
|
|
|
* merging/splitting extents is non-trivial.
|
|
|
|
*/
|
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
|
|
|
if (extents_init(tsdn, &arena->extents_dirty, extent_state_dirty,
|
2017-03-03 10:04:35 +08:00
|
|
|
true)) {
|
2017-01-30 13:57:14 +08:00
|
|
|
goto label_error;
|
2016-05-18 05:58:56 +08:00
|
|
|
}
|
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
|
|
|
/*
|
|
|
|
* Coalesce muzzy extents immediately, because operations on them are in
|
|
|
|
* the critical path much less often than for dirty extents.
|
|
|
|
*/
|
|
|
|
if (extents_init(tsdn, &arena->extents_muzzy, extent_state_muzzy,
|
|
|
|
false)) {
|
|
|
|
goto label_error;
|
|
|
|
}
|
2017-03-03 10:04:35 +08:00
|
|
|
/*
|
|
|
|
* Coalesce retained extents immediately, in part because they will
|
|
|
|
* never be evicted (and therefore there's no opportunity for delayed
|
|
|
|
* coalescing), but also because operations on retained extents are not
|
|
|
|
* in the critical path.
|
|
|
|
*/
|
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
|
|
|
if (extents_init(tsdn, &arena->extents_retained, extent_state_retained,
|
|
|
|
false)) {
|
2016-12-23 06:39:10 +08:00
|
|
|
goto label_error;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2016-09-23 02:57:28 +08:00
|
|
|
|
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
|
|
|
if (arena_decay_init(&arena->decay_dirty, &arena->extents_dirty,
|
|
|
|
arena_dirty_decay_time_default_get(), &arena->stats.decay_dirty)) {
|
|
|
|
goto label_error;
|
|
|
|
}
|
|
|
|
if (arena_decay_init(&arena->decay_muzzy, &arena->extents_muzzy,
|
|
|
|
arena_muzzy_decay_time_default_get(), &arena->stats.decay_muzzy)) {
|
2017-03-08 01:22:33 +08:00
|
|
|
goto label_error;
|
|
|
|
}
|
|
|
|
|
2017-01-16 08:56:30 +08:00
|
|
|
if (!config_munmap) {
|
2017-04-05 08:22:24 +08:00
|
|
|
atomic_store_u(&arena->extent_grow_next, psz2ind(HUGEPAGE),
|
|
|
|
ATOMIC_RELAXED);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2016-11-22 15:23:03 +08:00
|
|
|
|
2017-04-17 13:31:16 +08:00
|
|
|
extent_avail_new(&arena->extent_avail);
|
|
|
|
if (malloc_mutex_init(&arena->extent_avail_mtx, "extent_avail",
|
2017-01-30 13:57:14 +08:00
|
|
|
WITNESS_RANK_EXTENT_FREELIST)) {
|
2016-12-23 06:39:10 +08:00
|
|
|
goto label_error;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2015-02-16 10:04:46 +08:00
|
|
|
|
2010-01-17 01:53:50 +08:00
|
|
|
/* Initialize bins. */
|
2012-02-29 08:50:47 +08:00
|
|
|
for (i = 0; i < NBINS; i++) {
|
2016-04-23 05:36:48 +08:00
|
|
|
arena_bin_t *bin = &arena->bins[i];
|
2016-04-14 14:36:15 +08:00
|
|
|
if (malloc_mutex_init(&bin->lock, "arena_bin",
|
2017-01-16 08:56:30 +08:00
|
|
|
WITNESS_RANK_ARENA_BIN)) {
|
2016-12-23 06:39:10 +08:00
|
|
|
goto label_error;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2016-05-30 09:34:50 +08:00
|
|
|
bin->slabcur = NULL;
|
|
|
|
extent_heap_new(&bin->slabs_nonfull);
|
2017-01-30 13:57:14 +08:00
|
|
|
extent_list_init(&bin->slabs_full);
|
2017-01-16 08:56:30 +08:00
|
|
|
if (config_stats) {
|
2012-02-11 12:22:09 +08:00
|
|
|
memset(&bin->stats, 0, sizeof(malloc_bin_stats_t));
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2010-01-17 01:53:50 +08:00
|
|
|
}
|
|
|
|
|
2016-12-23 06:39:10 +08:00
|
|
|
arena->base = base;
|
|
|
|
|
2017-04-01 10:59:45 +08:00
|
|
|
/* We don't support reetrancy for arena 0 bootstrapping. */
|
|
|
|
if (ind != 0 && hooks_arena_new_hook) {
|
|
|
|
/*
|
|
|
|
* If we're here, then arena 0 already exists, so bootstrapping
|
|
|
|
* is done enough that we should have tsd.
|
|
|
|
*/
|
2017-04-13 07:16:27 +08:00
|
|
|
pre_reentrancy(tsdn_tsd(tsdn));
|
2017-04-01 10:59:45 +08:00
|
|
|
hooks_arena_new_hook();
|
2017-04-13 07:16:27 +08:00
|
|
|
post_reentrancy(tsdn_tsd(tsdn));
|
2017-04-01 10:59:45 +08:00
|
|
|
}
|
|
|
|
|
2017-01-20 10:15:45 +08:00
|
|
|
return arena;
|
2016-12-23 06:39:10 +08:00
|
|
|
label_error:
|
2017-01-16 08:56:30 +08:00
|
|
|
if (ind != 0) {
|
2016-12-23 06:39:10 +08:00
|
|
|
base_delete(base);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2017-01-20 10:15:45 +08:00
|
|
|
return NULL;
|
2010-01-17 01:53:50 +08:00
|
|
|
}
|
|
|
|
|
2016-04-09 05:16:19 +08:00
|
|
|
void
|
2017-01-16 08:56:30 +08:00
|
|
|
arena_boot(void) {
|
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
|
|
|
arena_dirty_decay_time_default_set(opt_dirty_decay_time);
|
|
|
|
arena_muzzy_decay_time_default_set(opt_muzzy_decay_time);
|
2010-01-17 01:53:50 +08:00
|
|
|
}
|
2012-03-14 07:31:41 +08:00
|
|
|
|
|
|
|
void
|
2017-01-16 08:56:30 +08:00
|
|
|
arena_prefork0(tsdn_t *tsdn, arena_t *arena) {
|
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
|
|
|
malloc_mutex_prefork(tsdn, &arena->decay_dirty.mtx);
|
|
|
|
malloc_mutex_prefork(tsdn, &arena->decay_muzzy.mtx);
|
2017-03-09 05:00:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
arena_prefork1(tsdn_t *tsdn, arena_t *arena) {
|
2017-02-13 10:50:53 +08:00
|
|
|
if (config_stats && config_tcache) {
|
|
|
|
malloc_mutex_prefork(tsdn, &arena->tcache_ql_mtx);
|
|
|
|
}
|
2016-04-26 14:14:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-03-09 05:00:42 +08:00
|
|
|
arena_prefork2(tsdn_t *tsdn, arena_t *arena) {
|
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
|
|
|
extents_prefork(tsdn, &arena->extents_dirty);
|
|
|
|
extents_prefork(tsdn, &arena->extents_muzzy);
|
2017-01-30 13:57:14 +08:00
|
|
|
extents_prefork(tsdn, &arena->extents_retained);
|
2016-04-26 14:14:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-03-09 05:00:42 +08:00
|
|
|
arena_prefork3(tsdn_t *tsdn, arena_t *arena) {
|
2017-04-17 13:31:16 +08:00
|
|
|
malloc_mutex_prefork(tsdn, &arena->extent_avail_mtx);
|
2016-04-26 14:14:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-03-09 05:00:42 +08:00
|
|
|
arena_prefork4(tsdn_t *tsdn, arena_t *arena) {
|
2016-12-23 06:39:10 +08:00
|
|
|
base_prefork(tsdn, arena->base);
|
2017-03-09 05:00:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
arena_prefork5(tsdn_t *tsdn, arena_t *arena) {
|
2017-02-13 09:43:33 +08:00
|
|
|
malloc_mutex_prefork(tsdn, &arena->large_mtx);
|
2017-03-09 05:00:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
arena_prefork6(tsdn_t *tsdn, arena_t *arena) {
|
|
|
|
for (unsigned i = 0; i < NBINS; i++) {
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_prefork(tsdn, &arena->bins[i].lock);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2012-03-14 07:31:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-01-16 08:56:30 +08:00
|
|
|
arena_postfork_parent(tsdn_t *tsdn, arena_t *arena) {
|
2012-03-14 07:31:41 +08:00
|
|
|
unsigned i;
|
|
|
|
|
2017-01-16 08:56:30 +08:00
|
|
|
for (i = 0; i < NBINS; i++) {
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_postfork_parent(tsdn, &arena->bins[i].lock);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2017-02-13 09:43:33 +08:00
|
|
|
malloc_mutex_postfork_parent(tsdn, &arena->large_mtx);
|
2016-12-23 06:39:10 +08:00
|
|
|
base_postfork_parent(tsdn, arena->base);
|
2017-04-17 13:31:16 +08:00
|
|
|
malloc_mutex_postfork_parent(tsdn, &arena->extent_avail_mtx);
|
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
|
|
|
extents_postfork_parent(tsdn, &arena->extents_dirty);
|
|
|
|
extents_postfork_parent(tsdn, &arena->extents_muzzy);
|
2017-01-30 13:57:14 +08:00
|
|
|
extents_postfork_parent(tsdn, &arena->extents_retained);
|
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
|
|
|
malloc_mutex_postfork_parent(tsdn, &arena->decay_dirty.mtx);
|
|
|
|
malloc_mutex_postfork_parent(tsdn, &arena->decay_muzzy.mtx);
|
2017-02-13 10:50:53 +08:00
|
|
|
if (config_stats && config_tcache) {
|
|
|
|
malloc_mutex_postfork_parent(tsdn, &arena->tcache_ql_mtx);
|
|
|
|
}
|
2012-03-14 07:31:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-01-16 08:56:30 +08:00
|
|
|
arena_postfork_child(tsdn_t *tsdn, arena_t *arena) {
|
2012-03-14 07:31:41 +08:00
|
|
|
unsigned i;
|
|
|
|
|
2017-01-16 08:56:30 +08:00
|
|
|
for (i = 0; i < NBINS; i++) {
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_postfork_child(tsdn, &arena->bins[i].lock);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2017-02-13 09:43:33 +08:00
|
|
|
malloc_mutex_postfork_child(tsdn, &arena->large_mtx);
|
2016-12-23 06:39:10 +08:00
|
|
|
base_postfork_child(tsdn, arena->base);
|
2017-04-17 13:31:16 +08:00
|
|
|
malloc_mutex_postfork_child(tsdn, &arena->extent_avail_mtx);
|
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
|
|
|
extents_postfork_child(tsdn, &arena->extents_dirty);
|
|
|
|
extents_postfork_child(tsdn, &arena->extents_muzzy);
|
2017-01-30 13:57:14 +08:00
|
|
|
extents_postfork_child(tsdn, &arena->extents_retained);
|
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
|
|
|
malloc_mutex_postfork_child(tsdn, &arena->decay_dirty.mtx);
|
|
|
|
malloc_mutex_postfork_child(tsdn, &arena->decay_muzzy.mtx);
|
2017-02-13 10:50:53 +08:00
|
|
|
if (config_stats && config_tcache) {
|
|
|
|
malloc_mutex_postfork_child(tsdn, &arena->tcache_ql_mtx);
|
|
|
|
}
|
2012-03-14 07:31:41 +08:00
|
|
|
}
|