Selaa lähdekoodia

The knobs are now guarded with WITH_KNOBS.

Ioannis Koutras 14 vuotta sitten
vanhempi
commit
7744f89706
6 muutettua tiedostoa jossa 13 lisäystä ja 13 poistoa
  1. 7 1
      include/dmmlib/heap.h
  2. 0 1
      src/CMakeLists.txt
  3. 0 11
      src/coalesce.c
  4. 2 0
      src/custom_free.c
  5. 2 0
      src/custom_malloc.c
  6. 2 0
      src/initialize_allocator.c

+ 7 - 1
include/dmmlib/heap.h

@@ -47,13 +47,16 @@ typedef struct dmmstats_s {
 	uint32_t num_free; /**< Number of free()'s served. */
 } dmmstats_t;
 
+#ifdef WITH_KNOBS
 /** A structure to represent tunable parameters of a heap */
 typedef struct dmmknobs_s {
 	float frag_threshold; /**< Fragmentation threshold to enable coalescing
 				or not. */ 
 	uint32_t mem_threshold; /**< Memory size threshold. */
-	int32_t max_coalesce_size; /**< Maximum coalesce size; -1 if coalescing
+#ifdef COALESCING
+	size_t max_coalesce_size; /**< Maximum coalesce size; -1 if coalescing
 				     is not supported */
+#endif /* COALESCING */
 	uint32_t min_split_size; /**< Minimum split size. */
 	/* FIXME Need to find explanation */
 	float empty_threshold; /**< Empty Threshold */
@@ -61,6 +64,7 @@ typedef struct dmmknobs_s {
 	knob_state_t frag_state; /**< The current state of fragmentation. */
 	knob_state_t foot_state; /**< The current state of footprint. */
 } dmmknobs_t;
+#endif /* WITH_KNOBS */
 
 /** A structure to store heap information. */
 typedef struct heap_s {
@@ -70,7 +74,9 @@ typedef struct heap_s {
 	void *rov_ptr; /**< Roving pointer. */
 	uint64_t num_objects; /**< Number of objects in the heap. */
 	dmmstats_t dmm_stats; /**< Statistics of the heap. */
+#ifdef WITH_KNOBS
 	dmmknobs_t dmm_knobs; /**< Tunable parameters of the heap. */
+#endif /* WITH_KNOBS */
 #ifdef HAVE_LOCKS
 	pthread_mutex_t mutex;/**< Mutex when POSIX Threads are used. */
 #endif /* HAVE_LOCKS */

+ 0 - 1
src/CMakeLists.txt

@@ -32,7 +32,6 @@ set(dmmlib_SRCS
   block_header.c
   custom_free.c
   custom_malloc.c
-  dmm_adaptor.c
   other.c
   initialize_allocator.c
   sys_alloc.c

+ 0 - 11
src/coalesce.c

@@ -8,17 +8,9 @@ void * coalesce(void *ptr, heap_t *heap, allocator_t *allocator) {
     int fixed_list_id, i;
     maptable_node_t *current_maptable_node;
 
-    // If there is a negative value on max_coalesce_size, then don't do
-    // anything.
-    // FIXME To be moved in custom_free()
-    //if(heap->dmm_knobs.max_coalesce_size < 0) {
-    //    return ptr;
-    //}
-
     // Try to coalesce with the previous memory block
     // FIXME What happens if we have multiple heaps and we don't know the
     // owner of the blocks?
-    printf("previous %zu\n", get_previous_size(ptr));
     if(is_previous_free(ptr)) {
         prev = get_previous(ptr);
 
@@ -47,11 +39,8 @@ void * coalesce(void *ptr, heap_t *heap, allocator_t *allocator) {
             allocator->border_ptr = prev;
         }
 
-        printf("Coalesced!\n");
-
         return prev;
     } else {
-        printf("Not Coalesced!\n");
         mark_free(ptr);
         return ptr;
     }

+ 2 - 0
src/custom_free.c

@@ -88,6 +88,7 @@ void custom_ahfree(allocator_t *allocator, heap_t* heap, void *ptr) {
 
     /* End of Stats */
 
+#ifdef WITH_KNOBS
     /* Refresh the state of the heap allocator if a certain number of
      * free's has been served already
      */
@@ -95,6 +96,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 */
 
 #ifdef HAVE_LOCKS
     posix_unlock(heap);

+ 2 - 0
src/custom_malloc.c

@@ -101,6 +101,7 @@ void * custom_ahmalloc(allocator_t* allocator, heap_t* heap, size_t size) {
         ptr = sys_alloc(allocator, heap, size);
     }
 
+#ifdef WITH_KNOBS
     /* Refresh the state of the heap allocator if a certain number of
      * malloc's has been served already
      */
@@ -108,6 +109,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 */
 
 #ifdef HAVE_LOCKS
     posix_unlock(heap);

+ 2 - 0
src/initialize_allocator.c

@@ -33,6 +33,7 @@ void initialize_allocator(allocator_t *allocator) {
         allocator->heaps[i].dmm_stats.num_malloc = 0;
         allocator->heaps[i].dmm_stats.num_free = 0;
 
+#ifdef WITH_KNOBS
         /* Knobs initialization */
         allocator->heaps[i].dmm_knobs.max_coalesce_size = -1;
         /* FIXME Create a constant for the initial value of the next
@@ -40,6 +41,7 @@ void initialize_allocator(allocator_t *allocator) {
          */
         allocator->heaps[i].dmm_knobs.frag_threshold = 1.0;
         allocator->heaps[i].dmm_knobs.mem_threshold = 17000;
+#endif /* WITH_KNOBS */
 
 #ifdef HAVE_LOCKS
         pthread_mutex_init(&allocator->heaps[i].mutex, NULL);