Commit 261755e7 authored by Swann Perarnau's avatar Swann Perarnau

[feature] add proper arena init

Add arena_jemalloc initialization, working the same way than tiling and
binding initializations.

We made the choice of not building generic arena allocation functions,
as the benefit of that isn't exactly obvious right now.

Also, we want users to understand the kind of arenas and areas they are
manipulating.
parent 2ae0aedb
......@@ -75,13 +75,15 @@ struct aml_arena_jemalloc_data {
(sizeof(struct aml_arena_jemalloc_data) + \
sizeof(struct aml_arena))
int aml_arena_jemalloc_regular_init(struct aml_arena_jemalloc_data *);
int aml_arena_jemalloc_regular_destroy(struct aml_arena_jemalloc_data *);
int aml_arena_jemalloc_aligned_init(struct aml_arena_jemalloc_data *, size_t);
int aml_arena_jemalloc_align_destroy(struct aml_arena_jemalloc_data *);
int aml_arena_jemalloc_generic_init(struct aml_arena_jemalloc_data *,
struct aml_arena_jemalloc_data *);
int aml_arena_jemalloc_generic_destroy(struct aml_arena_jemalloc_data *);
#define AML_ARENA_JEMALLOC_TYPE_REGULAR 0
#define AML_ARENA_JEMALLOC_TYPE_ALIGNED 1
#define AML_ARENA_JEMALLOC_TYPE_GENERIC 2
int aml_arena_jemalloc_create(struct aml_arena **, int type, ...);
int aml_arena_jemalloc_init(struct aml_arena *, int type, ...);
int aml_arena_jemalloc_vinit(struct aml_arena *, int type, va_list);
int aml_arena_jemalloc_destroy(struct aml_arena *);
/*******************************************************************************
* Areas:
......
......@@ -273,44 +273,63 @@ struct aml_arena_ops aml_arena_jemalloc_ops = {
* To create the data template for arenas.
******************************************************************************/
int aml_arena_jemalloc_regular_init(struct aml_arena_jemalloc_data *data)
/* allocate and init the binding according to type */
int aml_arena_jemalloc_create(struct aml_arena **a, int type, ...)
{
assert(data != NULL);
data->flags = 0;
va_list ap;
struct aml_arena *ret = NULL;
intptr_t baseptr, dataptr;
va_start(ap, type);
/* alloc */
baseptr = (intptr_t) calloc(1, AML_ARENA_JEMALLOC_ALLOCSIZE);
dataptr = baseptr + sizeof(struct aml_arena);
ret = (struct aml_arena *)baseptr;
ret->data = (struct aml_arena_data *)dataptr;
aml_arena_jemalloc_vinit(ret, type, ap);
va_end(ap);
*a = ret;
return 0;
}
int aml_arena_jemalloc_regular_destroy(struct aml_arena_jemalloc_data *data)
int aml_arena_jemalloc_vinit(struct aml_arena *a, int type, va_list ap)
{
assert(data != NULL);
return 0;
}
int aml_arena_jemalloc_aligned_init(struct aml_arena_jemalloc_data *data,
size_t align)
{
assert(data != NULL);
data->flags = MALLOCX_ALIGN(align);
return 0;
}
int aml_arena_jemalloc_align_destroy(struct aml_arena_jemalloc_data *data)
{
assert(data != NULL);
a->ops = &aml_arena_jemalloc_ops;
struct aml_arena_jemalloc_data *data =
(struct aml_arena_jemalloc_data *)a->data;
if(type == AML_ARENA_JEMALLOC_TYPE_REGULAR)
{
data->flags = 0;
}
else if(type == AML_ARENA_JEMALLOC_TYPE_ALIGNED)
{
size_t align = va_arg(ap, size_t);
data->flags = MALLOCX_ALIGN(align);
}
else if(type == AML_ARENA_JEMALLOC_TYPE_GENERIC)
{
struct aml_arena_data *arg = va_arg(ap, struct aml_arena_data*);
struct aml_arena_jemalloc_data *template =
(struct aml_arena_jemalloc_data *)arg;
data->flags = template->flags;
}
return 0;
}
int aml_arena_jemalloc_generic_init(struct aml_arena_jemalloc_data *data,
struct aml_arena_jemalloc_data *template)
int aml_arena_jemalloc_init(struct aml_arena *a, int type, ...)
{
assert(data != NULL);
assert(template != NULL);
data->flags = template->flags;
return 0;
int err;
va_list ap;
va_start(ap, type);
err = aml_arena_jemalloc_vinit(a, type, ap);
va_end(ap);
return err;
}
int aml_arena_jemalloc_generic_destroy(struct aml_arena_jemalloc_data *data)
int aml_arena_jemalloc_destroy(struct aml_arena *a)
{
assert(data != NULL);
return 0;
}
......@@ -51,9 +51,7 @@ void doit(struct aml_area *area)
int main(int argc, char *argv[])
{
struct aml_area area;
struct aml_arena_jemalloc_data arena_data;
struct aml_arena arena = {&aml_arena_jemalloc_ops,
(struct aml_arena_data *)&arena_data};
AML_ARENA_JEMALLOC_DECL(arena);
struct aml_area_linux area_data;
unsigned long nodemask[AML_NODEMASK_SZ];
struct bitmask *allowed;
......@@ -73,7 +71,7 @@ int main(int argc, char *argv[])
/* init all the inner objects:
* WARNING: there an order to this madness. */
assert(!aml_arena_jemalloc_regular_init(&arena_data));
assert(!aml_arena_jemalloc_init(&arena, AML_ARENA_JEMALLOC_TYPE_REGULAR));
assert(!aml_area_linux_manager_single_init(&area_data.data.manager,
&arena));
allowed = numa_get_mems_allowed();
......@@ -90,7 +88,7 @@ int main(int argc, char *argv[])
assert(!aml_area_linux_mmap_anonymous_destroy(&area_data.data.mmap));
assert(!aml_area_linux_mbind_destroy(&area_data.data.mbind));
assert(!aml_area_linux_manager_single_destroy(&area_data.data.manager));
assert(!aml_arena_jemalloc_regular_destroy(&arena_data));
assert(!aml_arena_jemalloc_destroy(&arena));
assert(!aml_area_linux_destroy(&area_data));
aml_finalize();
......
......@@ -47,13 +47,7 @@ void doit(struct aml_arena *arena)
int main(int argc, char *argv[])
{
struct aml_arena_jemalloc_data data[4];
struct aml_arena arenas[] = {
{&aml_arena_jemalloc_ops, (struct aml_arena_data *)&data[0]},
{&aml_arena_jemalloc_ops, (struct aml_arena_data *)&data[1]},
{&aml_arena_jemalloc_ops, (struct aml_arena_data *)&data[2]},
{&aml_arena_jemalloc_ops, (struct aml_arena_data *)&data[3]},
};
struct aml_arena *arenas[4];
/* library init */
aml_init(&argc, &argv);
......@@ -63,18 +57,25 @@ int main(int argc, char *argv[])
area.data = (struct aml_area_data *)&posix_data;
/* build up the data variants */
assert(!aml_arena_jemalloc_regular_init(&data[0]));
assert(!aml_arena_jemalloc_aligned_init(&data[1], 42));
assert(!aml_arena_jemalloc_generic_init(&data[2], &data[0]));
assert(!aml_arena_jemalloc_create(&arenas[0],
AML_ARENA_JEMALLOC_TYPE_REGULAR));
assert(!aml_arena_jemalloc_create(&arenas[1],
AML_ARENA_JEMALLOC_TYPE_ALIGNED,
(size_t)42));
assert(!aml_arena_jemalloc_create(&arenas[2],
AML_ARENA_JEMALLOC_TYPE_GENERIC,
arenas[0]->data));
/* alignment bigger than PAGE_SIZE */
assert(!aml_arena_jemalloc_aligned_init(&data[3], 4100));
assert(!aml_arena_jemalloc_create(&arenas[3],
AML_ARENA_JEMALLOC_TYPE_ALIGNED, 4100));
for(int i = 0; i < ARRAY_SIZE(arenas); i++)
doit(&arenas[i]);
doit(arenas[i]);
assert(!aml_arena_jemalloc_regular_destroy(&data[0]));
assert(!aml_arena_jemalloc_align_destroy(&data[1]));
assert(!aml_arena_jemalloc_generic_destroy(&data[2]));
assert(!aml_arena_jemalloc_align_destroy(&data[3]));
for(int i = 0; i < ARRAY_SIZE(arenas); i++)
{
assert(!aml_arena_jemalloc_destroy(arenas[i]));
free(arenas[i]);
}
return 0;
}
......@@ -26,9 +26,7 @@ int main(int argc, char *argv[])
{
struct aml_area area;
struct aml_area_posix_data area_data;
struct aml_arena_jemalloc_data arena_data;
struct aml_arena arena = {&aml_arena_jemalloc_ops,
(struct aml_arena_data *)&arena_data};
AML_ARENA_JEMALLOC_DECL(arena);
struct aml_area_linux_manager_data config[1];
aml_init(&argc, &argv);
......@@ -39,7 +37,7 @@ int main(int argc, char *argv[])
aml_area_posix_init(&area_data);
area.ops = &aml_area_posix_ops;
area.data = (struct aml_area_data *)&area_data;
assert(!aml_arena_jemalloc_regular_init(&arena_data));
assert(!aml_arena_jemalloc_init(&arena, AML_ARENA_JEMALLOC_TYPE_REGULAR));
assert(!aml_arena_register(&arena, &area));
aml_area_linux_manager_single_init(&config[0], &arena);
......@@ -49,7 +47,7 @@ int main(int argc, char *argv[])
aml_area_linux_manager_single_destroy(&config[0]);
assert(!aml_arena_deregister(&arena));
aml_arena_jemalloc_regular_destroy(&arena_data);
aml_arena_jemalloc_destroy(&arena);
aml_area_posix_init(&area_data);
aml_finalize();
return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment