lib/heap: use 'raw size' to denote the full storage length
The raw size is the length of the memory area which includes both the user data _and_ the meta-data we need for maintaining the heap.
This commit is contained in:
parent
390b6925eb
commit
bcd69eaba5
|
@ -89,7 +89,7 @@ struct evl_heap_extent {
|
|||
struct evl_heap {
|
||||
struct evl_mutex lock;
|
||||
struct list_head extents;
|
||||
size_t arena_size;
|
||||
size_t raw_size;
|
||||
size_t usable_size;
|
||||
size_t used_size;
|
||||
/* Heads of page lists for log2-sized blocks. */
|
||||
|
@ -99,19 +99,19 @@ struct evl_heap {
|
|||
#define __EVL_HEAP_MAP_SIZE(__nrpages) \
|
||||
((__nrpages) * EVL_HEAP_PGMAP_BYTES)
|
||||
|
||||
#define __EVL_HEAP_ARENA_SIZE(__size) \
|
||||
#define __EVL_HEAP_RAW_SIZE(__size) \
|
||||
(__size + \
|
||||
__align_to(sizeof(struct evl_heap_extent) + \
|
||||
__EVL_HEAP_MAP_SIZE((__size) >> EVL_HEAP_PAGE_SHIFT),\
|
||||
EVL_HEAP_MIN_ALIGN))
|
||||
|
||||
/*
|
||||
* Calculate the minimal size of the memory arena needed to contain a
|
||||
* heap of __user_size bytes, including our meta data for managing it.
|
||||
* Usable at build time if __user_size is constant.
|
||||
* Calculate the size of the memory area needed to contain a heap of
|
||||
* __user_size bytes, including our meta-data for managing it. Usable
|
||||
* at build time if __user_size is constant.
|
||||
*/
|
||||
#define EVL_HEAP_ARENA_SIZE(__user_size) \
|
||||
__EVL_HEAP_ARENA_SIZE(__align_to(__user_size, EVL_HEAP_PAGE_SIZE))
|
||||
#define EVL_HEAP_RAW_SIZE(__user_size) \
|
||||
__EVL_HEAP_RAW_SIZE(__align_to(__user_size, EVL_HEAP_PAGE_SIZE))
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -137,7 +137,7 @@ ssize_t evl_check_block(struct evl_heap *heap,
|
|||
static inline
|
||||
size_t evl_heap_raw_size(const struct evl_heap *heap)
|
||||
{
|
||||
return heap->arena_size;
|
||||
return heap->raw_size;
|
||||
}
|
||||
|
||||
static inline
|
||||
|
|
|
@ -1174,7 +1174,7 @@ static ssize_t add_extent(void *mem, size_t size)
|
|||
|
||||
/*
|
||||
* @size must include the overhead memory we need for storing
|
||||
* our meta data as calculated by EVL_HEAP_ARENA_SIZE(), find
|
||||
* our meta-data as calculated by EVL_HEAP_RAW_SIZE(), find
|
||||
* this amount back.
|
||||
*
|
||||
* o = overhead
|
||||
|
@ -1265,7 +1265,7 @@ int evl_init_heap(struct evl_heap *heap, void *mem, size_t size)
|
|||
}
|
||||
|
||||
list_append(&ext->next, &heap->extents);
|
||||
heap->arena_size = size;
|
||||
heap->raw_size = size;
|
||||
heap->usable_size = ret;
|
||||
heap->used_size = 0;
|
||||
|
||||
|
@ -1283,7 +1283,7 @@ int evl_extend_heap(struct evl_heap *heap, void *mem, size_t size)
|
|||
|
||||
evl_lock_mutex(&heap->lock);
|
||||
list_append(&ext->next, &heap->extents);
|
||||
heap->arena_size += size;
|
||||
heap->raw_size += size;
|
||||
heap->usable_size += ret;
|
||||
evl_unlock_mutex(&heap->lock);
|
||||
|
||||
|
|
|
@ -377,7 +377,7 @@ static size_t find_largest_free(size_t free_size, size_t block_size)
|
|||
|
||||
static int test_seq(size_t heap_size, size_t block_size, int flags)
|
||||
{
|
||||
size_t arena_size, user_size, largest_free, maximum_free, freed;
|
||||
size_t raw_size, user_size, largest_free, maximum_free, freed;
|
||||
long alloc_sum_ns, alloc_avg_ns, free_sum_ns, free_avg_ns,
|
||||
alloc_max_ns, free_max_ns, d;
|
||||
int ret, n, k, maxblocks, nrblocks;
|
||||
|
@ -392,17 +392,17 @@ static int test_seq(size_t heap_size, size_t block_size, int flags)
|
|||
pthread_setschedparam(pthread_self(), SCHED_FIFO, ¶m);
|
||||
ret = evl_attach_self("heap-torture:%d", getpid());
|
||||
|
||||
arena_size = EVL_HEAP_ARENA_SIZE(heap_size);
|
||||
mem = malloc(arena_size);
|
||||
raw_size = EVL_HEAP_RAW_SIZE(heap_size);
|
||||
mem = malloc(raw_size);
|
||||
if (mem == NULL)
|
||||
return -ENOMEM;
|
||||
|
||||
maxblocks = heap_size / block_size;
|
||||
|
||||
ret = evl_init_heap(&heap, mem, arena_size);
|
||||
ret = evl_init_heap(&heap, mem, raw_size);
|
||||
if (ret) {
|
||||
do_trace("cannot init heap with arena size %zu",
|
||||
arena_size);
|
||||
do_trace("cannot init heap with raw size %zu",
|
||||
raw_size);
|
||||
goto out;
|
||||
}
|
||||
|
||||
|
@ -649,8 +649,8 @@ out:
|
|||
flags & MEMCHECK_PATTERN ? "" : "no ",
|
||||
flags & MEMCHECK_HOT ? "" : "no ",
|
||||
heap_size / 1024, block_size,
|
||||
arena_size - heap_size,
|
||||
(arena_size * 100.0 / heap_size) - 100.0);
|
||||
raw_size - heap_size,
|
||||
(raw_size * 100.0 / heap_size) - 100.0);
|
||||
oom:
|
||||
free(mem);
|
||||
|
||||
|
|
Loading…
Reference in New Issue