Commit fbd94d99 authored by Rusty Russell's avatar Rusty Russell

alloc: implement huge allocations

Inefficient scheme for allocations > 1/8192 of the pool size.
parent 774ce035
......@@ -100,6 +100,7 @@ int main(int argc, char *argv[])
return 1;
if (strcmp(argv[1], "depends") == 0) {
printf("ccan/alignof\n");
printf("ccan/build_assert\n");
printf("ccan/likely\n");
printf("ccan/short_types\n");
......
This diff is collapsed.
......@@ -27,7 +27,7 @@ static bool sizes_ok(void *mem, unsigned long poolsize, void *p[], unsigned num)
static void test_pool(unsigned long pool_size)
{
unsigned int i, j, num;
unsigned int i, num;
void *mem;
void **p;
bool flip = false;
......@@ -50,17 +50,15 @@ static void test_pool(unsigned long pool_size)
ok1(sizes_ok(mem, pool_size, p, num));
/* Free every second one. */
for (i = j = 0; i < num; i = i * 3 / 2 + 1) {
for (i = 0; i < num; i = i * 3 / 2 + 1) {
flip = !flip;
if (flip) {
/* Compact. */
p[j++] = p[i];
invert_bytes(p[i], alloc_size(mem,pool_size,p[i]));
continue;
}
alloc_free(mem, pool_size, p[i]);
p[i] = NULL;
}
num /= 2;
ok1(alloc_check(mem, pool_size));
ok1(sizes_ok(mem, pool_size, p, num));
free(p);
......
......@@ -48,12 +48,9 @@ static void test(unsigned int pool_size)
void *mem;
unsigned int i, num, max_size;
void **p = calloc(pool_size, sizeof(*p));
/* FIXME: Should be pool_size! */
unsigned alloc_limit = (pool_size / MAX_LARGE_PAGES) >> MAX_PAGE_OBJECT_ORDER;
unsigned alloc_limit = pool_size / 2;
/* FIXME: Needs to be page aligned for now. */
if (posix_memalign(&mem, pool_size, pool_size) != 0)
errx(1, "Failed allocating aligned memory");
mem = malloc(pool_size);
/* Small pool, all allocs fail, even 0-length. */
alloc_init(mem, 0);
......@@ -136,7 +133,7 @@ static void test(unsigned int pool_size)
for (i = 0; (1 << i) < alloc_limit; i++) {
p[i] = alloc_get(mem, pool_size, i, 1 << i);
ok1(p[i]);
ok1(((unsigned long)p[i] % (1 << i)) == 0);
ok1(((char *)p[i] - (char *)mem) % (1 << i) == 0);
ok1(alloc_check(mem, pool_size));
ok1(alloc_size(mem, pool_size, p[i]) >= i);
}
......@@ -150,8 +147,9 @@ static void test(unsigned int pool_size)
for (i = 0; (1 << i) < alloc_limit; i++) {
p[0] = alloc_get(mem, pool_size, 1, 1 << i);
ok1(p[0]);
ok1(((char *)p[0] - (char *)mem) % (1 << i) == 0);
ok1(alloc_check(mem, pool_size));
ok1(alloc_size(mem, pool_size, p[i]) >= 1);
ok1(alloc_size(mem, pool_size, p[0]) >= 1);
alloc_free(mem, pool_size, p[0]);
ok1(alloc_check(mem, pool_size));
}
......@@ -166,7 +164,7 @@ static void test(unsigned int pool_size)
int main(int argc, char *argv[])
{
plan_tests(112 + 92);
plan_tests(480);
/* Large test. */
test(MIN_USEFUL_SIZE * 2);
......
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