From 9a0081b8565669e141d99124823fee3dfe7bcd9d Mon Sep 17 00:00:00 2001 From: Ruben Ayrapetyan Date: Mon, 24 Nov 2014 18:47:48 +0300 Subject: [PATCH] Splitting free block from end if block search direction is backward (currently, for short-term blocks). --- src/liballocator/mem-heap.c | 66 +++++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 18 deletions(-) diff --git a/src/liballocator/mem-heap.c b/src/liballocator/mem-heap.c index c1c5df8c9..6dcc38514 100644 --- a/src/liballocator/mem-heap.c +++ b/src/liballocator/mem-heap.c @@ -475,31 +475,61 @@ mem_heap_alloc_block (size_t size_in_bytes, /**< size of region to all { MEM_HEAP_STAT_FREE_BLOCK_SPLIT (); - uint8_t *new_free_block_first_chunk_p = (uint8_t*) block_p + new_block_size_in_chunks * MEM_HEAP_CHUNK_SIZE; - mem_init_block_header (new_free_block_first_chunk_p, - 0, - MEM_BLOCK_FREE, - block_p, - next_block_p); - - mem_block_header_t *new_free_block_p = (mem_block_header_t*) new_free_block_first_chunk_p; - - if (next_block_p == NULL) + if (direction == MEM_DIRECTION_PREV) { - mem_heap.last_block_p = new_free_block_p; + prev_block_p = block_p; + uint8_t *block_end_p = (uint8_t*) block_p + found_block_size_in_chunks * MEM_HEAP_CHUNK_SIZE; + block_p = (mem_block_header_t*) (block_end_p - new_block_size_in_chunks * MEM_HEAP_CHUNK_SIZE); + + VALGRIND_DEFINED_STRUCT(prev_block_p); + + prev_block_p->neighbours[ MEM_DIRECTION_NEXT ] = mem_get_block_neighbour_field (prev_block_p, + block_p); + + VALGRIND_NOACCESS_STRUCT(prev_block_p); + + if (next_block_p == NULL) + { + mem_heap.last_block_p = block_p; + } + else + { + VALGRIND_DEFINED_STRUCT(next_block_p); + + next_block_p->neighbours[ MEM_DIRECTION_PREV ] = mem_get_block_neighbour_field (block_p, + next_block_p); + + VALGRIND_NOACCESS_STRUCT(next_block_p); + } } else { - VALGRIND_DEFINED_STRUCT(next_block_p); + uint8_t *new_free_block_first_chunk_p = (uint8_t*) block_p + new_block_size_in_chunks * MEM_HEAP_CHUNK_SIZE; + mem_init_block_header (new_free_block_first_chunk_p, + 0, + MEM_BLOCK_FREE, + block_p, + next_block_p); - const mem_block_header_t* new_free_block_p = (mem_block_header_t*) new_free_block_first_chunk_p; - next_block_p->neighbours[ MEM_DIRECTION_PREV ] = mem_get_block_neighbour_field (new_free_block_p, - next_block_p); + mem_block_header_t *new_free_block_p = (mem_block_header_t*) new_free_block_first_chunk_p; - VALGRIND_NOACCESS_STRUCT(next_block_p); + if (next_block_p == NULL) + { + mem_heap.last_block_p = new_free_block_p; + } + else + { + VALGRIND_DEFINED_STRUCT(next_block_p); + + const mem_block_header_t* new_free_block_p = (mem_block_header_t*) new_free_block_first_chunk_p; + next_block_p->neighbours[ MEM_DIRECTION_PREV ] = mem_get_block_neighbour_field (new_free_block_p, + next_block_p); + + VALGRIND_NOACCESS_STRUCT(next_block_p); + } + + next_block_p = new_free_block_p; } - - next_block_p = new_free_block_p; } mem_init_block_header ((uint8_t*) block_p,