Browse Source

New feature: Count hops.

Ioannis Koutras 13 years ago
parent
commit
e75aad8541

+ 3 - 0
CMakeLists.txt

@@ -45,6 +45,9 @@ endif(BLOCKS_ORGANIZATION STREQUAL "dll")
 message(STATUS "Predefined lists of fixed-sized blocks: " ${WITH_FIXED_LISTS})
 message(STATUS "Heap Ownership per Block: " ${WITH_OWNERSHIP})
 message(STATUS "Have statistics: " ${WITH_STATS})
+if (WITH_STATS)
+  message(STATUS "Count hops per request: " ${COUNT_HOPS})
+endif (WITH_STATS)
 message(STATUS "Have knobs: " ${WITH_KNOBS})
 message(STATUS "Search policy: " ${SEARCH_POLICY})
 if(ALLOC_VAR_FIT OR HEAP_VAR_FIT)

+ 6 - 1
DefineOptions.cmake

@@ -4,6 +4,7 @@ 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_STATS "Build with statistics" OFF)
+option(COUNT_HOPS "Count hops per request" OFF)
 option(WITH_KNOBS "Build with knobs support" OFF)
 option(WITH_ADAPTIVITY "Build with adaptivity" OFF)
 option(WITH_STATIC_LIB "Build a static library" OFF)
@@ -17,7 +18,7 @@ if (NUM_HEAPS GREATER 1)
   set(MULTIPLE_HEAPS ON)
 endif (NUM_HEAPS GREATER 1)
 
-set(WITH_SYSTEM_CALLS "no" "Build with OS call support for more memory")
+set(WITH_SYSTEM_CALLS "no")
 
 set(SEARCH_POLICY "best")
 set(FIT_PERCENTAGE 0.8)
@@ -137,3 +138,7 @@ elseif(WITH_SPLITTING STREQUAL "variable")
   set(SPLITTING_VARIABLE ON)
 endif(WITH_SPLITTING STREQUAL "fixed")
 
+if(COUNT_HOPS)
+ set(WITH_STATS ON)
+endif(COUNT_HOPS)
+

+ 1 - 0
dmm_config.h.in

@@ -36,6 +36,7 @@
 #cmakedefine MIN_SPLITTING_SIZE @MIN_SPLITTING_SIZE@
 
 #cmakedefine WITH_STATS
+#cmakedefine COUNT_HOPS
 
 #cmakedefine WITH_KNOBS
 

+ 3 - 0
include/dmmlib/heap.h

@@ -76,6 +76,9 @@ typedef struct dmmstats_s {
 	uint32_t write_mem_accesses; /**< Number of write accesses. */
 	uint32_t num_malloc; /**< Number of malloc()'s served. */
 	uint32_t num_free; /**< Number of free()'s served. */
+#ifdef COUNT_HOPS
+	size_t total_hops; /**< Number of hops done for a DMM request. */
+#endif /* COUNT_HOPS */
 } dmmstats_t;
 #endif /* WITH_STATS */
 

+ 5 - 0
src/custom_free.c

