commit 64c09e5c2a77312abc0c4e18cdc3751e93748089
parent a6f66e1592b3224b5c95660906a1a7e829d884f3
Author: sin <sin@2f30.org>
Date: Fri, 2 Aug 2013 11:03:33 +0100
Use sbrk() in alloc_object()
We keep all the rbtree nodes close together for better
cache coherency.
Diffstat:
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/random/rballoc.c b/random/rballoc.c
@@ -71,22 +71,23 @@ dump_free_tree(void)
__func__, n->buf, n->siz);
}
+struct sbrk_descr {
+ void *base;
+ size_t siz;
+};
+
+static struct sbrk_descr sd;
+
static inline void *
alloc_object(size_t siz)
{
void *p;
- p = mmap(0, siz, PROT_READ | PROT_WRITE,
- MAP_PRIVATE | MAP_ANON, -1, 0);
- if (p == MAP_FAILED)
+ sd.base = sbrk(siz);
+ if (sd.base == (void *)-1)
return NULL;
- return p;
-}
-
-static inline void
-free_object(void *p, size_t siz)
-{
- munmap(p, siz);
+ sd.siz += siz;
+ return sd.base;
}
/* Allocate a memory block. Round `siz' to be
@@ -127,7 +128,6 @@ malloc(size_t siz)
}
p = alloc_block(siz);
if (!p) {
- free_object(an, sizeof(*an));
unlock(&rblock);
return NULL;
}