Browse Source

Created options for enabling fixed lists and adaptive functions.

Ioannis Koutras 14 years ago
parent
commit
a60756d022

+ 5 - 0
DefineOptions.cmake

@@ -1,7 +1,9 @@
 option(HAVE_LOCKS "Build with POSIX locking mechanisms" ON)
 option(WITH_EXAMPLES "Build with examples" OFF)
 option(WITH_MEMORY_SPACE_AWARENESS "Build with memory space awareness" OFF)
+option(WITH_FIXED_LISTS "Build with predefined lists of fixed-sized blocks" ON)
 option(WITH_KNOBS "Build with knobs support" OFF)
+option(WITH_ADAPTIVITY "Build with adaptivity" OFF)
 option(WITH_STATIC_LIB "Build a static library" OFF)
 option(WITH_SHARED_LIB "Build a shared library" OFF)
 option(WITH_DOC "Build with documentation" OFF)
@@ -24,6 +26,7 @@ if (P2012)
   set(WITH_STATIC_LIB ON)
   set(NUM_HEAPS 1)
   set(LINUXTEST OFF)
+  set(WITH_FIXED_LISTS OFF)
   set(WITH_COALESCING "never")
   set(WITH_SPLITTING "never")
   set(BLOCKS_ORGANIZATION "sll")
@@ -51,6 +54,7 @@ if(WITH_COALESCING STREQUAL "fixed")
   set(WITH_OWNERSHIP ON)
   set(COALESCING_FIXED ON)
 elseif(WITH_COALESCING STREQUAL "variable")
+  set(WITH_KNOBS ON)
   set(WITH_OWNERSHIP ON)
   set(COALESCING_VARIABLE ON)
 endif(WITH_COALESCING STREQUAL "fixed")
@@ -58,6 +62,7 @@ endif(WITH_COALESCING STREQUAL "fixed")
 if(WITH_SPLITTING STREQUAL "fixed")
   set(SPLITTING_FIXED ON)
 elseif(WITH_SPLITTING STREQUAL "variable")
+  set(WITH_KNOBS ON)
   set(SPLITTING_VARIABLE ON)
 endif(WITH_SPLITTING STREQUAL "fixed")
 

+ 4 - 0
dmm_config.h.in

@@ -7,6 +7,8 @@
 /** The number of the heaps. */
 #cmakedefine NUM_HEAPS @NUM_HEAPS@
 
+#cmakedefine WITH_FIXED_LISTS
+
 #cmakedefine COALESCING_FIXED
 #cmakedefine COALESCING_VARIABLE
 
@@ -19,6 +21,8 @@
 
 #cmakedefine WITH_KNOBS
 
+#cmakedefine WITH_ADAPTIVITY
+
 #cmakedefine BLOCKS_IN_SLL
 #cmakedefine BLOCKS_IN_DLL
 

+ 2 - 0
include/dmmlib/heap.h

@@ -87,7 +87,9 @@ typedef struct dmmknobs_s {
 
 /** A structure to store heap information. */
 typedef struct heap_s {
+#ifdef WITH_FIXED_LISTS
 	maptable_node_t *maptable_head; /**< The head of the maptable list. */
+#endif /* WITH_FIXED_LISTS */
 	void *free_list_head; /**< The head of the free list. */
 	void *used_blocks_head; /**< The head of the used blocks list. */
 	void *rov_ptr; /**< Roving pointer. */

+ 3 - 0
private-include/linked_lists/search_algorithms.h

@@ -27,7 +27,9 @@
 #define LINKED_LISTS_SEARCH_ALGORITHMS_H
 
 #include <dmmlib/heap.h>
+#include <dmm_config.h>
 
+#ifdef WITH_FIXED_LISTS
 /**
  * Perform an exact-fit search on fixed lists for a block of a certain size
  *
@@ -38,6 +40,7 @@
  * \retval NULL No block was found.
  */
 void * search_on_fixed(heap_t * heap, size_t requested_size);
+#endif /* WITH_FIXED_LISTS */
 
 void * best_fit_on_freelist(heap_t *heap, size_t requested_size);
 void * exact_fit_on_freelist(heap_t *heap, size_t requested_size);

+ 2 - 0
private-include/other.h

@@ -23,7 +23,9 @@
 
 size_t req_padding(size_t size);
 
+#ifdef WITH_FIXED_LISTS
 int map_size_to_list(heap_t *heap, size_t sz);
+#endif /* WITH_FIXED_LISTS */
 
 #ifndef WITH_MEMORY_SPACE_AWARENESS
 int map_thread_heap(void);

+ 7 - 1
src/CMakeLists.txt

@@ -37,7 +37,6 @@ set(dmmlib_SRCS
   other.c
   initialize_allocator.c
   sys_alloc.c
-  #  dmm_adaptor.c
   print_stats.c
 )
 
@@ -63,6 +62,13 @@ if (SPLITTING_FIXED OR SPLITTING_VARIABLE)
   )
 endif (SPLITTING_FIXED OR SPLITTING_VARIABLE)
 
+if (WITH_ADAPTIVITY)
+  set(dmmlib_SRCS
+    ${dmmlib_SRCS}
+    dmm_adaptor.c
+  )
+endif (WITH_ADAPTIVITY)
+
 include_directories(
   ${DMMLIB_PUBLIC_INCLUDE_DIRS}
   ${DMMLIB_PRIVATE_INCLUDE_DIRS}

+ 3 - 0
src/coalesce.c

@@ -19,6 +19,7 @@
 #include "coalesce.h"
 #include "block_header.h"
 #include "other.h"
+#include "dmm_config.h"
 
 void * coalesce(void *ptr, heap_t *heap, allocator_t *allocator) {
     void *prev;
@@ -27,6 +28,7 @@ void * coalesce(void *ptr, heap_t *heap, allocator_t *allocator) {
 
     prev = get_dlprevious(ptr);
 
+#ifdef WITH_FIXED_LISTS
     // Check if it is a block of a fixed list
     fixed_list_id = map_size_to_list(heap, get_size(prev));
     if(fixed_list_id != -1) {
@@ -39,6 +41,7 @@ void * coalesce(void *ptr, heap_t *heap, allocator_t *allocator) {
         }
         remove_block(ptr, current_maptable_node->fixed_list_head);
     }
+#endif /* WITH_FIXED_LISTS */
 
     // Set the new size
     // Note: the rest of the header variables will be set on free().

+ 10 - 5
src/custom_free.c

@@ -16,7 +16,6 @@
  */
 
 #include <dmmlib/dmmlib.h>
-#include "dmm_config.h"
 #include "other.h"
 #ifdef HAVE_LOCKS
 #include "posix_lock.h"
@@ -24,15 +23,17 @@
 #if defined (COALESCING_FIXED) || defined (COALESCING_VARIABLE)
 #include "coalesce.h"
 #endif /* COALESCING_FIXED || COALESCING_VARIABLE */
-#ifdef WITH_KNOBS
+#ifdef WITH_ADAPTIVITY
 #include "dmm_adaptor.h"
-#endif /* WITH_KNOBS */
+#endif /* WITH_ADAPTIVITY */
 #include "block_header.h"
 
 void custom_ahfree(allocator_t *allocator, heap_t* heap, void *ptr) {
     size_t size;
+#ifdef WITH_FIXED_LISTS
     int fixed_list_id, i;
     maptable_node_t *current_maptable_node;
+#endif /* WITH_FIXED_LISTS */
 #if defined (COALESCING_FIXED) || defined (COALESCING_VARIABLE)
     bool coalesced;
     size_t max_coal_size;
@@ -88,6 +89,7 @@ void custom_ahfree(allocator_t *allocator, heap_t* heap, void *ptr) {
     }
 #endif /* COALESCING_FIXED || COALESCING_VARIABLE */
 
+#ifdef WITH_FIXED_LISTS
     /* Check if the block could be put in a fixed list */
     fixed_list_id = map_size_to_list(heap, size);
 
@@ -100,6 +102,7 @@ void custom_ahfree(allocator_t *allocator, heap_t* heap, void *ptr) {
         }
         push_block(ptr, current_maptable_node->fixed_list_head);
     } else { /* put it in the free list */
+#endif /* WITH_FIXED_LISTS */
 #if defined (COALESCING_FIXED) || defined (COALESCING_VARIABLE)
         /* The block should be added to the free list only if it is not
          * coalesced
@@ -110,7 +113,9 @@ void custom_ahfree(allocator_t *allocator, heap_t* heap, void *ptr) {
 #else
         push_block(ptr, heap->free_list_head);
 #endif /* COALESCING_FIXED || COALESCING_VARIABLE */
+#ifdef WITH_FIXED_LISTS
     }
+#endif /* WITH_FIXED_LISTS */
 
     /* Update Stats */
     heap->dmm_stats.live_objects -= 1;
@@ -118,7 +123,7 @@ void custom_ahfree(allocator_t *allocator, heap_t* heap, void *ptr) {
 
     /* End of Stats */
 
-#ifdef WITH_KNOBS
+#ifdef WITH_ADAPTIVITY
     /* Refresh the state of the heap allocator if a certain number of
      * free's has been served already
      */
@@ -126,7 +131,7 @@ void custom_ahfree(allocator_t *allocator, heap_t* heap, void *ptr) {
     if(heap->dmm_stats.num_free % 100) {
         free_state_refresh(heap);
     }
-#endif /* WITH_KNOBS */
+#endif /* WITH_ADAPTIVITY */
 
 #ifdef HAVE_LOCKS
     posix_unlock(heap);

+ 6 - 4
src/custom_malloc.c

@@ -29,9 +29,9 @@
 #include "linked_lists/search_algorithms.h"
 #include "sys_alloc.h"
 #include "block_header.h"
-#ifdef WITH_KNOBS
+#ifdef WITH_ADAPTIVITY
 #include "dmm_adaptor.h"
-#endif /* WITH_KNOBS */
+#endif /* WITH_ADAPTIVITY */
 
 void * custom_ahmalloc(allocator_t* allocator, heap_t* heap, size_t size) {
     void *ptr;
@@ -64,7 +64,9 @@ void * custom_ahmalloc(allocator_t* allocator, heap_t* heap, size_t size) {
     posix_lock(heap);
 #endif /* HAVE_LOCKS */
 
+#ifdef WITH_FIXED_LISTS
     ptr = search_on_fixed(heap, req_padding(size));
+#endif /* WITH_FIXED_LISTS */
 
     if(ptr == NULL) {
        ptr = best_fit_on_freelist(heap, size);
@@ -108,7 +110,7 @@ void * custom_ahmalloc(allocator_t* allocator, heap_t* heap, size_t size) {
         ptr = sys_alloc(allocator, heap, size);
     }
 
-#ifdef WITH_KNOBS
+#ifdef WITH_ADAPTIVITY
     /* Refresh the state of the heap allocator if a certain number of
      * malloc's has been served already
      */
@@ -116,7 +118,7 @@ void * custom_ahmalloc(allocator_t* allocator, heap_t* heap, size_t size) {
     if(heap->dmm_stats.num_malloc % 50) {
         malloc_state_refresh(heap);
     }
-#endif /* WITH_KNOBS */
+#endif /* WITH_ADAPTIVITY */
 
 #ifdef HAVE_LOCKS
     posix_unlock(heap);

+ 8 - 10
src/initialize_allocator.c

@@ -15,14 +15,13 @@
  *
  */
 
-#include "dmm_config.h"
 #ifndef WITH_MEMORY_SPACE_AWARENESS
 #include <unistd.h>
 #endif /* WITH_MEMORY_SPACE_AWARENESS */
+#include <dmmlib/initialize_allocator.h>
 #ifdef HAVE_LOCKS
 #include "posix_lock.h"
 #endif /* HAVE_LOCKS */
-#include <dmmlib/initialize_allocator.h>
 #include "sys_alloc.h"
 
 #ifdef WITH_MEMORY_SPACE_AWARENESS
@@ -32,15 +31,19 @@ void initialize_allocator(allocator_t *allocator, void *starting_address,
 void initialize_allocator(allocator_t *allocator) {
 #endif /* WITH_MEMORY_SPACE_AWARENESS */
     int i;
+#ifdef WITH_FIXED_LISTS
     heap_t *current_heap;
     maptable_node_t *maptablenode;
+#endif /* WITH_FIXED_LISTS */
 
 #ifdef HAVE_LOCKS
     sbrk_lock();
 #endif /* HAVE_LOCKS */
 
     for(i = 0; i < NUM_HEAPS; i++) {
+#ifdef WITH_FIXED_LISTS
         allocator->heaps[i].maptable_head = NULL;
+#endif /* WITH_FIXED_LISTS */
         allocator->heaps[i].free_list_head = NULL;
         allocator->heaps[i].used_blocks_head = NULL;
         allocator->heaps[i].rov_ptr = NULL;
@@ -81,6 +84,8 @@ void initialize_allocator(allocator_t *allocator) {
     allocator->remaining_size = size;
 #endif /* WITH_MEMORY_SPACE_AWARENESS */
 
+#ifdef WITH_FIXED_LISTS
+
     /* Custom number of fixed lists and their initialization
      * 2 first ones with 32, 64, 128 and 256 (4 fixed lists per heap)
      * 2 last ones with 64 and 256 (2 fixed lists per heap)
@@ -88,16 +93,8 @@ void initialize_allocator(allocator_t *allocator) {
      */
     current_heap = &allocator->heaps[0];
 
-#ifdef HAVE_LOCKS
-    sbrk_unlock();
-#endif /* HAVE_LOCKS */
- 
     maptablenode = (maptable_node_t *) sys_alloc(allocator, &allocator->heaps[0], 12*(sizeof(maptable_node_t)));
 
-#ifdef HAVE_LOCKS
-    sbrk_lock();
-#endif /* HAVE_LOCKS */
- 
     maptablenode->size = 32;
     maptablenode->fixed_list_head = NULL;
     maptablenode->next = maptablenode+1;
@@ -144,6 +141,7 @@ void initialize_allocator(allocator_t *allocator) {
     (maptablenode+1)->size = 256;
     (maptablenode+1)->fixed_list_head = NULL;
     (maptablenode+1)->next = NULL;
+#endif /* WITH_FIXED_LISTS */
 
     allocator->initialized = true;
 

+ 2 - 0
src/linked_lists/search_algorithms.c

@@ -18,6 +18,7 @@
 #include "linked_lists/search_algorithms.h"
 #include "block_header.h"
 
+#ifdef WITH_FIXED_LISTS
 /**
  * \details The maptable of the heap is being traversed sequentially while
  * searching for a size equal of the requested size. If one is found, then we
@@ -46,6 +47,7 @@ void * search_on_fixed(heap_t * heap, size_t requested_size) {
 
     return ptr;
 }
+#endif /* WITH_FIXED_LISTS */
 
 /**
  * \details In order to remove a block from a singly linked list, we need to

+ 4 - 0
src/other.c

@@ -38,6 +38,8 @@ size_t req_padding(size_t size) {
     return size;
 }
 
+#ifdef WITH_FIXED_LISTS
+
 int map_size_to_list(heap_t *heap, size_t sz) {
     int i;
     maptable_node_t *node;
@@ -53,6 +55,8 @@ int map_size_to_list(heap_t *heap, size_t sz) {
     return -1;
 }
 
+#endif /* WITH_FIXED_LISTS */
+
 #ifndef WITH_MEMORY_SPACE_AWARENESS
 
 /* Random assignment */

+ 5 - 0
src/split.c

@@ -18,6 +18,7 @@
 #include "block_header.h"
 #include "other.h"
 #include "split.h"
+#include "dmm_config.h"
 
 void split(allocator_t *allocator, heap_t *heap, void *ptr,
         size_t new_block_size) {
@@ -36,6 +37,7 @@ void split(allocator_t *allocator, heap_t *heap, void *ptr,
     set_size(new_block, new_block_size);
     set_previous_size_availability(new_block, get_size_availability(ptr));
 
+#ifdef WITH_FIXED_LISTS
     /* FIXME code from custom_free, some refactoring maybe?
      * Be careful, custom_free also does coalescing, we don't need that
      */
@@ -52,8 +54,11 @@ void split(allocator_t *allocator, heap_t *heap, void *ptr,
         }
         push_block(new_block, current_maptable_node->fixed_list_head);
     } else { /* put it in the free list */
+#endif /* WITH_FIXED_LISTS */
         push_block(new_block, heap->free_list_head);
+#ifdef WITH_FIXED_LISTS
     }
+#endif /* WITH_FIXED_LISTS */
 
     set_owner(new_block, heap);
     mark_free(new_block);