@@ -63,6 +63,11 @@ void custom_ahfree(allocator_t *allocator, heap_t* heap, void *ptr) {
     posix_lock(heap);
 #endif /* HAVE_LOCKS */
 
+#ifdef COUNT_HOPS
+    /* Initialize the hops counter */
+    heap->dmm_stats.total_hops = 0;
+#endif /* COUNT_HOPS */
+
 #ifdef FUTURE_FEATURES
     remove_block(&ptr, &heap->used_blocks_head);
 #endif /* FUTURE_FEATURES */

+ 5 - 0
src/custom_malloc.c

@@ -74,6 +74,11 @@ void * custom_ahmalloc(allocator_t* allocator, heap_t* heap, size_t size) {
     posix_lock(heap);
 #endif /* HAVE_LOCKS */
 
+#ifdef COUNT_HOPS
+    /* Initialize the hops counter */
+    heap->dmm_stats.total_hops = 0;
+#endif /* COUNT_HOPS */
+
 #ifdef WITH_FIXED_LISTS
     ptr = search_on_fixed(heap, req_padding(size));
 

+ 3 - 0
src/linked_lists/linked_lists.c

@@ -64,6 +64,9 @@ void remove_block(void **block, void **starting_node) {
     /* Traverse a list starting from the starting node until block is found. */
     for(current_node = *starting_node; current_node != NULL; 
             current_node = get_next(current_node)) {
+#ifdef COUNT_HOPS
+        heap->dmm_stats.total_hops++;
+#endif /* COUNT_HOPS */
         if(current_node == *block) {
             if(current_node == *starting_node) {
                 *starting_node = get_next(*block);

+ 17 - 1
src/linked_lists/search_algorithms.c

@@ -23,7 +23,8 @@
 /**
  * \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
- * return the head of this list and set the next block as the new head.
+ * return the head of this list (provided that it is not null) and set the next
+ * block as the new head.
  */
 void * search_on_fixed(heap_t * heap, size_t requested_size) {
     maptable_node_t *node;
@@ -33,6 +34,9 @@ void * search_on_fixed(heap_t * heap, size_t requested_size) {
     ptr = NULL;
 
     while(node) {
+#ifdef COUNT_HOPS
+        heap->dmm_stats.total_hops++;
+#endif /* COUNT_HOPS */
         if(node->size == requested_size) {
             ptr = node->fixed_list_head;
             if(ptr != NULL) {
@@ -73,6 +77,9 @@ void * best_fit_on_freelist(heap_t *heap, size_t requested_size) {
 
     for(current_block = heap->free_list_head; current_block != NULL;
             current_block = get_next(current_block)) {
+#ifdef COUNT_HOPS
+        heap->dmm_stats.total_hops++;
+#endif /* COUNT_HOPS */
         block_size = get_size(current_block);
         if(block_size >= requested_size) {
             if(block_size < best_size) {
@@ -128,6 +135,9 @@ void * good_fit_on_freelist(heap_t *heap, size_t requested_size) {
 
     for(current_block = heap->free_list_head; current_block != NULL;
             current_block = get_next(current_block)) {
+#ifdef COUNT_HOPS
+        heap->dmm_stats.total_hops++;
+#endif /* COUNT_HOPS */
         block_size = get_size(current_block);
         if(block_size >= requested_size) {
             if(block_size < best_size) {
@@ -183,6 +193,9 @@ void * exact_fit_on_freelist(heap_t *heap, size_t requested_size) {
 
     for(current_block = heap->free_list_head; current_block != NULL;
             current_block = get_next(current_block)) {
+#ifdef COUNT_HOPS
+        heap->dmm_stats.total_hops++;
+#endif /* COUNT_HOPS */
         if(get_size(current_block) == requested_size) {
             if(current_block == heap->free_list_head) {
                 heap->free_list_head = get_next(current_block);
@@ -217,6 +230,9 @@ void * first_fit_on_freelist(heap_t *heap, size_t requested_size) {
 
     for(current_block = heap->free_list_head; current_block != NULL;
             current_block = get_next(current_block)) {
+#ifdef COUNT_HOPS
+        heap->dmm_stats.total_hops++;
+#endif /* COUNT_HOPS */
         if(get_size(current_block) >= requested_size) {
             if(current_block == heap->free_list_head) {
                 heap->free_list_head = get_next(current_block);

+ 3 - 0
src/other.c

@@ -46,6 +46,9 @@ int map_size_to_list(heap_t *heap, size_t sz) {
     i = 0;
     node = heap->maptable_head;
     while(node) {
+#ifdef COUNT_HOPS
+        heap->dmm_stats.total_hops++;
+#endif /* COUNT_HOPS */
         if(node->size == sz) {
             return i;
         }

+ 8 - 0
src/sys_alloc.c

@@ -109,6 +109,14 @@ void *sys_alloc(allocator_t *allocator, heap_t *heap, size_t size) {
     }
 #endif /* COALESCING_FIXED || COALESCING_VARIABLE */    
 #else /* WITH_MEMORY_SPACE_AWARENESS */
+
+    /* Iraklis' request: On space-aware memory allocators, each sys_alloc() call
+     * is equivalent to 2 hops.
+     */
+#ifdef COUNT_HOPS
+    heap->dmm_stats.total_hops += 2;
+#endif /* COUNT_HOPS */   
+
     if(allocator->remaining_size >= allocation_size) {
         ptr = (void *) ((char *) allocator->border_ptr + previous_size);
         allocator->remaining_size -= allocation_size;