Browse Source

Fixed coalescing. Larson does not require more memory than the current page size.

Ioannis Koutras 13 years ago
parent
commit
19ba68f2bc
3 changed files with 28 additions and 67 deletions
  1. 1 1
      DefineOptions.cmake
  2. 1 1
      examples/larson.c
  3. 26 65
      src/coalesce.c

+ 1 - 1
DefineOptions.cmake

@@ -70,7 +70,7 @@ endif (LEON3)
 
 if (LINUXTEST)
   set(WITH_SYSTEM_CALLS "mmap")
-  set(SYS_ALLOC_SIZE 32000000)
+  set(SYS_ALLOC_SIZE 1024000000)
   set(WITH_FIXED_LISTS OFF)
   set(SORT_POLICY "fifo")
   set(SEARCH_POLICY "first")

+ 1 - 1
examples/larson.c

@@ -307,7 +307,7 @@ int main(void) {
     printf("chunk size (min,max): ") ;
     //scanf("%d %d", &min_size, &max_size ) ;
     min_size = 32;
-    max_size = 768;
+    max_size = 64;
     printf("%d %d\n", min_size, max_size);
 
     printf("threads (min, max):   ") ; 

+ 26 - 65
src/coalesce.c

@@ -15,7 +15,6 @@
  *
  */
 
-#include <stdio.h>
 #include "coalesce.h"
 #include "block_header.h"
 #include "other.h"
@@ -100,74 +99,36 @@ bool coalesce(allocator_t **allocator, heap_t *heap, void **ptr) {
         three_blocks_size = (size_t) -1; /* SIZE_MAX */
     }
 
-    /* /1* Check if Previous + Current + Next is ok *1/ */
-    /* if(three_blocks_size <= max_coal_size) { */
-    /*     /1* If previous block is on a fixed list, remove it *1/ */
-/* #ifdef WITH_FIXED_LISTS */
-    /*     /1* Check if it is a block of a fixed list *1/ */
-    /*     fixed_list_id = map_size_to_list(heap, get_size(previous_block)); */
-    /*     if(fixed_list_id != -1) { */
-    /*         /1* If it is, find the fixed list and remove the block *1/ */
-    /*         current_maptable_node = heap->maptable_head; */
-    /*         if(fixed_list_id != 0) { */
-    /*             for(i = 1; i < fixed_list_id; i++) { */
-    /*                 current_maptable_node = current_maptable_node->next; */
-    /*             } */
-    /*         } */
-/* #ifdef COUNT_HOPS */
-    /*         remove_block(heap, ptr, &current_maptable_node->fixed_list_head); */
-/* #else */
-    /*         remove_block(ptr, &current_maptable_node->fixed_list_head); */
-/* #endif /1* COUNT_HOPS *1/ */
-    /*     } */
-/* #endif /1* WITH_FIXED_LISTS *1/ */
-    /*     /1* Remove the next block from any freelist *1/ */
-    /*     remove_block_from_lists(&next_block, heap); */
-    /*     /1* Update border pointer if the next block was the border pointer *1/ */
-    /*     if(allocator->border_ptr == next_block) { */
-    /*         allocator->border_ptr = previous_block; */
-    /*     } */
-    /*     /1* Reset the previous block size *1/ */
-    /*     set_size_and_free(allocator, previous_block, three_blocks_size); */
-    /*     return true; */
-    /* } */
+    /* Check if Previous + Current + Next is ok */
+    if(three_blocks_size <= max_coal_size) {
+        remove_block_from_lists(&previous_block, heap);
+        /* Remove the next block from any freelist */
+        remove_block_from_lists(&next_block, heap);
+        /* Update border pointer if the next block was the border pointer */
+        if((*allocator)->border_ptr == next_block) {
+            (*allocator)->border_ptr = previous_block;
+        }
+        /* Reset the previous block size */
+        set_size_and_free(*allocator, previous_block, three_blocks_size);
+        return false;
+    }
 
-    /* /1* Check if Previous + Current is ok *1/ */
-    /* if(previous_current_size <= max_coal_size) { */
-    /*     /1* If previous block is on a fixed list, remove it *1/ */
-/* #ifdef WITH_FIXED_LISTS */
-    /*     /1* Check if it is a block of a fixed list *1/ */
-    /*     fixed_list_id = map_size_to_list(heap, get_size(previous_block)); */
-    /*     if(fixed_list_id != -1) { */
-    /*         /1* If it is, find the fixed list and remove the block *1/ */
-    /*         current_maptable_node = heap->maptable_head; */
-    /*         if(fixed_list_id != 0) { */
-    /*             for(i = 1; i < fixed_list_id; i++) { */
-    /*                 current_maptable_node = current_maptable_node->next; */
-    /*             } */
-    /*         } */
-/* #ifdef COUNT_HOPS */
-    /*         remove_block(heap, ptr, &current_maptable_node->fixed_list_head); */
-/* #else */
-    /*         remove_block(ptr, &current_maptable_node->fixed_list_head); */
-/* #endif /1* COUNT_HOPS *1/ */
-    /*     } */
-/* #endif /1* WITH_FIXED_LISTS *1/ */
-    /*     /1* Update border pointer if the current block was the border pointer *1/ */
-    /*     if((allocator)->border_ptr == *ptr) { */
-    /*         (allocator)->border_ptr = previous_block; */
-    /*     } */
-    /*     /1* Reset the previous block size *1/ */
-    /*     set_size_and_free(allocator, *ptr, previous_current_size); */
-    /*     return true; */
-    /* } */
+    /* Check if Previous + Current is ok */
+    if(previous_current_size <= max_coal_size) {
+        /* printf("pcs\n"); */
+        remove_block_from_lists(*ptr, heap);
+        /* Update border pointer if the current block was the border pointer */
+        if((*allocator)->border_ptr == *ptr) {
+            (*allocator)->border_ptr = previous_block;
+        }
+        /* Reset the previous block size */
+        set_size_and_free(*allocator, *ptr, previous_current_size);
+        return false;
+    }
  
     /* Check if Current + Next is ok */
     if(current_next_size <= max_coal_size) {
-        printf("cnsize = %zu\n", current_next_size);
-        if(get_size(next_block) == 0) {
-            printf("danger!\n");
-        }
+        /* printf("cn\n"); */
         remove_block_from_lists(&next_block, heap);
         if((*allocator)->border_ptr == next_block) {
             (*allocator)->border_ptr = *ptr;