diff options
| author | Yinan Zhang <zyn8950@gmail.com> | 2020-07-15 10:42:07 -0700 |
|---|---|---|
| committer | Yinan Zhang <zyn8950@gmail.com> | 2020-07-31 09:16:50 -0700 |
| commit | f6cf5eb388eefd1c48c04d6b8c550105b2ad8c17 (patch) | |
| tree | c84cd35818e876cc679c155e3559b06c8b93241e | |
| parent | 978f830ee300c15460085bdc49b4bdb9ef1a16d8 (diff) | |
| download | platform_external_jemalloc_new-f6cf5eb388eefd1c48c04d6b8c550105b2ad8c17.tar.gz platform_external_jemalloc_new-f6cf5eb388eefd1c48c04d6b8c550105b2ad8c17.tar.bz2 platform_external_jemalloc_new-f6cf5eb388eefd1c48c04d6b8c550105b2ad8c17.zip | |
Add mallctl for batch allocation API
| -rw-r--r-- | src/ctl.c | 32 | ||||
| -rw-r--r-- | test/unit/batch_alloc.c | 21 |
2 files changed, 51 insertions, 2 deletions
@@ -254,6 +254,7 @@ CTL_PROTO(experimental_arenas_i_pactivep) INDEX_PROTO(experimental_arenas_i) CTL_PROTO(experimental_prof_recent_alloc_max) CTL_PROTO(experimental_prof_recent_alloc_dump) +CTL_PROTO(experimental_batch_alloc) #define MUTEX_STATS_CTL_PROTO_GEN(n) \ CTL_PROTO(stats_##n##_num_ops) \ @@ -675,7 +676,8 @@ static const ctl_named_node_t experimental_node[] = { {NAME("hooks"), CHILD(named, experimental_hooks)}, {NAME("utilization"), CHILD(named, experimental_utilization)}, {NAME("arenas"), CHILD(indexed, experimental_arenas)}, - {NAME("prof_recent"), CHILD(named, experimental_prof_recent)} + {NAME("prof_recent"), CHILD(named, experimental_prof_recent)}, + {NAME("batch_alloc"), CTL(experimental_batch_alloc)} }; static const ctl_named_node_t root_node[] = { @@ -3637,3 +3639,31 @@ experimental_prof_recent_alloc_dump_ctl(tsd_t *tsd, const size_t *mib, label_return: return ret; } + +typedef struct batch_alloc_packet_s batch_alloc_packet_t; +struct batch_alloc_packet_s { + void **ptrs; + size_t num; + size_t size; + int flags; +}; + +static int +experimental_batch_alloc_ctl(tsd_t *tsd, const size_t *mib, + size_t miblen, void *oldp, size_t *oldlenp, void *newp, size_t newlen) { + int ret; + + VERIFY_READ(size_t); + + batch_alloc_packet_t batch_alloc_packet; + ASSURED_WRITE(batch_alloc_packet, batch_alloc_packet_t); + size_t filled = batch_alloc(batch_alloc_packet.ptrs, + batch_alloc_packet.num, batch_alloc_packet.size, + batch_alloc_packet.flags); + READ(filled, size_t); + + ret = 0; + +label_return: + return ret; +} diff --git a/test/unit/batch_alloc.c b/test/unit/batch_alloc.c index 66e0565f..08d6f66a 100644 --- a/test/unit/batch_alloc.c +++ b/test/unit/batch_alloc.c @@ -80,6 +80,24 @@ release_batch(void **ptrs, size_t batch, size_t size) { } } +typedef struct batch_alloc_packet_s batch_alloc_packet_t; +struct batch_alloc_packet_s { + void **ptrs; + size_t num; + size_t size; + int flags; +}; + +static size_t +batch_alloc_wrapper(void **ptrs, size_t num, size_t size, int flags) { + batch_alloc_packet_t batch_alloc_packet = {ptrs, num, size, flags}; + size_t filled; + size_t len = sizeof(size_t); + assert_d_eq(mallctl("experimental.batch_alloc", &filled, &len, + &batch_alloc_packet, sizeof(batch_alloc_packet)), 0, ""); + return filled; +} + static void test_wrapper(size_t size, size_t alignment, bool zero, unsigned arena_flag) { tsd_t *tsd = tsd_fetch(); @@ -131,7 +149,8 @@ test_wrapper(size_t size, size_t alignment, bool zero, unsigned arena_flag) { assert(batch < BATCH_MAX); bin_stats_t stats_before, stats_after; memcpy(&stats_before, &bin->stats, sizeof(bin_stats_t)); - size_t filled = batch_alloc(ptrs, batch, size, flags); + size_t filled = batch_alloc_wrapper(ptrs, batch, size, + flags); assert_zu_eq(filled, batch, ""); memcpy(&stats_after, &bin->stats, sizeof(bin_stats_t)); verify_stats(&stats_before, &stats_after, batch, nregs); |
