Browse Source

knobs support on setting the size of the raw block, the good-fit percentage, the maximum coalescing and minimum splitting sizes

Ioannis Koutras 13 years ago
parent
commit
0e43f0ae97

+ 1 - 0
CMakeLists.txt

@@ -177,6 +177,7 @@ elseif(RAW_BLOCKS_TYPE STREQUAL "bitmap")
 
 endif(RAW_BLOCKS_TYPE STREQUAL "freelist")
 
+message(STATUS "Have knobs: " ${WITH_KNOBS})
 message(STATUS "Have statistics: " ${STATS})
 message(STATUS "Requested Size per Block: " ${REQUEST_SIZE_INFO})
 message(STATUS "Support for debug functions: " ${WITH_DEBUG})

+ 20 - 2
DefineOptions.cmake

@@ -13,6 +13,8 @@ set(ORDERING_POLICY "lifo" CACHE STRING "Choose the ordering policy in freelist-
 
 set(FITTING_POLICY "best" CACHE STRING "Choose the fitting policy in freelist-organized raw blocks, options are: best, exact, first, good")
 
+set(GOOD_FIT_PERCENTAGE 0.8 CACHE DOUBLE "Choose the good-fit percentage")
+
 set(WITH_COALESCING "never" "Build with coalescing support")
 set(WITH_SPLITTING "never" "Build with splitting support")
 option(FREELIST_COALESCE_AFTER_SPLIT "Try to coalesce blocks after split" OFF)
@@ -26,6 +28,10 @@ set(BITMAP_RESOLUTION 256 CACHE INTEGER "Choose the size of cells in bitmap-orga
 option(WITH_REALLOC "Build with realloc" ON)
 option(WITH_CALLOC "Build with calloc" ON)
 
+# Knobs Settings
+
+option(WITH_KNOBS "Build with knobs support" OFF)
+
 # Statistics Settings
 
 set(STATS "none" CACHE STRING "Choose if the memory allocator keeps internally statistics per raw block or globally, options are: none, global")
@@ -61,7 +67,9 @@ if(P2012)
   set(WITH_SPLITTING "never")
   set(WITH_REALLOC OFF)
   set(WITH_CALLOC OFF)
+  set(WITH_KNOBS OFF)
   set(STATS "none")
+  set(REQUEST_SIZE_INFO OFF)
   set(TRACE_LEVEL 0)
   set(WITH_STATIC_LIB ON)
   set(WITH_SHARED_LIB OFF)
@@ -79,7 +87,9 @@ if(LEON3)
   set(WITH_SPLITTING "never")
   set(WITH_REALLOC OFF)
   set(WITH_CALLOC OFF)
+  set(WITH_KNOBS OFF)
   set(STATS "none")
+  set(REQUEST_SIZE_INFO OFF)
   set(TRACE_LEVEL 0)
   set(WITH_STATIC_LIB ON)
   set(WITH_SHARED_LIB OFF)
@@ -91,11 +101,19 @@ if(LINUX)
   set(WITH_SYSTEM_CALLS "mmap")
   set(SYS_ALLOC_SIZE 32768)
   set(HAVE_LOCKS ON)
-  set(RAW_BLOCKS_TYPE "bitmap")
-  set(BITMAP_RESOLUTION 256)
+  set(RAW_BLOCKS_TYPE "freelist")
+  set(ORDERING_POLICY "lifo")
+  set(FITTING_POLICY "good")
+  set(GOOD_FIT_PERCENTAGE 0.8)
+  set(WITH_COALESCING "variable")
+  set(MAX_COALESCE_SIZE 60000)
+  set(WITH_SPLITTING "variable")
+  set(MIN_SPLITTING_SIZE 64)
+  set(FREELIST_COALESCE_AFTER_SPLIT ON)
   set(TRACE_LEVEL 3)
   set(WITH_REALLOC ON)
   set(WITH_CALLOC ON)
+  set(WITH_KNOBS ON)
   set(STATS "global")
   set(REQUEST_SIZE_INFO ON)
   set(WITH_SHARED_LIB ON)

+ 4 - 1
include/dmmlib/CMakeLists.txt

@@ -5,9 +5,12 @@ set(dmmlib_HDRS
   dmmlib.h
   dmmstats.h 
   raw_block.h
-  knobs.h
 )
 
+if(WITH_KNOBS)
+  set(dmmlib_HDRS ${dmmlib_HDRS} knobs.h)
+endif(WITH_KNOBS)
+
 if(RAW_BLOCKS_TYPE STREQUAL "freelist")
   set(dmmlib_HDRS
     ${dmmlib_HDRS}

+ 8 - 1
include/dmmlib/allocator.h

@@ -1,5 +1,5 @@
 /*
- *   Copyright 2011 Institute of Communication and Computer Systems (ICCS) 
+ *   Copyright Institute of Communication and Computer Systems (ICCS)
  *
  *   Licensed under the Apache License, Version 2.0 (the "License");
  *   you may not use this file except in compliance with the License.
@@ -31,6 +31,10 @@
 #include <pthread.h>
 #endif /* HAVE_LOCKS */
 
+#ifdef WITH_KNOBS
+#include "dmmlib/knobs.h"
+#endif /* WITH_KNOBS */
+
 #ifdef WITH_ALLOCATOR_STATS
 #include <dmmlib/dmmstats.h>
 #endif /* WITH_ALLOCATOR_STATS */
@@ -47,6 +51,9 @@ typedef struct allocator_s {
 /** Mutex to allow the creation of new raw blocks. */
     pthread_mutex_t creation_mutex;
 #endif /* HAVE_LOCKS */
+#ifdef WITH_KNOBS
+    dmm_knobs_t dmm_knobs; /**< Global knobs. */
+#endif /* WITH_KNOBS */
 #ifdef WITH_ALLOCATOR_STATS
     dmmstats_t dmm_stats; /**< Global statistics. */
 #endif /* WITH_ALLOCATOR_STATS */

+ 44 - 10
include/dmmlib/knobs.h

@@ -1,10 +1,44 @@
-struct rtm_knobs_t {
-	struct p {
-		double sysallocsize;
-		double fitpercentage;
-	};
-	struct m {
-		double avr_req_sz;
-		double tot_req_sz;
-	};
-};
+/*
+ *   Copyright Institute of Communication and Computer Systems (ICCS) 
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+
+/**
+ * @file   knobs.h
+ * @author Ioannis Koutras (joko@microlab.ntua.gr)
+ * @date   November 2012
+ * @brief  Basic knob structure
+ */
+
+#ifndef KNOBS_H
+#define KNOBS_H
+
+#include "dmm_config.h"
+
+/** The knobs structure of dmmlib. */
+typedef struct dmm_knobs_s {
+    double sys_alloc_size; /**< The default size of the raw block. */
+#ifdef GOOD_FIT
+    double fitpercentage; /**< The good-fit percentage. */
+#endif /* GOOD_FIT */
+#ifdef COALESCING_VARIABLE
+    double max_coalesce_size; /**< Maximum allowed size to be coalesced. */
+#endif /* COALESCING_VARIABLE */
+#ifdef SPLITTING_VARIABLE
+    double min_split_size; /**< Minimum allowed size to be split. */
+#endif /* SPLITTING_VARIABLE */
+} dmm_knobs_t;
+
+#endif /* KNOBS_H */

+ 4 - 0
src/CMakeLists.txt

@@ -169,6 +169,10 @@ if(WITH_DEBUG)
   )
 endif(WITH_DEBUG)
 
+if(WITH_KNOBS)
+  set(dmmlib_SRCS ${dmmlib_SRCS} knobs.c)
+endif(WITH_KNOBS)
+
 if(NOT STATS STREQUAL "none")
   set(dmmlib_SRCS
     ${dmmlib_SRCS}

+ 7 - 1
src/freelist/coalesce.c

@@ -15,6 +15,12 @@
  *
  */
 
+#include "dmm_config.h"
+
+#ifdef WITH_KNOBS
+#include "dmmlib/dmmlib.h"
+#endif /* WITH_KNOBS */
+
 #include "freelist/coalesce.h"
 #include "freelist/block_header_funcs.h"
 #include "freelist/ordering_policy.h"
@@ -31,7 +37,7 @@ void coalesce(freelist_rb_t *raw_block, block_header_t *ptr) {
     max_coal_size = MAX_COALESCE_SIZE;
 #endif /* COALESCING_FIXED */
 #ifdef COALESCING_VARIABLE
-    max_coal_size = heap->dmm_knobs.max_coalesce_size;
+    max_coal_size = (size_t) systemallocator.dmm_knobs.max_coalesce_size;
 #endif /* COALESCING_VARIABLE */
 
     size = get_size(ptr);

+ 10 - 1
src/freelist/fitting/good.c

@@ -17,6 +17,10 @@
 
 #include "dmm_config.h"
 
+#ifdef WITH_KNOBS
+#include "dmmlib/dmmlib.h"
+#endif /* WITH_KNOBS */
+
 #include "freelist/fitting/good.h"
 #include "freelist/ordering_policy.h"
 #include "freelist/block_header_funcs.h"
@@ -30,7 +34,12 @@ block_header_t * fl_good_fit(freelist_rb_t *raw_block, size_t requested_size) {
     good_previous_block = NULL;
     good_block = NULL;
     good_size = (size_t) -1; /* SIZE_MAX */
-    ideal_size = (size_t) ((float) requested_size / GOOD_FIT_PERCENTAGE);
+#ifdef WITH_KNOBS
+    ideal_size = (size_t) ((double) requested_size /
+            systemallocator.dmm_knobs.fitpercentage);
+#else /* WITH_KNOBS */
+    ideal_size = (size_t) ((double) requested_size / GOOD_FIT_PERCENTAGE);
+#endif /* WITH_KNOBS */
     
     SLIST_FOREACH(current_block, &raw_block->fl_head, pointers) {
         block_size = get_size(current_block);

+ 8 - 2
src/freelist/split.c

@@ -17,6 +17,12 @@
 
 #include "freelist/split.h"
 
+#include "dmm_config.h"
+
+#ifdef WITH_KNOBS
+#include "dmmlib/dmmlib.h"
+#endif /* WITH_KNOBS */
+
 #include "freelist/block_header_funcs.h"
 #include "freelist/ordering_policy.h"
 
@@ -47,7 +53,7 @@ void split(freelist_rb_t *raw_block, block_header_t *ptr, size_t req_size) {
     min_split_size = MIN_SPLITTING_SIZE;
 #endif /* SPLITTING_FIXED */
 #ifdef SPLITTING_VARIABLE
-    min_split_size = heap->dmm_knobs.min_split_size;
+    min_split_size = (size_t) systemallocator.dmm_knobs.min_split_size;
 #endif /* SPLITTING_VARIABLE */
 
     if(new_size < min_split_size) {
@@ -69,7 +75,7 @@ void split(freelist_rb_t *raw_block, block_header_t *ptr, size_t req_size) {
     max_coal_size = MAX_COALESCE_SIZE;
 #endif /* COALESCING_FIXED */
 #ifdef COALESCING_VARIABLE
-    max_coal_size = heap->dmm_knobs.max_coalesce_size;
+    max_coal_size = systemallocator.dmm_knobs.max_coalesce_size;
 #endif /* COALESCING_VARIABLE */
 
     if(next_block != NULL && is_free(next_block) == true) {

+ 42 - 0
src/knobs.c

@@ -0,0 +1,42 @@
+/*
+ *   Copyright Institute of Communication and Computer Systems (ICCS) 
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+
+/**
+ * @file   knobs.c
+ * @author Ioannis Koutras (joko@microlab.ntua.gr)
+ * @date   November 2012
+ * @brief  Knobs initialization routine.
+ */
+
+#include "dmm_config.h"
+#include "dmmlib/dmmlib.h"
+
+__attribute__((constructor)) void knobs_init(void);
+
+/** Initializes the knobs structure of the system allocator. */
+void knobs_init(void) {
+    systemallocator.dmm_knobs.sys_alloc_size = SYS_ALLOC_SIZE;
+#ifdef GOOD_FIT
+    systemallocator.dmm_knobs.fitpercentage = GOOD_FIT_PERCENTAGE;
+#endif /* GOOD_FIT_PERCENTAGE */
+#ifdef COALESCING_VARIABLE
+    systemallocator.dmm_knobs.max_coalesce_size = MAX_COALESCE_SIZE;
+#endif /* COALESCING_VARIABLE */
+#ifdef SPLITTING_VARIABLE
+    systemallocator.dmm_knobs.min_split_size = MIN_SPLITTING_SIZE;
+#endif /* SPLITTING_VARIABLE */
+}

+ 11 - 4
src/malloc.c

@@ -73,6 +73,13 @@ void * malloc(size_t size) {
     }
 
     if(ptr == NULL) {
+        size_t sys_alloc_size;
+
+#ifdef WITH_KNOBS
+        sys_alloc_size = (size_t) systemallocator.dmm_knobs.sys_alloc_size;
+#else /* WITH_KNOBS */
+        sys_alloc_size = SYS_ALLOC_SIZE;
+#endif /* WITH_KNOBS */
 
 #ifdef BITMAP_RB_ONLY
         /* Check if the request would fit in a new bitmap raw block
@@ -80,16 +87,16 @@ void * malloc(size_t size) {
          */
 
         size_t bm_vector_size = BMAP_EL_SIZE *
-            (SYS_ALLOC_SIZE + BMAP_EL_SIZE -
+            (sys_alloc_size + BMAP_EL_SIZE -
                 sizeof(raw_block_header_t) - sizeof(bitmap_rb_t)) /
             (BMAP_EL_SIZE + BMAP_EL_SIZE_BITS * BITMAP_RESOLUTION);
 
-        if(2 * size > SYS_ALLOC_SIZE - sizeof(raw_block_header_t) -
+        if(2 * size > sys_alloc_size - sizeof(raw_block_header_t) -
                 sizeof(bitmap_rb_t) - bm_vector_size) {
 #endif /* BITMAP_RB_ONLY */
 
 #ifdef FL_RB_ONLY
-        if( 2 * size > SYS_ALLOC_SIZE - sizeof(raw_block_header_t) -
+        if( 2 * size > sys_alloc_size - sizeof(raw_block_header_t) -
                 sizeof(freelist_rb_t)) {
 #endif /* FL_RB_ONLY */
 
@@ -122,7 +129,7 @@ void * malloc(size_t size) {
         } else {
 
             lock_global();
-            new_raw_block = create_raw_block((size_t) SYS_ALLOC_SIZE,
+            new_raw_block = create_raw_block((size_t) sys_alloc_size,
                     DEFAULT_RB_TYPE);
             if(new_raw_block != NULL) {
                 lock_raw_block(new_raw_block);