Browse Source

correct tracking of big block statistics

Ioannis Koutras 12 years ago
parent
commit
c5b63eb8b8
6 changed files with 32 additions and 11 deletions
  1. 3 0
      include/dmmlib/raw_block.h
  2. 3 1
      src/free.c
  3. 3 0
      src/freelist/free.c
  4. 3 0
      src/freelist/malloc.c
  5. 3 3
      src/malloc.c
  6. 17 7
      src/raw_block.c

+ 3 - 0
include/dmmlib/raw_block.h

@@ -53,6 +53,9 @@ typedef enum rb_type_en {
 typedef struct raw_block_header_s {
     rb_type type; /**< The type of the raw block. */
     size_t size; /**< Total size of the raw block. */
+#ifdef REQUEST_SIZE_INFO
+    size_t requested_size; /**< The requested size of the raw block. */
+#endif /* REQUEST_SIZE_INFO */
     SLIST_ENTRY(raw_block_header_s) pointers; /**< Pointer to the next raw
                                                 block. */
 #ifdef HAVE_LOCKS

+ 3 - 1
src/free.c

@@ -74,13 +74,15 @@ void free(void *ptr) {
 #endif /* WITH_DEBUG */
 
 #ifdef WITH_ALLOCATOR_STATS
+        lock_global();
         update_stats(&systemallocator.dmm_stats,
                 FREE,
 #ifdef REQUEST_SIZE_INFO
-                owner_raw_block->size - sizeof(raw_block_header_t),
+                owner_raw_block->requested_size,
 #endif /* REQUEST_SIZE_INFO */
                 owner_raw_block->size);
 #endif /* WITH_ALLOCATOR_STATS */
+        unlock_global();
 
         release_memory(owner_raw_block);
     }

+ 3 - 0
src/freelist/free.c

@@ -32,6 +32,7 @@
 #include "trace.h"
 
 #ifdef WITH_ALLOCATOR_STATS
+#include "locks.h"
 #include "statistics.h"
 #include "dmmlib/dmmlib.h"
 #endif /* WITH_ALLOCATOR_STATS */
@@ -48,12 +49,14 @@ void freelist_free(freelist_rb_t *raw_block, void *ptr) {
     // free neighbors.
 
 #ifdef WITH_ALLOCATOR_STATS
+            lock_global();
             update_stats(&systemallocator.dmm_stats,
                     FREE,
 #ifdef REQUEST_SIZE_INFO
                     get_requested_size(block),
 #endif /* REQUEST_SIZE_INFO */
                     get_size(block) + HEADER_SIZE);
+            unlock_global();
 #endif /* WITH_ALLOCATOR_STATS */
 
 #if defined (COALESCING_FIXED) || defined (COALESCING_VARIABLE)

+ 3 - 0
src/freelist/malloc.c

@@ -36,6 +36,7 @@
 #include "trace.h"
 
 #ifdef WITH_ALLOCATOR_STATS
+#include "locks.h"
 #include "statistics.h"
 #include "dmmlib/dmmlib.h"
 #endif /* WITH_ALLOCATOR_STATS */
@@ -122,12 +123,14 @@ void * freelist_malloc(freelist_rb_t *raw_block, size_t size) {
     if(ptr != NULL) {
 
 #ifdef WITH_ALLOCATOR_STATS
+        lock_global();
         update_stats(&systemallocator.dmm_stats,
                 MALLOC,
 #ifdef REQUEST_SIZE_INFO
                 size,
 #endif /* REQUEST_SIZE_INFO */
                 get_size(ptr) + HEADER_SIZE);
+        unlock_global();
 #endif /* WITH_ALLOCATOR_STATS */
 
         return (void *)((uintptr_t) ptr + HEADER_SIZE);

+ 3 - 3
src/malloc.c

@@ -89,8 +89,8 @@ void * malloc(size_t size) {
 #endif /* FL_RB_ONLY */
 
             lock_global();
-            ptr = (void *)create_raw_block(size +
-                    sizeof(raw_block_header_t), BIGBLOCK);
+            ptr = create_raw_block(size + sizeof(raw_block_header_t),
+                        BIGBLOCK);
             if(ptr != NULL) {
 
 #ifdef WITH_DEBUG
@@ -104,7 +104,7 @@ void * malloc(size_t size) {
 #ifdef REQUEST_SIZE_INFO
                         size,
 #endif /* REQUEST_SIZE_INFO */
-                        size + sizeof(raw_block_header_t));
+                        ((raw_block_header_t *)ptr)->size);
 #endif /* WITH_ALLOCATOR_STATS */
 
                 unlock_global();

+ 17 - 7
src/raw_block.c

@@ -43,6 +43,19 @@ raw_block_header_t *create_raw_block(size_t raw_block_size, rb_type type) {
     size_t remaining_cells;
 #endif /* BITMAP_RB_ONLY */
 
+    ptr = (raw_block_header_t *)request_memory(raw_block_size);
+
+    if(ptr == NULL) {
+        return NULL;
+    }
+
+    init_raw_block_lock(ptr);
+    lock_raw_block(ptr);
+
+#ifdef REQUEST_SIZE_INFO
+    ptr->requested_size = raw_block_size;
+#endif /* REQUEST_SIZE_INFO */
+
     // In case mmap() function is used, align the requested size to multiple of
     // pagesizes
 #ifdef PAGESIZE_ALIGN
@@ -50,12 +63,6 @@ raw_block_header_t *create_raw_block(size_t raw_block_size, rb_type type) {
     raw_block_size = pagesize * ((raw_block_size + pagesize - 1) / pagesize);
 #endif /* PAGESIZE_ALIGN */
 
-    ptr = (raw_block_header_t *)request_memory(raw_block_size);
-
-    if(ptr == NULL) {
-        return NULL;
-    }
-
     ptr->size = raw_block_size;
 
     switch(type) {
@@ -119,10 +126,13 @@ raw_block_header_t *create_raw_block(size_t raw_block_size, rb_type type) {
 #endif /* BITMAP_RB_ONLY */
 
         case BIGBLOCK:
+#ifdef REQUEST_SIZE_INFO
+            ptr->requested_size -= sizeof(raw_block_header_t);
+#endif /* REQUEST_SIZE_INFO */
             break;
     }
 
-    init_raw_block_lock(ptr);
+    unlock_raw_block(ptr);
 
     return ptr;
 }