diff options
author | Miles Bader <miles@lsi.nec.co.jp> | 2002-07-23 06:50:40 +0000 |
---|---|---|
committer | Miles Bader <miles@lsi.nec.co.jp> | 2002-07-23 06:50:40 +0000 |
commit | 83cef9f931bcd2030f42079c332525e1e73ab6aa (patch) | |
tree | 5867067ac5387998a301f69a59ca6d78b26680d5 /libc/stdlib/malloc/malloc.h | |
parent | a9752043dd652d0fb4addf947b76e57c588f430c (diff) |
* Automatically try to unmap heap free-areas when they get very big.
* Instead of using mmap/munmap directly for large allocations, just use
the heap for everything (this is reasonable now that heap memory can
be unmapped).
* Use sbrk instead of mmap/munmap on systems with an MMU.
Diffstat (limited to 'libc/stdlib/malloc/malloc.h')
-rw-r--r-- | libc/stdlib/malloc/malloc.h | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/libc/stdlib/malloc/malloc.h b/libc/stdlib/malloc/malloc.h index 187477a67..0cab1dba2 100644 --- a/libc/stdlib/malloc/malloc.h +++ b/libc/stdlib/malloc/malloc.h @@ -23,11 +23,26 @@ satisfy a particularly big request). */ #define MALLOC_HEAP_EXTEND_SIZE MALLOC_PAGE_SIZE -/* The threshold above which blocks are allocated/freed with mmap/munmap, - rather than using the heap. */ -#define MALLOC_MMAP_THRESHOLD (8*MALLOC_PAGE_SIZE) +/* When a heap free-area grows above this size, try to unmap it, releasing + the memory back to the system. */ +#define MALLOC_UNMAP_THRESHOLD (8*MALLOC_PAGE_SIZE) +/* When unmapping a free-area, retain this many bytes if it's the only one, + to avoid completely emptying the heap. This is only a heuristic -- the + existance of another free area, even if it's smaller than + MALLOC_MIN_SIZE, will cause us not to reserve anything. */ +#define MALLOC_MIN_SIZE (2*MALLOC_PAGE_SIZE) +/* For systems with an MMU, use sbrk to map/unmap memory for the malloc + heap, instead of mmap/munmap. This is a tradeoff -- sbrk is faster than + mmap/munmap, and guarantees contiguous allocation, but is also less + flexible, and causes the heap to only be shrinkable from the end. */ +#ifdef __UCLIBC_HAS_MMU__ +#define MALLOC_USE_SBRK +#endif + + +/* Change this to `#if 1' to cause malloc to emit debugging info to stderr. */ #if 0 #include <stdio.h> #define MALLOC_DEBUG(fmt, args...) fprintf (stderr, fmt , ##args) @@ -36,10 +51,20 @@ #endif +/* Return SZ rounded down to POWER_OF_2_SIZE (which must be power of 2). */ +#define MALLOC_ROUND_DOWN(sz, power_of_2_size) \ + ((sz) & ~(power_of_2_size - 1)) +/* Return SZ rounded to POWER_OF_2_SIZE (which must be power of 2). */ +#define MALLOC_ROUND_UP(sz, power_of_2_size) \ + MALLOC_ROUND_DOWN ((sz) + (power_of_2_size - 1), (power_of_2_size)) + +/* Return SZ rounded down to a multiple MALLOC_PAGE_SIZE. */ +#define MALLOC_ROUND_DOWN_TO_PAGE_SIZE(sz) \ + MALLOC_ROUND_DOWN (sz, MALLOC_PAGE_SIZE) /* Return SZ rounded up to a multiple MALLOC_PAGE_SIZE. */ #define MALLOC_ROUND_UP_TO_PAGE_SIZE(sz) \ - (((sz) + (MALLOC_PAGE_SIZE - 1)) & ~(MALLOC_PAGE_SIZE - 1)) + MALLOC_ROUND_UP (sz, MALLOC_PAGE_SIZE) -/* The heap used for small allocations. */ +/* The malloc heap. */ extern struct heap __malloc_heap; |