diff options
author | Piotr Balcer <piotr.balcer@intel.com> | 2021-08-23 14:03:35 +0200 |
---|---|---|
committer | Qi Wang <interwq@gmail.com> | 2021-09-24 13:43:18 -0700 |
commit | 7bb05e04be693b26536dc2335b4d230dacc5d7d2 (patch) | |
tree | f39bfd3dc6d6310f9a8469fcebdd07d5b4b5e9a5 /test | |
parent | a9031a0970df9c999873617423f789bd46bfe619 (diff) | |
download | jemalloc-7bb05e04be693b26536dc2335b4d230dacc5d7d2.tar.gz |
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.
Diffstat (limited to 'test')
-rw-r--r-- | test/integration/extent.c | 53 | ||||
-rw-r--r-- | test/unit/base.c | 7 | ||||
-rw-r--r-- | test/unit/edata_cache.c | 2 | ||||
-rw-r--r-- | test/unit/hpa.c | 2 | ||||
-rw-r--r-- | test/unit/pa.c | 3 | ||||
-rw-r--r-- | test/unit/rtree.c | 15 | ||||
-rw-r--r-- | test/unit/sec.c | 4 |
7 files changed, 72 insertions, 14 deletions
diff --git a/test/integration/extent.c b/test/integration/extent.c index 831ef63f..7a028f18 100644 --- a/test/integration/extent.c +++ b/test/integration/extent.c @@ -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); } diff --git a/test/unit/base.c b/test/unit/base.c index 5e990b34..07a43df7 100644 --- a/test/unit/base.c +++ b/test/unit/base.c @@ -32,7 +32,8 @@ TEST_BEGIN(test_base_hooks_default) { tsdn_t *tsdn = tsd_tsdn(tsd_fetch()); base = base_new(tsdn, 0, - (extent_hooks_t *)&ehooks_default_extent_hooks); + (extent_hooks_t *)&ehooks_default_extent_hooks, + /* metadata_use_hooks */ true); if (config_stats) { base_stats_get(tsdn, base, &allocated0, &resident, &mapped, @@ -74,7 +75,7 @@ TEST_BEGIN(test_base_hooks_null) { memcpy(&hooks, &hooks_null, sizeof(extent_hooks_t)); tsdn_t *tsdn = tsd_tsdn(tsd_fetch()); - base = base_new(tsdn, 0, &hooks); + base = base_new(tsdn, 0, &hooks, /* metadata_use_hooks */ true); expect_ptr_not_null(base, "Unexpected base_new() failure"); if (config_stats) { @@ -120,7 +121,7 @@ TEST_BEGIN(test_base_hooks_not_null) { tsdn_t *tsdn = tsd_tsdn(tsd_fetch()); did_alloc = false; - base = base_new(tsdn, 0, &hooks); + base = base_new(tsdn, 0, &hooks, /* metadata_use_hooks */ true); expect_ptr_not_null(base, "Unexpected base_new() failure"); expect_true(did_alloc, "Expected alloc"); diff --git a/test/unit/edata_cache.c b/test/unit/edata_cache.c index fe920c9a..af1110a9 100644 --- a/test/unit/edata_cache.c +++ b/test/unit/edata_cache.c @@ -5,7 +5,7 @@ static void test_edata_cache_init(edata_cache_t *edata_cache) { base_t *base = base_new(TSDN_NULL, /* ind */ 1, - &ehooks_default_extent_hooks); + &ehooks_default_extent_hooks, /* metadata_use_hooks */ true); assert_ptr_not_null(base, ""); bool err = edata_cache_init(edata_cache, base); assert_false(err, ""); diff --git a/test/unit/hpa.c b/test/unit/hpa.c index dc3acc08..86012c75 100644 --- a/test/unit/hpa.c +++ b/test/unit/hpa.c @@ -37,7 +37,7 @@ static hpa_shard_t * create_test_data(hpa_hooks_t *hooks, hpa_shard_opts_t *opts) { bool err; base_t *base = base_new(TSDN_NULL, /* ind */ SHARD_IND, - &ehooks_default_extent_hooks); + &ehooks_default_extent_hooks, /* metadata_use_hooks */ true); assert_ptr_not_null(base, ""); test_data_t *test_data = malloc(sizeof(test_data_t)); diff --git a/test/unit/pa.c b/test/unit/pa.c index 4d3ad5e9..01d891df 100644 --- a/test/unit/pa.c +++ b/test/unit/pa.c @@ -53,7 +53,8 @@ test_data_t *init_test_data(ssize_t dirty_decay_ms, ssize_t muzzy_decay_ms) { assert_ptr_not_null(test_data, ""); init_test_extent_hooks(&test_data->hooks); - base_t *base = base_new(TSDN_NULL, /* ind */ 1, &test_data->hooks); + base_t *base = base_new(TSDN_NULL, /* ind */ 1, + &test_data->hooks, /* metadata_use_hooks */ true); assert_ptr_not_null(base, ""); test_data->base = base; diff --git a/test/unit/rtree.c b/test/unit/rtree.c index 7b2a4e36..82b617bd 100644 --- a/test/unit/rtree.c +++ b/test/unit/rtree.c @@ -12,7 +12,8 @@ TEST_BEGIN(test_rtree_read_empty) { tsdn = tsdn_fetch(); - base_t *base = base_new(tsdn, 0, &ehooks_default_extent_hooks); + base_t *base = base_new(tsdn, 0, + &ehooks_default_extent_hooks, /* metadata_use_hooks */ true); expect_ptr_not_null(base, "Unexpected base_new failure"); rtree_t *rtree = &test_rtree; @@ -52,7 +53,8 @@ TEST_BEGIN(test_rtree_extrema) { tsdn_t *tsdn = tsdn_fetch(); - base_t *base = base_new(tsdn, 0, &ehooks_default_extent_hooks); + base_t *base = base_new(tsdn, 0, + &ehooks_default_extent_hooks, /* metadata_use_hooks */ true); expect_ptr_not_null(base, "Unexpected base_new failure"); rtree_t *rtree = &test_rtree; @@ -103,7 +105,8 @@ TEST_END TEST_BEGIN(test_rtree_bits) { tsdn_t *tsdn = tsdn_fetch(); - base_t *base = base_new(tsdn, 0, &ehooks_default_extent_hooks); + base_t *base = base_new(tsdn, 0, + &ehooks_default_extent_hooks, /* metadata_use_hooks */ true); expect_ptr_not_null(base, "Unexpected base_new failure"); uintptr_t keys[] = {PAGE, PAGE + 1, @@ -152,7 +155,8 @@ TEST_BEGIN(test_rtree_random) { sfmt_t *sfmt = init_gen_rand(SEED); tsdn_t *tsdn = tsdn_fetch(); - base_t *base = base_new(tsdn, 0, &ehooks_default_extent_hooks); + base_t *base = base_new(tsdn, 0, + &ehooks_default_extent_hooks, /* metadata_use_hooks */ true); expect_ptr_not_null(base, "Unexpected base_new failure"); uintptr_t keys[NSET]; @@ -250,7 +254,8 @@ test_rtree_range_write(tsdn_t *tsdn, rtree_t *rtree, uintptr_t start, TEST_BEGIN(test_rtree_range) { tsdn_t *tsdn = tsdn_fetch(); - base_t *base = base_new(tsdn, 0, &ehooks_default_extent_hooks); + base_t *base = base_new(tsdn, 0, + &ehooks_default_extent_hooks, /* metadata_use_hooks */ true); expect_ptr_not_null(base, "Unexpected base_new failure"); rtree_t *rtree = &test_rtree; diff --git a/test/unit/sec.c b/test/unit/sec.c index 82b0c9d9..763e6087 100644 --- a/test/unit/sec.c +++ b/test/unit/sec.c @@ -42,7 +42,7 @@ test_sec_init(sec_t *sec, pai_t *fallback, size_t nshards, size_t max_alloc, * short-running, and SECs are arena-scoped in reality. */ base_t *base = base_new(TSDN_NULL, /* ind */ 123, - &ehooks_default_extent_hooks); + &ehooks_default_extent_hooks, /* metadata_use_hooks */ true); bool err = sec_init(TSDN_NULL, sec, base, fallback, &opts); assert_false(err, "Unexpected initialization failure"); @@ -442,7 +442,7 @@ TEST_BEGIN(test_nshards_0) { /* See the note above -- we can't use the real tsd. */ tsdn_t *tsdn = TSDN_NULL; base_t *base = base_new(TSDN_NULL, /* ind */ 123, - &ehooks_default_extent_hooks); + &ehooks_default_extent_hooks, /* metadata_use_hooks */ true); sec_opts_t opts = SEC_OPTS_DEFAULT; opts.nshards = 0; |