|
@@ -4,9 +4,9 @@
|
|
|
#ifdef HAVE_LOCKS
|
|
|
#include "posix_lock.h"
|
|
|
#endif /* HAVE_LOCKS */
|
|
|
-#ifdef WITH_COALESCING
|
|
|
+#if defined (COALESCING_FIXED) || defined (COALESCING_VARIABLE)
|
|
|
#include "coalesce.h"
|
|
|
-#endif /* WITH_COALESCING */
|
|
|
+#endif /* COALESCING_FIXED || COALESCING_VARIABLE */
|
|
|
#include "dmm_adaptor.h"
|
|
|
#include "block_header.h"
|
|
|
|
|
@@ -14,10 +14,10 @@ void custom_ahfree(allocator_t *allocator, heap_t* heap, void *ptr) {
|
|
|
size_t size;
|
|
|
int heap_id, fixed_list_id, i;
|
|
|
maptable_node_t *current_maptable_node;
|
|
|
-#ifdef WITH_COALESCING
|
|
|
- void *coalesced_ptr;
|
|
|
+#if defined (COALESCING_FIXED) || defined (COALESCING_VARIABLE)
|
|
|
bool coalesced;
|
|
|
-#endif /* WITH_COALESCING */
|
|
|
+ size_t max_coal_size;
|
|
|
+#endif /* COALESCING_FIXED || COALESCING_VARIABLE */
|
|
|
|
|
|
#ifndef WITH_MEMORY_SPACE_AWARENESS
|
|
|
/* Currently all the memory space aware allocators are pre-initialized */
|
|
@@ -39,15 +39,29 @@ void custom_ahfree(allocator_t *allocator, heap_t* heap, void *ptr) {
|
|
|
|
|
|
remove_block(ptr, heap->used_blocks_head);
|
|
|
|
|
|
-#ifdef WITH_COALESCING
|
|
|
- coalesced_ptr = coalesce(ptr, heap, allocator);
|
|
|
- if(coalesced_ptr != ptr) {
|
|
|
- ptr = coalesced_ptr;
|
|
|
- coalesced = true;
|
|
|
+#if defined (COALESCING_FIXED) || defined (COALESCING_VARIABLE)
|
|
|
+ if(is_previous_free(ptr)) {
|
|
|
+
|
|
|
+#ifdef COALESCING_FIXED
|
|
|
+ max_coal_size = MAX_COALESCE_SIZE;
|
|
|
+#endif /* COALESCING_FIXED */
|
|
|
+#ifdef COALESCING_VARIABLE
|
|
|
+ max_coal_size = heap->dmm_knobs.max_coalesce_size;
|
|
|
+#endif /* COALESCING_VARIABLE */
|
|
|
+
|
|
|
+ if(get_previous_size(ptr) + get_size(ptr) + HEADER_SIZE <=
|
|
|
+ max_coal_size) {
|
|
|
+ ptr = coalesce(ptr, heap, allocator);
|
|
|
+ coalesced = true;
|
|
|
+ } else {
|
|
|
+ mark_free(ptr);
|
|
|
+ coalesced = false;
|
|
|
+ }
|
|
|
} else {
|
|
|
+ mark_free(ptr);
|
|
|
coalesced = false;
|
|
|
}
|
|
|
-#endif /* WITH_COALESCING */
|
|
|
+#endif /* COALESCING_FIXED || COALESCING_VARIABLE */
|
|
|
|
|
|
/* Check if the block could be put in a fixed list */
|
|
|
fixed_list_id = map_size_to_list(heap, size);
|
|
@@ -62,7 +76,7 @@ void custom_ahfree(allocator_t *allocator, heap_t* heap, void *ptr) {
|
|
|
set_next(ptr, current_maptable_node->fixed_list_head);
|
|
|
current_maptable_node->fixed_list_head = ptr;
|
|
|
} else { /* put it in the free list */
|
|
|
-#ifdef WITH_COALESCING
|
|
|
+#if defined (COALESCING_FIXED) || defined (COALESCING_VARIABLE)
|
|
|
/* If the block is coalesced, there is no need to add it to the free
|
|
|
* list as there is already an entry of the old block
|
|
|
*/
|
|
@@ -73,14 +87,9 @@ void custom_ahfree(allocator_t *allocator, heap_t* heap, void *ptr) {
|
|
|
#else
|
|
|
set_next(ptr, heap->free_list_head);
|
|
|
heap->free_list_head = ptr;
|
|
|
-#endif /* WITH_COALESCING */
|
|
|
+#endif /* COALESCING_FIXED || COALESCING_VARIABLE */
|
|
|
}
|
|
|
|
|
|
- /* A coalesced block is already free */
|
|
|
-#ifndef WITH_COALESCING
|
|
|
- mark_free(ptr);
|
|
|
-#endif /* WITH_COALESCING */
|
|
|
-
|
|
|
/* Begin of Stats */
|
|
|
|
|
|
heap->dmm_stats.live_objects -= 1;
|