ソースを参照

Small fixes to remove warnings. initialize_allocator() could now use sbrk locks.

Ioannis Koutras 13 年 前
コミット
186a55c23d
共有6 個のファイルを変更した36 個の追加22 個の削除を含む
  1. 1 1
      include/dmmlib/heap.h
  2. 3 0
      private-include/dmm_adaptor.h
  3. 13 12
      src/custom_malloc.c
  4. 17 7
      src/initialize_allocator.c
  5. 1 1
      src/other.c
  6. 1 1
      src/sys_alloc.c

+ 1 - 1
include/dmmlib/heap.h

@@ -9,7 +9,7 @@
 #define HEAP_H
 
 #include <stdint.h>
-#include <stddef.h> // For size_t support
+#include <stddef.h> /* For size_t support */
 #include <stdbool.h>
 
 #include "dmm_config.h"

+ 3 - 0
private-include/dmm_adaptor.h

@@ -6,6 +6,9 @@
 void set_frag_params(heap_t *heap);
 void set_foot_params(heap_t *heap);
 
+void update_frag_params(heap_t *heap);
+void update_foot_params(heap_t *heap);
+
 float get_current_fragmentation(heap_t *heap);
 void check_footprint(heap_t *heap);
 void malloc_state_refresh(heap_t *heap);

+ 13 - 12
src/custom_malloc.c

@@ -5,7 +5,7 @@
 #ifdef HAVE_LOCKS
 #include "posix_lock.h"
 #endif /* HAVE_LOCKS */
-#include "dmm_init.h"
+#include <dmmlib/initialize_allocator.h>
 #include "other.h"
 #include "sys_alloc.h"
 #include "block_header.h"
@@ -19,7 +19,7 @@ void * custom_ahmalloc(allocator_t* allocator, heap_t* heap, size_t size) {
 
 #ifndef WITH_MEMORY_SPACE_AWARENESS
 
-    // Go to the system allocator if none was given
+    /* Go to the system allocator if none was given */
     if(allocator == NULL) {
         allocator = &systemallocator;
         if(allocator->initialized != true) {
@@ -43,10 +43,10 @@ void * custom_ahmalloc(allocator_t* allocator, heap_t* heap, size_t size) {
 
     fixed_list_id = map_size_to_list(heap, req_padding(size));
 
-    // If a fixed list is found, do a first fit
+    /* If a fixed list is found, do a first fit */
     if(fixed_list_id != -1) {
         current_maptable_node = heap->maptable_head;
-        // traverse through the maptable node list
+        /* traverse through the maptable node list */
         if(fixed_list_id != 0) {
             for(i = 1; i < fixed_list_id; i++) {
                 current_maptable_node = current_maptable_node->next;
@@ -60,12 +60,12 @@ void * custom_ahmalloc(allocator_t* allocator, heap_t* heap, size_t size) {
 
     if(ptr == NULL) {
 
-        // first fit from free list
+        /* first fit from free list */
         for(current_block = heap->free_list_head; current_block != NULL;
                 current_block = get_next(current_block)) {
             if(get_size(current_block) >= size) {
                 if(current_block == heap->free_list_head) {
-                    heap->free_list_head = get_next(ptr);
+                    heap->free_list_head = get_next(current_block);
                 } else {
                     set_next(previous_block, get_next(current_block));
                 }
@@ -82,16 +82,16 @@ void * custom_ahmalloc(allocator_t* allocator, heap_t* heap, size_t size) {
         set_requested_size(ptr, size);
         mark_used(ptr);
 
-        // Update the used blocks list
+        /* Update the used blocks list */
         set_next(ptr, heap->used_blocks_head);
         heap->used_blocks_head = ptr;
 
-        // Begin of Stats
+        /* Begin of Stats */
 
         heap->dmm_stats.live_objects += 1;
         heap->dmm_stats.num_malloc += 1;
 
-        // End of Stats
+        /* End of Stats */
         /* FIXME To be refactored - END */
 
     }
@@ -100,9 +100,10 @@ void * custom_ahmalloc(allocator_t* allocator, heap_t* heap, size_t size) {
         ptr = sys_alloc(allocator, heap, size);
     }
 
-    // Refresh the state of the heap allocator if a certain number of
-    // malloc's has been served already
-    // TODO Define 50 as a constant
+    /* Refresh the state of the heap allocator if a certain number of
+     * malloc's has been served already
+     */
+    /* TODO Define 50 as a constant */
     if(heap->dmm_stats.num_malloc % 50) {
         malloc_state_refresh(heap);
     }

+ 17 - 7
src/initialize_allocator.c

@@ -17,6 +17,10 @@ void initialize_allocator(allocator_t *allocator) {
     heap_t *current_heap;
     maptable_node_t *maptablenode;
 
+#ifdef HAVE_LOCKS
+    sbrk_lock();
+#endif /* HAVE_LOCKS */
+
     for(i = 0; i < NUM_HEAPS; i++) {
         allocator->heaps[i].maptable_head = NULL;
         allocator->heaps[i].free_list_head = NULL;
@@ -29,10 +33,11 @@ void initialize_allocator(allocator_t *allocator) {
         allocator->heaps[i].dmm_stats.num_malloc = 0;
         allocator->heaps[i].dmm_stats.num_free = 0;
 
-        // Knobs initialization
+        /* Knobs initialization */
         allocator->heaps[i].dmm_knobs.max_coalesce_size = -1;
-        // FIXME Create a constant for the initial value of the next
-        // variables
+        /* FIXME Create a constant for the initial value of the next
+         * variables
+         */
         allocator->heaps[i].dmm_knobs.frag_threshold = 1.0;
         allocator->heaps[i].dmm_knobs.mem_threshold = 17000;
 
@@ -47,10 +52,11 @@ void initialize_allocator(allocator_t *allocator) {
     allocator->border_ptr = starting_address;
 #endif /* WITH_MEMORY_SPACE_AWARENESS */
 
-    // 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)
-    // 2 * 4 + 2 * 2 = 12 maptable nodes
+    /* 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)
+     * 2 * 4 + 2 * 2 = 12 maptable nodes
+     */
     current_heap = &allocator->heaps[0];
 
     maptablenode = (maptable_node_t *) sys_alloc(allocator, &allocator->heaps[0], 12*(sizeof(maptable_node_t)));
@@ -105,6 +111,10 @@ void initialize_allocator(allocator_t *allocator) {
 #ifndef WITH_MEMORY_SPACE_AWARENESS
     allocator->initialized = true;
 #endif /* WITH_MEMORY_SPACE_AWARENESS */
+
+#ifdef HAVE_LOCKS
+    sbrk_unlock();
+#endif /* HAVE_LOCKS */
     
 }
 

+ 1 - 1
src/other.c

@@ -28,7 +28,7 @@ int map_size_to_list(heap_t *heap, size_t sz) {
     return -1;
 }
 
-// Random assignment
+/* Random assignment */
 int map_thread_heap(void) {
     return (int) (((unsigned long) pthread_self() >> 10) % NUM_HEAPS);
 }

+ 1 - 1
src/sys_alloc.c

@@ -34,7 +34,7 @@ void *sys_alloc(allocator_t *allocator, heap_t *heap, size_t size) {
     ptr = sbrk((int) allocation_size);
     if(ptr == (void *) -1) {
         printf("sbrk problem for size of: %zu\n", allocation_size);
-        printf( "Error on sbrk: %s\n", strerror( errno ) );
+        printf("Error on sbrk: %s\n", strerror( errno ) );
     }   
     if(allocator->border_ptr != NULL && ptr != (void *) 
             ((char *) allocator->border_ptr + previous_size)) {