mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-07-23 00:57:19 +03:00
add experimental.arenas_create_ext mallctl
This mallctl accepts an arena_config_t structure which can be used to customize the behavior of the arena. Right now it contains extent_hooks and a new option, metadata_use_hooks, which controls whether the extent hooks are also used for metadata allocation. The medata_use_hooks option has two main use cases: 1. In heterogeneous memory systems, to avoid metadata being placed on potentially slower memory. 2. Avoiding virtual memory from being leaked as a result of metadata allocation failure originating in an extent hook.
This commit is contained in:
parent
a9031a0970
commit
7bb05e04be
17 changed files with 165 additions and 41 deletions
21
src/base.c
21
src/base.c
|
|
@ -295,6 +295,12 @@ base_block_alloc(tsdn_t *tsdn, base_t *base, ehooks_t *ehooks, unsigned ind,
|
|||
return block;
|
||||
}
|
||||
|
||||
static ehooks_t *
|
||||
base_ehooks_get_for_metadata(base_t *base) {
|
||||
return base->metadata_use_hooks ? &base->ehooks :
|
||||
(struct ehooks_s *)&ehooks_default_extent_hooks;
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate an extent that is at least as large as specified size, with
|
||||
* specified alignment.
|
||||
|
|
@ -303,7 +309,7 @@ static edata_t *
|
|||
base_extent_alloc(tsdn_t *tsdn, base_t *base, size_t size, size_t alignment) {
|
||||
malloc_mutex_assert_owner(tsdn, &base->mtx);
|
||||
|
||||
ehooks_t *ehooks = base_ehooks_get(base);
|
||||
ehooks_t *ehooks = base_ehooks_get_for_metadata(base);
|
||||
/*
|
||||
* Drop mutex during base_block_alloc(), because an extent hook will be
|
||||
* called.
|
||||
|
|
@ -342,7 +348,8 @@ b0get(void) {
|
|||
}
|
||||
|
||||
base_t *
|
||||
base_new(tsdn_t *tsdn, unsigned ind, const extent_hooks_t *extent_hooks) {
|
||||
base_new(tsdn_t *tsdn, unsigned ind, const extent_hooks_t *extent_hooks,
|
||||
bool metadata_use_hooks) {
|
||||
pszind_t pind_last = 0;
|
||||
size_t extent_sn_next = 0;
|
||||
|
||||
|
|
@ -352,7 +359,9 @@ base_new(tsdn_t *tsdn, unsigned ind, const extent_hooks_t *extent_hooks) {
|
|||
* memory, and then initialize the ehooks within the base_t.
|
||||
*/
|
||||
ehooks_t fake_ehooks;
|
||||
ehooks_init(&fake_ehooks, (extent_hooks_t *)extent_hooks, ind);
|
||||
ehooks_init(&fake_ehooks, metadata_use_hooks ?
|
||||
(extent_hooks_t *)extent_hooks :
|
||||
(extent_hooks_t *)&ehooks_default_extent_hooks, ind);
|
||||
|
||||
base_block_t *block = base_block_alloc(tsdn, NULL, &fake_ehooks, ind,
|
||||
&pind_last, &extent_sn_next, sizeof(base_t), QUANTUM);
|
||||
|
|
@ -375,6 +384,7 @@ base_new(tsdn_t *tsdn, unsigned ind, const extent_hooks_t *extent_hooks) {
|
|||
base->extent_sn_next = extent_sn_next;
|
||||
base->blocks = block;
|
||||
base->auto_thp_switched = false;
|
||||
base->metadata_use_hooks = metadata_use_hooks;
|
||||
for (szind_t i = 0; i < SC_NSIZES; i++) {
|
||||
edata_heap_new(&base->avail[i]);
|
||||
}
|
||||
|
|
@ -397,7 +407,7 @@ base_new(tsdn_t *tsdn, unsigned ind, const extent_hooks_t *extent_hooks) {
|
|||
|
||||
void
|
||||
base_delete(tsdn_t *tsdn, base_t *base) {
|
||||
ehooks_t *ehooks = base_ehooks_get(base);
|
||||
ehooks_t *ehooks = base_ehooks_get_for_metadata(base);
|
||||
base_block_t *next = base->blocks;
|
||||
do {
|
||||
base_block_t *block = next;
|
||||
|
|
@ -512,6 +522,7 @@ base_postfork_child(tsdn_t *tsdn, base_t *base) {
|
|||
|
||||
bool
|
||||
base_boot(tsdn_t *tsdn) {
|
||||
b0 = base_new(tsdn, 0, (extent_hooks_t *)&ehooks_default_extent_hooks);
|
||||
b0 = base_new(tsdn, 0,
|
||||
(extent_hooks_t *)&ehooks_default_extent_hooks, true);
|
||||
return (b0 == NULL);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue