Extent -> Ehooks: Move over default hooks.
This commit is contained in:
parent
2fe5108263
commit
c8dae890c8
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include "jemalloc/internal/atomic.h"
|
#include "jemalloc/internal/atomic.h"
|
||||||
|
|
||||||
extern const extent_hooks_t extent_hooks_default;
|
extern const extent_hooks_t ehooks_default_extent_hooks;
|
||||||
|
|
||||||
typedef struct ehooks_s ehooks_t;
|
typedef struct ehooks_s ehooks_t;
|
||||||
struct ehooks_s {
|
struct ehooks_s {
|
||||||
@ -11,6 +11,8 @@ struct ehooks_s {
|
|||||||
atomic_p_t ptr;
|
atomic_p_t ptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern const extent_hooks_t ehooks_default_extent_hooks;
|
||||||
|
|
||||||
/* NOT PUBLIC. */
|
/* NOT PUBLIC. */
|
||||||
void *ehooks_default_alloc_impl(tsdn_t *tsdn, void *new_addr, size_t size,
|
void *ehooks_default_alloc_impl(tsdn_t *tsdn, void *new_addr, size_t size,
|
||||||
size_t alignment, bool *zero, bool *commit, unsigned arena_ind);
|
size_t alignment, bool *zero, bool *commit, unsigned arena_ind);
|
||||||
@ -73,7 +75,8 @@ ehooks_get_extent_hooks_ptr(ehooks_t *ehooks) {
|
|||||||
|
|
||||||
static inline bool
|
static inline bool
|
||||||
ehooks_are_default(ehooks_t *ehooks) {
|
ehooks_are_default(ehooks_t *ehooks) {
|
||||||
return ehooks_get_extent_hooks_ptr(ehooks) == &extent_hooks_default;
|
return ehooks_get_extent_hooks_ptr(ehooks) ==
|
||||||
|
&ehooks_default_extent_hooks;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool
|
static inline bool
|
||||||
@ -105,7 +108,7 @@ static inline void *
|
|||||||
ehooks_alloc(tsdn_t *tsdn, ehooks_t *ehooks, void *new_addr, size_t size,
|
ehooks_alloc(tsdn_t *tsdn, ehooks_t *ehooks, void *new_addr, size_t size,
|
||||||
size_t alignment, bool *zero, bool *commit, unsigned arena_ind) {
|
size_t alignment, bool *zero, bool *commit, unsigned arena_ind) {
|
||||||
extent_hooks_t *extent_hooks = ehooks_get_extent_hooks_ptr(ehooks);
|
extent_hooks_t *extent_hooks = ehooks_get_extent_hooks_ptr(ehooks);
|
||||||
if (extent_hooks == &extent_hooks_default) {
|
if (extent_hooks == &ehooks_default_extent_hooks) {
|
||||||
return ehooks_default_alloc_impl(tsdn, new_addr, size,
|
return ehooks_default_alloc_impl(tsdn, new_addr, size,
|
||||||
alignment, zero, commit, arena_ind);
|
alignment, zero, commit, arena_ind);
|
||||||
}
|
}
|
||||||
@ -120,7 +123,7 @@ static inline bool
|
|||||||
ehooks_dalloc(tsdn_t *tsdn, ehooks_t *ehooks, void *addr, size_t size,
|
ehooks_dalloc(tsdn_t *tsdn, ehooks_t *ehooks, void *addr, size_t size,
|
||||||
bool committed, unsigned arena_ind) {
|
bool committed, unsigned arena_ind) {
|
||||||
extent_hooks_t *extent_hooks = ehooks_get_extent_hooks_ptr(ehooks);
|
extent_hooks_t *extent_hooks = ehooks_get_extent_hooks_ptr(ehooks);
|
||||||
if (extent_hooks == &extent_hooks_default) {
|
if (extent_hooks == &ehooks_default_extent_hooks) {
|
||||||
return ehooks_default_dalloc_impl(addr, size);
|
return ehooks_default_dalloc_impl(addr, size);
|
||||||
} else if (extent_hooks->dalloc == NULL) {
|
} else if (extent_hooks->dalloc == NULL) {
|
||||||
return true;
|
return true;
|
||||||
@ -137,7 +140,7 @@ static inline void
|
|||||||
ehooks_destroy(tsdn_t *tsdn, ehooks_t *ehooks, void *addr, size_t size,
|
ehooks_destroy(tsdn_t *tsdn, ehooks_t *ehooks, void *addr, size_t size,
|
||||||
bool committed, unsigned arena_ind) {
|
bool committed, unsigned arena_ind) {
|
||||||
extent_hooks_t *extent_hooks = ehooks_get_extent_hooks_ptr(ehooks);
|
extent_hooks_t *extent_hooks = ehooks_get_extent_hooks_ptr(ehooks);
|
||||||
if (extent_hooks == &extent_hooks_default) {
|
if (extent_hooks == &ehooks_default_extent_hooks) {
|
||||||
return ehooks_default_destroy_impl(addr, size);
|
return ehooks_default_destroy_impl(addr, size);
|
||||||
} else if (extent_hooks->destroy == NULL) {
|
} else if (extent_hooks->destroy == NULL) {
|
||||||
return;
|
return;
|
||||||
@ -153,7 +156,7 @@ static inline bool
|
|||||||
ehooks_commit(tsdn_t *tsdn, ehooks_t *ehooks, void *addr, size_t size,
|
ehooks_commit(tsdn_t *tsdn, ehooks_t *ehooks, void *addr, size_t size,
|
||||||
size_t offset, size_t length, unsigned arena_ind) {
|
size_t offset, size_t length, unsigned arena_ind) {
|
||||||
extent_hooks_t *extent_hooks = ehooks_get_extent_hooks_ptr(ehooks);
|
extent_hooks_t *extent_hooks = ehooks_get_extent_hooks_ptr(ehooks);
|
||||||
if (extent_hooks == &extent_hooks_default) {
|
if (extent_hooks == &ehooks_default_extent_hooks) {
|
||||||
return ehooks_default_commit_impl(addr, offset, length);
|
return ehooks_default_commit_impl(addr, offset, length);
|
||||||
} else if (extent_hooks->commit == NULL) {
|
} else if (extent_hooks->commit == NULL) {
|
||||||
return true;
|
return true;
|
||||||
@ -170,7 +173,7 @@ static inline bool
|
|||||||
ehooks_decommit(tsdn_t *tsdn, ehooks_t *ehooks, void *addr, size_t size,
|
ehooks_decommit(tsdn_t *tsdn, ehooks_t *ehooks, void *addr, size_t size,
|
||||||
size_t offset, size_t length, unsigned arena_ind) {
|
size_t offset, size_t length, unsigned arena_ind) {
|
||||||
extent_hooks_t *extent_hooks = ehooks_get_extent_hooks_ptr(ehooks);
|
extent_hooks_t *extent_hooks = ehooks_get_extent_hooks_ptr(ehooks);
|
||||||
if (extent_hooks == &extent_hooks_default) {
|
if (extent_hooks == &ehooks_default_extent_hooks) {
|
||||||
return ehooks_default_decommit_impl(addr, offset, length);
|
return ehooks_default_decommit_impl(addr, offset, length);
|
||||||
} else if (extent_hooks->decommit == NULL) {
|
} else if (extent_hooks->decommit == NULL) {
|
||||||
return true;
|
return true;
|
||||||
@ -188,7 +191,7 @@ ehooks_purge_lazy(tsdn_t *tsdn, ehooks_t *ehooks, void *addr, size_t size,
|
|||||||
size_t offset, size_t length, unsigned arena_ind) {
|
size_t offset, size_t length, unsigned arena_ind) {
|
||||||
extent_hooks_t *extent_hooks = ehooks_get_extent_hooks_ptr(ehooks);
|
extent_hooks_t *extent_hooks = ehooks_get_extent_hooks_ptr(ehooks);
|
||||||
#ifdef PAGES_CAN_PURGE_LAZY
|
#ifdef PAGES_CAN_PURGE_LAZY
|
||||||
if (extent_hooks == &extent_hooks_default) {
|
if (extent_hooks == &ehooks_default_extent_hooks) {
|
||||||
return ehooks_default_purge_lazy_impl(addr, offset, length);
|
return ehooks_default_purge_lazy_impl(addr, offset, length);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -208,7 +211,7 @@ ehooks_purge_forced(tsdn_t *tsdn, ehooks_t *ehooks, void *addr, size_t size,
|
|||||||
size_t offset, size_t length, unsigned arena_ind) {
|
size_t offset, size_t length, unsigned arena_ind) {
|
||||||
extent_hooks_t *extent_hooks = ehooks_get_extent_hooks_ptr(ehooks);
|
extent_hooks_t *extent_hooks = ehooks_get_extent_hooks_ptr(ehooks);
|
||||||
#ifdef PAGES_CAN_PURGE_FORCED
|
#ifdef PAGES_CAN_PURGE_FORCED
|
||||||
if (extent_hooks == &extent_hooks_default) {
|
if (extent_hooks == &ehooks_default_extent_hooks) {
|
||||||
return ehooks_default_purge_forced_impl(addr, offset, length);
|
return ehooks_default_purge_forced_impl(addr, offset, length);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -244,7 +247,7 @@ static inline bool
|
|||||||
ehooks_merge(tsdn_t *tsdn, ehooks_t *ehooks, void *addr_a, size_t size_a,
|
ehooks_merge(tsdn_t *tsdn, ehooks_t *ehooks, void *addr_a, size_t size_a,
|
||||||
void *addr_b, size_t size_b, bool committed, unsigned arena_ind) {
|
void *addr_b, size_t size_b, bool committed, unsigned arena_ind) {
|
||||||
extent_hooks_t *extent_hooks = ehooks_get_extent_hooks_ptr(ehooks);
|
extent_hooks_t *extent_hooks = ehooks_get_extent_hooks_ptr(ehooks);
|
||||||
if (extent_hooks == &extent_hooks_default) {
|
if (extent_hooks == &ehooks_default_extent_hooks) {
|
||||||
return ehooks_default_merge_impl(addr_a, addr_b);
|
return ehooks_default_merge_impl(addr_a, addr_b);
|
||||||
} else if (extent_hooks->merge == NULL) {
|
} else if (extent_hooks->merge == NULL) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -91,7 +91,7 @@ arena_get(tsdn_t *tsdn, unsigned ind, bool init_if_missing) {
|
|||||||
if (unlikely(ret == NULL)) {
|
if (unlikely(ret == NULL)) {
|
||||||
if (init_if_missing) {
|
if (init_if_missing) {
|
||||||
ret = arena_init(tsdn, ind,
|
ret = arena_init(tsdn, ind,
|
||||||
(extent_hooks_t *)&extent_hooks_default);
|
(extent_hooks_t *)&ehooks_default_extent_hooks);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -511,6 +511,6 @@ base_postfork_child(tsdn_t *tsdn, base_t *base) {
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
base_boot(tsdn_t *tsdn) {
|
base_boot(tsdn_t *tsdn) {
|
||||||
b0 = base_new(tsdn, 0, (extent_hooks_t *)&extent_hooks_default);
|
b0 = base_new(tsdn, 0, (extent_hooks_t *)&ehooks_default_extent_hooks);
|
||||||
return (b0 == NULL);
|
return (b0 == NULL);
|
||||||
}
|
}
|
||||||
|
@ -2377,7 +2377,7 @@ arena_i_extent_hooks_ctl(tsd_t *tsd, const size_t *mib, size_t miblen,
|
|||||||
goto label_return;
|
goto label_return;
|
||||||
}
|
}
|
||||||
old_extent_hooks =
|
old_extent_hooks =
|
||||||
(extent_hooks_t *)&extent_hooks_default;
|
(extent_hooks_t *)&ehooks_default_extent_hooks;
|
||||||
READ(old_extent_hooks, extent_hooks_t *);
|
READ(old_extent_hooks, extent_hooks_t *);
|
||||||
if (newp != NULL) {
|
if (newp != NULL) {
|
||||||
/* Initialize a new arena as a side effect. */
|
/* Initialize a new arena as a side effect. */
|
||||||
@ -2581,7 +2581,7 @@ arenas_create_ctl(tsd_t *tsd, const size_t *mib, size_t miblen,
|
|||||||
|
|
||||||
malloc_mutex_lock(tsd_tsdn(tsd), &ctl_mtx);
|
malloc_mutex_lock(tsd_tsdn(tsd), &ctl_mtx);
|
||||||
|
|
||||||
extent_hooks = (extent_hooks_t *)&extent_hooks_default;
|
extent_hooks = (extent_hooks_t *)&ehooks_default_extent_hooks;
|
||||||
WRITE(extent_hooks, extent_hooks_t *);
|
WRITE(extent_hooks, extent_hooks_t *);
|
||||||
if ((arena_ind = ctl_arena_init(tsd, extent_hooks)) == UINT_MAX) {
|
if ((arena_ind = ctl_arena_init(tsd, extent_hooks)) == UINT_MAX) {
|
||||||
ret = EAGAIN;
|
ret = EAGAIN;
|
||||||
|
20
src/ehooks.c
20
src/ehooks.c
@ -208,3 +208,23 @@ ehooks_default_merge(extent_hooks_t *extent_hooks, void *addr_a, size_t size_a,
|
|||||||
}
|
}
|
||||||
return ehooks_default_merge_impl(addr_a, addr_b);
|
return ehooks_default_merge_impl(addr_a, addr_b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const extent_hooks_t ehooks_default_extent_hooks = {
|
||||||
|
ehooks_default_alloc,
|
||||||
|
ehooks_default_dalloc,
|
||||||
|
ehooks_default_destroy,
|
||||||
|
ehooks_default_commit,
|
||||||
|
ehooks_default_decommit,
|
||||||
|
#ifdef PAGES_CAN_PURGE_LAZY
|
||||||
|
ehooks_default_purge_lazy,
|
||||||
|
#else
|
||||||
|
NULL,
|
||||||
|
#endif
|
||||||
|
#ifdef PAGES_CAN_PURGE_FORCED
|
||||||
|
ehooks_default_purge_forced,
|
||||||
|
#else
|
||||||
|
NULL,
|
||||||
|
#endif
|
||||||
|
ehooks_default_split,
|
||||||
|
ehooks_default_merge
|
||||||
|
};
|
||||||
|
20
src/extent.c
20
src/extent.c
@ -34,26 +34,6 @@ static extent_t *extent_split_impl(tsdn_t *tsdn, arena_t *arena,
|
|||||||
static bool extent_merge_impl(tsdn_t *tsdn, arena_t *arena, ehooks_t *ehooks,
|
static bool extent_merge_impl(tsdn_t *tsdn, arena_t *arena, ehooks_t *ehooks,
|
||||||
extent_t *a, extent_t *b, bool growing_retained);
|
extent_t *a, extent_t *b, bool growing_retained);
|
||||||
|
|
||||||
const extent_hooks_t extent_hooks_default = {
|
|
||||||
ehooks_default_alloc,
|
|
||||||
ehooks_default_dalloc,
|
|
||||||
ehooks_default_destroy,
|
|
||||||
ehooks_default_commit,
|
|
||||||
ehooks_default_decommit,
|
|
||||||
#ifdef PAGES_CAN_PURGE_LAZY
|
|
||||||
ehooks_default_purge_lazy,
|
|
||||||
#else
|
|
||||||
NULL,
|
|
||||||
#endif
|
|
||||||
#ifdef PAGES_CAN_PURGE_FORCED
|
|
||||||
ehooks_default_purge_forced,
|
|
||||||
#else
|
|
||||||
NULL,
|
|
||||||
#endif
|
|
||||||
ehooks_default_split,
|
|
||||||
ehooks_default_merge
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Used exclusively for gdump triggering. */
|
/* Used exclusively for gdump triggering. */
|
||||||
static atomic_zu_t curpages;
|
static atomic_zu_t curpages;
|
||||||
static atomic_zu_t highpages;
|
static atomic_zu_t highpages;
|
||||||
|
@ -589,7 +589,8 @@ arena_choose_hard(tsd_t *tsd, bool internal) {
|
|||||||
choose[j] = first_null;
|
choose[j] = first_null;
|
||||||
arena = arena_init_locked(tsd_tsdn(tsd),
|
arena = arena_init_locked(tsd_tsdn(tsd),
|
||||||
choose[j],
|
choose[j],
|
||||||
(extent_hooks_t *)&extent_hooks_default);
|
(extent_hooks_t *)
|
||||||
|
&ehooks_default_extent_hooks);
|
||||||
if (arena == NULL) {
|
if (arena == NULL) {
|
||||||
malloc_mutex_unlock(tsd_tsdn(tsd),
|
malloc_mutex_unlock(tsd_tsdn(tsd),
|
||||||
&arenas_lock);
|
&arenas_lock);
|
||||||
@ -1589,8 +1590,8 @@ malloc_init_hard_a0_locked() {
|
|||||||
* Initialize one arena here. The rest are lazily created in
|
* Initialize one arena here. The rest are lazily created in
|
||||||
* arena_choose_hard().
|
* arena_choose_hard().
|
||||||
*/
|
*/
|
||||||
if (arena_init(TSDN_NULL, 0, (extent_hooks_t *)&extent_hooks_default)
|
if (arena_init(TSDN_NULL, 0,
|
||||||
== NULL) {
|
(extent_hooks_t *)&ehooks_default_extent_hooks) == NULL) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
a0 = arena_get(TSDN_NULL, 0, false);
|
a0 = arena_get(TSDN_NULL, 0, false);
|
||||||
|
@ -31,7 +31,8 @@ TEST_BEGIN(test_base_hooks_default) {
|
|||||||
size_t allocated0, allocated1, resident, mapped, n_thp;
|
size_t allocated0, allocated1, resident, mapped, n_thp;
|
||||||
|
|
||||||
tsdn_t *tsdn = tsd_tsdn(tsd_fetch());
|
tsdn_t *tsdn = tsd_tsdn(tsd_fetch());
|
||||||
base = base_new(tsdn, 0, (extent_hooks_t *)&extent_hooks_default);
|
base = base_new(tsdn, 0,
|
||||||
|
(extent_hooks_t *)&ehooks_default_extent_hooks);
|
||||||
|
|
||||||
if (config_stats) {
|
if (config_stats) {
|
||||||
base_stats_get(tsdn, base, &allocated0, &resident, &mapped,
|
base_stats_get(tsdn, base, &allocated0, &resident, &mapped,
|
||||||
|
Loading…
Reference in New Issue
Block a user