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:
@@ -2,6 +2,8 @@
|
||||
|
||||
#include "test/extent_hooks.h"
|
||||
|
||||
#include "jemalloc/internal/arena_types.h"
|
||||
|
||||
static void
|
||||
test_extent_body(unsigned arena_ind) {
|
||||
void *p;
|
||||
@@ -228,9 +230,58 @@ TEST_BEGIN(test_extent_auto_hook) {
|
||||
}
|
||||
TEST_END
|
||||
|
||||
static void
|
||||
test_arenas_create_ext_base(arena_config_t config,
|
||||
bool expect_hook_data, bool expect_hook_metadata)
|
||||
{
|
||||
unsigned arena, arena1;
|
||||
void *ptr;
|
||||
size_t sz = sizeof(unsigned);
|
||||
|
||||
extent_hooks_prep();
|
||||
|
||||
called_alloc = false;
|
||||
expect_d_eq(mallctl("experimental.arenas_create_ext",
|
||||
(void *)&arena, &sz, &config, sizeof(arena_config_t)), 0,
|
||||
"Unexpected mallctl() failure");
|
||||
expect_b_eq(called_alloc, expect_hook_metadata,
|
||||
"expected hook metadata alloc mismatch");
|
||||
|
||||
called_alloc = false;
|
||||
ptr = mallocx(42, MALLOCX_ARENA(arena) | MALLOCX_TCACHE_NONE);
|
||||
expect_b_eq(called_alloc, expect_hook_data,
|
||||
"expected hook data alloc mismatch");
|
||||
|
||||
expect_ptr_not_null(ptr, "Unexpected mallocx() failure");
|
||||
expect_d_eq(mallctl("arenas.lookup", &arena1, &sz, &ptr, sizeof(ptr)),
|
||||
0, "Unexpected mallctl() failure");
|
||||
expect_u_eq(arena, arena1, "Unexpected arena index");
|
||||
dallocx(ptr, 0);
|
||||
}
|
||||
|
||||
TEST_BEGIN(test_arenas_create_ext_with_ehooks_no_metadata) {
|
||||
arena_config_t config;
|
||||
config.extent_hooks = &hooks;
|
||||
config.metadata_use_hooks = false;
|
||||
|
||||
test_arenas_create_ext_base(config, true, false);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_arenas_create_ext_with_ehooks_with_metadata) {
|
||||
arena_config_t config;
|
||||
config.extent_hooks = &hooks;
|
||||
config.metadata_use_hooks = true;
|
||||
|
||||
test_arenas_create_ext_base(config, true, true);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
int
|
||||
main(void) {
|
||||
return test(
|
||||
test_extent_manual_hook,
|
||||
test_extent_auto_hook);
|
||||
test_extent_auto_hook,
|
||||
test_arenas_create_ext_with_ehooks_no_metadata,
|
||||
test_arenas_create_ext_with_ehooks_with_metadata);
|
||||
}
|
||||
|
Reference in New Issue
Block a user