mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-08-06 10:26:18 +03:00
Extent -> Ehooks: Move alloc hook.
This commit is contained in:
parent
703fbc0ff5
commit
dc8b4e6e13
4 changed files with 105 additions and 99 deletions
69
src/ehooks.c
69
src/ehooks.c
|
|
@ -2,7 +2,76 @@
|
|||
#include "jemalloc/internal/jemalloc_internal_includes.h"
|
||||
|
||||
#include "jemalloc/internal/ehooks.h"
|
||||
#include "jemalloc/internal/extent_mmap.h"
|
||||
|
||||
void ehooks_init(ehooks_t *ehooks, extent_hooks_t *extent_hooks) {
|
||||
ehooks_set_extent_hooks_ptr(ehooks, extent_hooks);
|
||||
}
|
||||
|
||||
/*
|
||||
* If the caller specifies (!*zero), it is still possible to receive zeroed
|
||||
* memory, in which case *zero is toggled to true. arena_extent_alloc() takes
|
||||
* advantage of this to avoid demanding zeroed extents, but taking advantage of
|
||||
* them if they are returned.
|
||||
*/
|
||||
static void *
|
||||
extent_alloc_core(tsdn_t *tsdn, arena_t *arena, void *new_addr, size_t size,
|
||||
size_t alignment, bool *zero, bool *commit, dss_prec_t dss_prec) {
|
||||
void *ret;
|
||||
|
||||
assert(size != 0);
|
||||
assert(alignment != 0);
|
||||
|
||||
/* "primary" dss. */
|
||||
if (have_dss && dss_prec == dss_prec_primary && (ret =
|
||||
extent_alloc_dss(tsdn, arena, new_addr, size, alignment, zero,
|
||||
commit)) != NULL) {
|
||||
return ret;
|
||||
}
|
||||
/* mmap. */
|
||||
if ((ret = extent_alloc_mmap(new_addr, size, alignment, zero, commit))
|
||||
!= NULL) {
|
||||
return ret;
|
||||
}
|
||||
/* "secondary" dss. */
|
||||
if (have_dss && dss_prec == dss_prec_secondary && (ret =
|
||||
extent_alloc_dss(tsdn, arena, new_addr, size, alignment, zero,
|
||||
commit)) != NULL) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* All strategies for allocation failed. */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *
|
||||
ehooks_default_alloc_impl(tsdn_t *tsdn, void *new_addr, size_t size,
|
||||
size_t alignment, bool *zero, bool *commit, unsigned arena_ind) {
|
||||
arena_t *arena = arena_get(tsdn, arena_ind, false);
|
||||
void *ret = extent_alloc_core(tsdn, arena, new_addr, size, alignment, zero,
|
||||
commit, (dss_prec_t)atomic_load_u(&arena->dss_prec,
|
||||
ATOMIC_RELAXED));
|
||||
if (have_madvise_huge && ret) {
|
||||
pages_set_thp_state(ret, size);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void *
|
||||
ehooks_default_alloc(extent_hooks_t *extent_hooks, void *new_addr, size_t size,
|
||||
size_t alignment, bool *zero, bool *commit, unsigned arena_ind) {
|
||||
tsdn_t *tsdn;
|
||||
arena_t *arena;
|
||||
|
||||
tsdn = tsdn_fetch();
|
||||
arena = arena_get(tsdn, arena_ind, false);
|
||||
/*
|
||||
* The arena we're allocating on behalf of must have been initialized
|
||||
* already.
|
||||
*/
|
||||
assert(arena != NULL);
|
||||
|
||||
return ehooks_default_alloc_impl(tsdn, new_addr, size,
|
||||
ALIGNMENT_CEILING(alignment, PAGE), zero, commit,
|
||||
arena_ind_get(arena));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue