Переглянути джерело

Fixed and cleaned splitting and coalescing for freelist-organized raw blocks

Ioannis Koutras 12 роки тому
батько
коміт
7e0a66ce23

+ 5 - 5
private-include/freelist/coalesce.h

@@ -17,17 +17,17 @@
 
 #ifndef COALESCE_H
 #define COALESCE_H
+#include "dmm_config.h"
 
-#include <dmmlib/raw_block.h>
-#include <dmmlib/block_header.h>
+#include "freelist/freelist_rb.h"
+#include "freelist/block_header.h"
 
 /**
  * Tries to merges a memory block with its previous one and/or the next one.
  *
+ * @param raw_block The raw block owner.
  * @param ptr The memory block to be checked.
- * @param heap The heap of the memory block.
  */
-void coalesce(raw_block_header_t *raw_block, block_header_t *ptr);
+void coalesce(freelist_rb_t *raw_block, block_header_t *ptr);
 
 #endif /* COALESCE_H */
-

+ 4 - 5
private-include/freelist/split.h

@@ -17,11 +17,11 @@
 
 #ifndef SPLIT_H
 #define SPLIT_H
-
-#include <dmmlib/raw_block.h>
-#include <dmmlib/block_header.h>
 #include "dmm_config.h"
 
+#include "freelist/freelist_rb.h"
+#include "freelist/block_header.h"
+
 /**
  * Splits a memory block to two blocks: one with the requested size and the
  * another one with the remaining space.
@@ -31,7 +31,6 @@
  * @param ptr The memory block to be split.
  * @param req_size The size which the first block will use.
  */ 
-void split(raw_block_header_t *raw_block, block_header_t *ptr, size_t req_size);
+void split(freelist_rb_t *raw_block, block_header_t *ptr, size_t req_size);
 
 #endif /* SPLIT_H */
-

+ 1 - 0
src/dmmlib.c

@@ -26,6 +26,7 @@
 #include "dmmlib/dmmlib.h"
 #ifdef FL_RB_ONLY
 #include "freelist/freelist_malloc.h"
+#include "freelist/freelist_rb.h"
 #endif /* FL_RB_ONLY */
 #ifdef BITMAP_RB_ONLY
 #include "bitmap/bitmap.h"

+ 1 - 3
src/freelist/coalesce.c

@@ -19,10 +19,8 @@
 #include "freelist/linked_lists/add_block.h"
 #include "freelist/linked_lists/linked_lists.h"
 #include "freelist/block_header_funcs.h"
-#include "other.h"
-#include "dmm_config.h"
 
-void coalesce(raw_block_header_t *raw_block, block_header_t *ptr) {
+void coalesce(freelist_rb_t *raw_block, block_header_t *ptr) {
     size_t max_coal_size;
     size_t size;
     size_t current_next_size;

+ 4 - 5
src/freelist/freelist_malloc.c

@@ -170,8 +170,12 @@ void freelist_free(raw_block_header_t *raw_block, void *ptr) {
     pthread_mutex_lock(&raw_block->mutex);
 #endif /* HAVE_LOCKS */
 
+    // Memory stats get updated here in case the space gets coalesced with its
+    // free neighbors.
 #ifdef WITH_STATS
     raw_block->dmm_stats.total_mem_allocated -= get_size(ptr);
+    raw_block->dmm_stats.live_objects--;
+    raw_block->dmm_stats.num_free++;
 #endif /* WITH_STATS */
 
 #if defined (COALESCING_FIXED) || defined (COALESCING_VARIABLE)
@@ -181,11 +185,6 @@ void freelist_free(raw_block_header_t *raw_block, void *ptr) {
     add_block(rb_header, ptr);
 #endif /* COALESCING_FIXED || COALESCING_VARIABLE */
 
-#ifdef WITH_STATS
-    raw_block->dmm_stats.live_objects--;
-    raw_block->dmm_stats.num_free++;
-#endif /* WITH_STATS */
-
 #ifdef HAVE_LOCKS
     pthread_mutex_unlock(&raw_block->mutex);
 #endif /* HAVE_LOCKS */

+ 3 - 11
src/freelist/split.c

@@ -15,13 +15,12 @@
  *
  */
 
-#include "freelist/block_header_funcs.h"
-#include "other.h"
-#include "freelist/linked_lists/add_block.h"
 #include "freelist/split.h"
 
+#include "freelist/block_header_funcs.h"
+#include "freelist/linked_lists/add_block.h"
 
-void split(raw_block_header_t *raw_block, block_header_t *ptr, size_t req_size) {
+void split(freelist_rb_t *raw_block, block_header_t *ptr, size_t req_size) {
     size_t new_size;
     size_t min_split_size;
     block_header_t *new_block;
@@ -52,9 +51,6 @@ void split(raw_block_header_t *raw_block, block_header_t *ptr, size_t req_size)
 #endif /* SPLITTING_VARIABLE */
 
     if(new_size < min_split_size) {
-#ifdef WITH_STATS
-        raw_block->dmm_stats.total_mem_allocated += get_size(ptr);
-#endif /* WITH_STATS */
         return;
     }
 
@@ -103,8 +99,4 @@ void split(raw_block_header_t *raw_block, block_header_t *ptr, size_t req_size)
     add_block(raw_block, new_block);
 #endif /* FIFO_SORT_POLICY */
 
-#ifdef WITH_STATS
-    raw_block->dmm_stats.total_mem_allocated += req_size;
-#endif /* WITH_STATS */
-
 }