Commit 638d5b36 authored by marko's avatar marko

branches/zip: When creating a memory heap, set the block size to what

was actually obtained from the buddy allocator.  This should avoid some
internal memory fragmentation in mem_heap_create() and mem_heap_alloc().

mem_area_alloc(): Change the in parameter size to an in/out parameter.
Adjust the size based on what was obtained from pool->free_list[].

mem_heap_create_block(): Adjust block->len to what was obtained from
mem_area_alloc().
parent bb97dfee
......@@ -50,9 +50,11 @@ void*
mem_area_alloc(
/*===========*/
/* out, own: allocated memory buffer */
ulint size, /* in: allocated size in bytes; for optimum
ulint* psize, /* in: requested size in bytes; for optimum
space usage, the size should be a power of 2
minus MEM_AREA_EXTRA_SIZE */
minus MEM_AREA_EXTRA_SIZE;
out: allocated size in bytes (greater than
or equal to the requested size) */
mem_pool_t* pool); /* in: memory pool */
/************************************************************************
Frees memory to a pool. */
......
......@@ -334,7 +334,7 @@ mem_heap_create_block(
if (type == MEM_HEAP_DYNAMIC) {
len = MEM_BLOCK_HEADER_SIZE + MEM_SPACE_NEEDED(n);
block = mem_area_alloc(len, mem_comm_pool);
block = mem_area_alloc(&len, mem_comm_pool);
} else {
ut_ad(n <= MEM_MAX_ALLOC_IN_BUF);
......@@ -342,7 +342,7 @@ mem_heap_create_block(
if (len < UNIV_PAGE_SIZE / 2) {
block = mem_area_alloc(len, mem_comm_pool);
block = mem_area_alloc(&len, mem_comm_pool);
} else {
len = UNIV_PAGE_SIZE;
......
......@@ -324,15 +324,19 @@ void*
mem_area_alloc(
/*===========*/
/* out, own: allocated memory buffer */
ulint size, /* in: allocated size in bytes; for optimum
ulint* psize, /* in: requested size in bytes; for optimum
space usage, the size should be a power of 2
minus MEM_AREA_EXTRA_SIZE */
minus MEM_AREA_EXTRA_SIZE;
out: allocated size in bytes (greater than
or equal to the requested size) */
mem_pool_t* pool) /* in: memory pool */
{
mem_area_t* area;
ulint size;
ulint n;
ibool ret;
size = *psize;
n = ut_2_log(ut_max(size + MEM_AREA_EXTRA_SIZE, MEM_AREA_MIN_SIZE));
mutex_enter(&(pool->mutex));
......@@ -403,8 +407,9 @@ mem_area_alloc(
mutex_exit(&(pool->mutex));
ut_ad(mem_pool_validate(pool));
UNIV_MEM_ALLOC(MEM_AREA_EXTRA_SIZE + (byte*)area,
ut_2_exp(n) - MEM_AREA_EXTRA_SIZE);
*psize = ut_2_exp(n) - MEM_AREA_EXTRA_SIZE;
UNIV_MEM_ALLOC(MEM_AREA_EXTRA_SIZE + (byte*)area, *psize);
return((void*)(MEM_AREA_EXTRA_SIZE + ((byte*)area)));
}
......
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