Explorar el Código

small fix for the stats on freelist_realloc()

freelist_realloc() calls freelist_free() and stats were leaking from both
functions. In this commit, freelist_free() without stats is copied.
Ioannis Koutras hace 11 años
padre
commit
c0ccb6929e
Se han modificado 1 ficheros con 33 adiciones y 2 borrados
  1. 33 2
      src/freelist/realloc.c

+ 33 - 2
src/freelist/realloc.c

@@ -26,6 +26,11 @@
 #include "dmmlib/freelist/block_header.h"
 #include "dmmlib/freelist/block_header.h"
 #include "freelist/block_header_funcs.h"
 #include "freelist/block_header_funcs.h"
 
 
+/* for freelist_free() functionality */
+#if defined (COALESCING_FIXED) || defined (COALESCING_VARIABLE)
+#include "freelist/coalesce.h"
+#endif /* COALESCING_FIXED || COALESCING_VARIABLE */
+
 #include "dmmlib/dmmlib.h"
 #include "dmmlib/dmmlib.h"
 
 
 #include "memcpy.h"
 #include "memcpy.h"
@@ -37,6 +42,7 @@
 #include "locks.h"
 #include "locks.h"
 #include "other.h"
 #include "other.h"
 #include "padding.h"
 #include "padding.h"
+#include "statistics.h"
 
 
 /**
 /**
  * Re-allocates a memory block from a freelist-organized raw block
  * Re-allocates a memory block from a freelist-organized raw block
@@ -52,10 +58,18 @@ void * freelist_realloc(freelist_rb_t *raw_block, void *ptr,
     block_header_t *block;
     block_header_t *block;
     void *ret;
     void *ret;
 
 
+#ifdef REQUEST_SIZE_INFO
+    size_t unmodified_req_size = req_size;
+#endif /* REQUEST_SIZE_INFO */
+
     req_size = req_padding(req_size);
     req_size = req_padding(req_size);
 
 
     block = get_header(ptr);
     block = get_header(ptr);
 
 
+#ifdef REQUEST_SIZE_INFO
+    size_t original_req_size = get_requested_size(block);
+#endif /* REQUEST_SIZE_INFO */
+
     if(get_size(block) > req_size) {
     if(get_size(block) > req_size) {
         /* TODO Maybe create a memory block in the unneeded space */
         /* TODO Maybe create a memory block in the unneeded space */
         return ptr;
         return ptr;
@@ -77,7 +91,15 @@ void * freelist_realloc(freelist_rb_t *raw_block, void *ptr,
     ret = freelist_malloc(raw_block, req_size);
     ret = freelist_malloc(raw_block, req_size);
     UNLOCK_RAW_BLOCK(rb);
     UNLOCK_RAW_BLOCK(rb);
 
 
-    if(ret == NULL) {
+    if(ret != NULL) {
+#ifdef REQUEST_SIZE_INFO
+        UPDATE_GLOBAL_STATS(REALLOC_GT,
+                unmodified_req_size - original_req_size);
+#else /* REQUEST_SIZE_INFO */
+        UPDATE_GLOBAL_STATS(REALLOC_GT);
+#endif /* REQUEST_SIZE_INFO */
+    } else {
+        /* FIXME stats leak from this malloc() call */
         ret = malloc(req_size);
         ret = malloc(req_size);
     }
     }
 
 
@@ -88,7 +110,16 @@ void * freelist_realloc(freelist_rb_t *raw_block, void *ptr,
     memcpy(ret, ptr, get_size(block));
     memcpy(ret, ptr, get_size(block));
 
 
     LOCK_RAW_BLOCK(rb);
     LOCK_RAW_BLOCK(rb);
-    freelist_free(raw_block, ptr);
+
+    /* start of copy from freelist_free() */
+#if defined (COALESCING_FIXED) || defined (COALESCING_VARIABLE)
+    coalesce(raw_block, block);
+#else
+    mark_free(raw_block, block);
+    ADD_BLOCK(block);
+#endif /* COALESCING_FIXED || COALESCING_VARIABLE */
+    /* end of copy from freelist_free() */
+
     UNLOCK_RAW_BLOCK(rb);
     UNLOCK_RAW_BLOCK(rb);
 
 
     return ret;
     return ret;