Prechádzať zdrojové kódy

Fit percentage for good-fit and search policy per heap is moved to knobs.

Ioannis Koutras 13 rokov pred
rodič
commit
74715a865a

+ 2 - 1
DefineOptions.cmake

@@ -61,7 +61,7 @@ endif (LEON3)
 
 if (LINUXTEST)
   set(WITH_SYSTEM_CALLS "mmap")
-  set(SEARCH_POLICY "allocvar")
+  set(SEARCH_POLICY "good")
   set(FIT_PERCENTAGE 0.6)
   set(HAVE_LOCKS ON)
   set(WITH_EXAMPLES ON)
@@ -90,6 +90,7 @@ if(SEARCH_POLICY STREQUAL "best")
   set(BEST_FIT ON)
 elseif(SEARCH_POLICY STREQUAL "good")
   set(GOOD_FIT ON)
+  set(WITH_KNOBS ON)
 elseif(SEARCH_POLICY STREQUAL "exact")
   set(EXACT_FIT ON)
 elseif(SEARCH_POLICY STREQUAL "first")

+ 7 - 4
include/dmmlib/heap.h

@@ -81,6 +81,13 @@ typedef struct dmmknobs_s {
 	float frag_threshold; /**< Fragmentation threshold to enable coalescing
 				or not. */ 
 	uint32_t mem_threshold; /**< Memory size threshold. */
+#ifdef GOOD_FIT
+	float fit_percentage; /**< Fit percentage for good-fit searches. */
+#endif  /* GOOD_FIT */
+#ifdef HEAP_VAR_FIT
+	/** Current search policy on the allocator's free lists. */
+	void *(*search_policy)(heap_t * heap, size_t requested_size);
+#endif /* HEAP_VAR_FIT */
 #ifdef COALESCING_VARIABLE
 	size_t max_coalesce_size; /**< Maximum coalesce size; -1 if coalescing
 				     is not supported */
@@ -98,10 +105,6 @@ typedef struct dmmknobs_s {
 
 /** A structure to store heap information. */
 typedef struct heap_s {
-#ifdef HEAP_VAR_FIT
-	/** Current search policy on the allocator's free lists. */
-	void *(*search_policy)(heap_t * heap, size_t requested_size);
-#endif /* HEAP_VAR_FIT */
 #ifdef WITH_FIXED_LISTS
 	maptable_node_t *maptable_head; /**< The head of the maptable list. */
 #endif /* WITH_FIXED_LISTS */

+ 5 - 2
private-include/linked_lists/search_algorithms.h

@@ -53,17 +53,20 @@ void * search_on_fixed(heap_t * heap, size_t requested_size);
  */
 void * best_fit_on_freelist(heap_t *heap, size_t requested_size);
 
+#ifdef GOOD_FIT
+
 /**
  * Perform a good-fit search on the free list
  *
  * \param heap The heap whose free list should be accessed.
  * \param requested_size The desired size of the block.
- * \param fit_percentage The lowest acceptable percentage of the block space to be filled.
  *
  * \return The pointer to the data part of the matched memory block.
  * \retval NULL No block was found.
  */
-void * good_fit_on_freelist(heap_t *heap, size_t requested_size, float fit_percentage);
+void * good_fit_on_freelist(heap_t *heap, size_t requested_size);
+
+#endif /* GOOD_FIT */
 
 /**
  * Perform an exact-fit search on free lists for a block of a certain size

+ 3 - 1
src/custom_malloc.c

@@ -36,7 +36,7 @@
 #if defined (BEST_FIT)
 #define search_on_free(size) best_fit_on_freelist(heap, size)
 #elif defined (GOOD_FIT)
-#define search_on_free(size) good_fit_on_freelist(heap, size, FIT_PERCENTAGE)
+#define search_on_free(size) good_fit_on_freelist(heap, size)
 #elif defined (EXACT_FIT)
 #define search_on_free(size) exact_fit_on_freelist(heap, size)
 #elif defined (FIRST_FIT)
@@ -81,6 +81,8 @@ void * custom_ahmalloc(allocator_t* allocator, heap_t* heap, size_t size) {
 #endif /* WITH_FIXED_LISTS */
 #ifdef ALLOC_VAR_FIT
         ptr = (*allocator->search_policy)(heap, req_padding(size));
+#elif defined (HEAP_VAR_FIT)
+        ptr = (*heap->dmm_knobs.search_policy)(heap, req_padding(size));
 #else /* ALLOC_VAR_FIT */
         ptr = search_on_free(size);
 #endif /* ALLOC_VAR_FIT */

+ 4 - 0
src/initialize_allocator.c

@@ -72,6 +72,10 @@ void initialize_allocator(allocator_t *allocator) {
 #ifdef WITH_KNOBS
         /* Knobs initialization */
 
+#ifdef GOOD_FIT
+        allocator->heaps[i].dmm_knobs.fit_percentage = FIT_PERCENTAGE;
+#endif /* GOOD_FIT */
+
 #ifdef COALESCING_VARIABLE
         allocator->heaps[i].dmm_knobs.max_coalesce_size = MAX_COALESCE_SIZE;
 #endif /* COALESCING_VARIABLE */

+ 6 - 2
src/linked_lists/search_algorithms.c

@@ -112,7 +112,9 @@ void * best_fit_on_freelist(heap_t *heap, size_t requested_size) {
     return best_block;
 }
 
-void * good_fit_on_freelist(heap_t *heap, size_t requested_size, float fit_percentage) {
+#ifdef GOOD_FIT
+
+void * good_fit_on_freelist(heap_t *heap, size_t requested_size) {
     void *current_block, *previous_block;
     void *best_block, *best_previous_block;
     size_t best_size, block_size;
@@ -134,7 +136,7 @@ void * good_fit_on_freelist(heap_t *heap, size_t requested_size, float fit_perce
                 best_previous_block = previous_block;
 		/* If the block size fits the relaxed requirements, then there
 		 * is no need to keep searching for a better sized block */
-                if(fit_percentage * best_size <= requested_size) {
+                if(heap->dmm_knobs.fit_percentage * best_size <= requested_size) {
                     break;
                 }
             }
@@ -165,6 +167,8 @@ void * good_fit_on_freelist(heap_t *heap, size_t requested_size, float fit_perce
     return best_block;
 }
 
+#endif /* GOOD_FIT */
+
 
 /**
  * \details In order to remove a block from a singly linked list, we need to