|
@@ -24,6 +24,11 @@ void split(allocator_t *allocator, heap_t *heap, void *ptr,
|
|
|
size_t req_size) {
|
|
|
void *new_block;
|
|
|
size_t new_block_size;
|
|
|
+#ifdef COALESCE_AFTER_SPLIT
|
|
|
+ size_t max_coal_size;
|
|
|
+ void *next_block;
|
|
|
+ size_t current_next_size;
|
|
|
+#endif /* COALESCE_AFTER_SPLIT */
|
|
|
#ifdef WITH_FIXED_LISTS
|
|
|
int fixed_list_id, i;
|
|
|
maptable_node_t *current_maptable_node;
|
|
@@ -35,6 +40,41 @@ void split(allocator_t *allocator, heap_t *heap, void *ptr,
|
|
|
/* Resize the previous, to be used block */
|
|
|
set_size_and_used(allocator, ptr, req_size);
|
|
|
|
|
|
+#ifdef COALESCE_AFTER_SPLIT
|
|
|
+ /* Try to coalesce with the next block if it is free */
|
|
|
+#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 */
|
|
|
+
|
|
|
+ next_block = get_dlnext(allocator, ptr);
|
|
|
+ if(next_block != NULL) {
|
|
|
+ if(is_free(next_block) == true) {
|
|
|
+#ifdef WITH_OWNERSHIP
|
|
|
+ if(get_owner(next_block) == get_owner(ptr)) {
|
|
|
+#endif /* WITH_OWNERSHIP */
|
|
|
+ current_next_size = new_block_size + get_size(next_block) +
|
|
|
+ HEADER_SIZE;
|
|
|
+ if(current_next_size <= max_coal_size) {
|
|
|
+ /* it's ok to coalesce the new split block with the next
|
|
|
+ * free block
|
|
|
+ */
|
|
|
+ remove_block_from_lists(&next_block, heap);
|
|
|
+ if(allocator->border_ptr == next_block) {
|
|
|
+ allocator->border_ptr = ptr;
|
|
|
+ }
|
|
|
+ new_block_size = current_next_size;
|
|
|
+ }
|
|
|
+#ifdef WITH_OWNERSHIP
|
|
|
+ }
|
|
|
+#endif /* WITH_OWNERSHIP */
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+#endif /* COALESCE_AFTER_SPLIT */
|
|
|
+
|
|
|
set_size_and_free(allocator, new_block, new_block_size);
|
|
|
set_previous_size_availability(new_block, get_size_availability(ptr));
|
|
|
|