Quellcode durchsuchen

refactor usage of req_padding()

req_padding() was being called several times. This patch limits it to a single
call during an execution path. Courtesy of Iraklis Anagnostopoulos.
Ioannis Koutras vor 11 Jahren
Ursprung
Commit
365a0e5158

+ 4 - 4
private-include/freelist/fitting_policy.h

@@ -40,16 +40,16 @@
 
 #if defined (BEST_FIT)
 #include "freelist/fitting/best.h"
-#define SEARCH_LIST(raw_block, size) fl_best_fit(raw_block, req_padding(size))
+#define SEARCH_LIST(raw_block, size) fl_best_fit(raw_block, size)
 #elif defined (EXACT_FIT)
 #include "freelist/fitting/exact.h"
-#define SEARCH_LIST(raw_block, size) fl_exact_fit(raw_block, req_padding(size))
+#define SEARCH_LIST(raw_block, size) fl_exact_fit(raw_block, size)
 #elif defined (FIRST_FIT)
 #include "freelist/fitting/first.h"
-#define SEARCH_LIST(raw_block, size) fl_first_fit(raw_block, req_padding(size))
+#define SEARCH_LIST(raw_block, size) fl_first_fit(raw_block, size)
 #elif defined (GOOD_FIT)
 #include "freelist/fitting/good.h"
-#define SEARCH_LIST(raw_block, size) fl_good_fit(raw_block, req_padding(size))
+#define SEARCH_LIST(raw_block, size) fl_good_fit(raw_block, size)
 #endif /* BEST_FIT */ 
 
 #endif /* FL_FITTING_POLICY_H */

+ 2 - 2
src/freelist/malloc.c

@@ -57,7 +57,7 @@ void * freelist_malloc(freelist_rb_t *raw_block, size_t size) {
         mark_used(raw_block, ptr);
     } else {
 
-        allocation_size = req_padding(size) + HEADER_SIZE;
+        allocation_size = size + HEADER_SIZE;
 
         if(allocation_size <= raw_block->remaining_size) {
             if(raw_block->border_ptr == NULL) {
@@ -77,7 +77,7 @@ void * freelist_malloc(freelist_rb_t *raw_block, size_t size) {
             raw_block->border_ptr = ptr;
 
             // Update block metadata
-            set_size_and_used(raw_block, ptr, req_padding(size));
+            set_size_and_used(raw_block, ptr, size);
             set_previous_size_availability(ptr, previous_size_availability);
             SET_REQUESTED_SIZE(ptr, size);
         }

+ 2 - 1
src/freelist/memalign.c

@@ -27,6 +27,7 @@
 #include <inttypes.h>
 
 #include "memcpy.h"
+#include "padding.h"
 
 #include "dmmlib/config.h"
 #include "freelist/block_header_funcs.h"
@@ -36,7 +37,7 @@ void * freelist_memalign(freelist_rb_t *raw_block, size_t alignment,
     void *return_ptr;
     /* extra_size denotes the worst-case scenario. Because memcpy() is used,
      * at least HEADER_SIZE is needed for no memory overlap. */
-    size_t extra_size = HEADER_SIZE + alignment - 1;
+    size_t extra_size = req_padding(HEADER_SIZE + alignment - 1);
 
     return_ptr = freelist_malloc(raw_block, size + extra_size);
 

+ 0 - 2
src/freelist/realloc.c

@@ -63,8 +63,6 @@ void * freelist_realloc(freelist_rb_t *raw_block, void *ptr,
     size_t unmodified_req_size = req_size;
 #endif /* WITH_ALLOCATOR_STATS && REQUEST_SIZE_INFO */
 
-    req_size = req_padding(req_size);
-
     block = get_header(ptr);
 
 #if defined (WITH_ALLOCATOR_STATS) && defined (REQUEST_SIZE_INFO)

+ 0 - 3
src/freelist/split.c

@@ -41,9 +41,6 @@ void split(freelist_rb_t *raw_block, block_header_t *ptr, size_t req_size) {
     next_block = get_dlnext(raw_block, ptr);
 #endif /* COALESCE_AFTER_SPLIT */
 
-    /* Align the requested size */
-    req_size = req_padding(req_size);
-
     /* Check what would be the size of the new block if we split the current
      * one.
      * Note: new_size is a size_t, so compare first in order to prevent an

+ 4 - 0
src/malloc.c

@@ -37,6 +37,7 @@
 #include "slab.h"
 
 #include "dmmlib_trace.h"
+#include "padding.h"
 #include "statistics.h"
 
 void * malloc(size_t size) {
@@ -96,6 +97,9 @@ void * malloc(size_t size) {
             }
         }
     } else {
+
+        size = req_padding(size);
+
         /* Check if the size is appropriate for the use of a freelist-organized
          * or bitmap-organized raw block. */
 

+ 2 - 1
src/realloc.c

@@ -60,6 +60,7 @@ void * realloc(void *ptr, size_t size) {
         return NULL;
     }
 
+    size = req_padding(size);
     owner_raw_block = find_raw_block_owner(ptr);
 
     if(owner_raw_block->type == SLAB) {
@@ -88,7 +89,7 @@ void * realloc(void *ptr, size_t size) {
         owner_raw_block = (raw_block_header_t *)
             ((uintptr_t) ptr - sizeof(raw_block_header_t));
 
-        size_t full_size = sizeof(raw_block_header_t) + req_padding(size);
+        size_t full_size = sizeof(raw_block_header_t) + size;
 
 #ifdef PAGESIZE_ALIGN
         full_size = (full_size + SYS_PAGESIZE - 1) &