Add mallctl for batch allocation API

This commit is contained in:
Yinan Zhang 2020-07-15 10:42:07 -07:00
parent 978f830ee3
commit f6cf5eb388
2 changed files with 51 additions and 2 deletions

View File

@ -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;
}

View File

@ -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);