Forráskód Böngészése

Reorganized the file and directory structure before the BiBoP integration

Ioannis Koutras 12 éve
szülő
commit
c5b79398e7

+ 7 - 13
DefineOptions.cmake

@@ -1,25 +1,21 @@
-option(WITH_SINGLE_ALLOCATOR "Build with support of just one allocator" ON)
+set(WITH_SYSTEM_CALLS "none" CACHE STRING "Choose what system calls can be used, options are: none, sbrk, mmap")
+set(RAW_BLOCKS_TYPE "freelist" CACHE STRING "Choose what raw blocks can be used, options are: freelist")
 option(HAVE_LOCKS "Build with POSIX locking mechanisms" ON)
 option(WITH_REALLOC "Build with realloc" OFF)
 option(WITH_EXAMPLES "Build with examples" OFF)
 option(WITH_FIXED_LISTS "Build with predefined lists of fixed-sized blocks" ON)
 option(WITH_STATS "Build with statistics" OFF)
-option(COUNT_ACCESSES "Count memory accesses" OFF)
-option(COUNT_HOPS "Count hops per request" OFF)
-option(WITH_KNOBS "Build with knobs support" OFF)
 option(WITH_ADAPTIVITY "Build with adaptivity" OFF)
 option(WITH_STATIC_LIB "Build a static library" OFF)
 option(WITH_SHARED_LIB "Build a shared library" OFF)
 option(WITH_DOC "Build with documentation" OFF)
-option(COALESCE_AFTER_SPLIT "Try to coalesce blocks after split" OFF)
 
-option(WITH_SYSTEM_CALLS "Choose what system calls can be used, options are: none, sbrk, mmap" "none")
+option(FREELIST_COALESCE_AFTER_SPLIT "Try to coalesce blocks after split" OFF)
+
 option(SORT_POLICY "Choose the block sorting policy, options are: lifo, fifo, size, address")
 
 set(REQUEST_SIZE_INFO ON)
 
-set(NUM_POOLS 1)
-
 set(WITH_SYSTEM_CALLS "none")
 
 set(SEARCH_POLICY "best")
@@ -40,7 +36,6 @@ option(LINUXTEST "Build a case for Linux" ON)
 if (P2012)
   set(WITH_SINGLE_ALLOCATOR OFF)
   set(HAVE_LOCKS OFF)
-  set(WITH_SYSTEM_CALLS "none")
   set(WITH_STATIC_LIB ON)
   set(NUM_POOLS 1)
   set(LINUXTEST OFF)
@@ -53,7 +48,6 @@ endif (P2012)
 if (LEON3)
   set(WITH_SINGLE_ALLOCATOR OFF)
   set(HAVE_LOCKS OFF)
-  set(WITH_SYSTEM_CALLS "none")
   set(WITH_STATIC_LIB ON)
   set(NUM_POOLS 1)
   set(LINUXTEST OFF)
@@ -85,9 +79,9 @@ if (LINUXTEST)
   set(WITH_DOC ON)
 endif (LINUXTEST)
 
-if (NUM_POOLS GREATER 1)
-  set(MULTIPLE_POOLS ON)
-endif (NUM_POOLS GREATER 1)
+if(RAW_BLOCKS_TYPE STREQUAL "freelist")
+  set(FL_RB_ONLY ON)
+endif(RAW_BLOCKS_TYPE STREQUAL "freelist")
 
 if(COALESCE_AFTER_SPLIT)
   if(WITH_SPLITTING STREQUAL "never")

+ 2 - 16
dmm_config.h.in

@@ -1,23 +1,9 @@
 #ifndef DMM_CONFIG_H
 #define DMM_CONFIG_H
 
-#cmakedefine LEON3
-
-#cmakedefine WITH_SINGLE_ALLOCATOR
-
-#cmakedefine HAVE_LOCKS
-
-#cmakedefine NO_SYSTEM_CALLS
-#cmakedefine WITH_SBRK
-#cmakedefine WITH_MMAP
-#ifndef NO_SYSTEM_CALLS
+#cmakedefine FL_RB_ONLY
 #cmakedefine SYS_ALLOC_SIZE @SYS_ALLOC_SIZE@
-#endif /* NO_SYSTEM_CALLS */
-
-/** The number of the pools. */
-#cmakedefine NUM_POOLS @NUM_POOLS@
-
-#cmakedefine WITH_FIXED_LISTS
+#cmakedefine HAVE_LOCKS
 
 #cmakedefine LIFO_SORT_POLICY
 #cmakedefine FIFO_SORT_POLICY

+ 5 - 7
examples/larson.c

@@ -25,9 +25,7 @@
 #include <string.h>
 #include <assert.h>
 #include <unistd.h>
-/* #include <stdlib.h> */
 #include <dmmlib/dmmlib.h>
-/* #include <dmmlib/print_stats.h> */
 #include "lran2.h"
 
 #define MAX_THREADS     100
@@ -104,7 +102,7 @@ static void warmup(char **blkp, int num_chunks) {
 
     for(cblks = 0; cblks < num_chunks; cblks++) {
         blk_size = min_size + lran2(&rgen) % (max_size - min_size);
-        blkp[cblks] = (char *) dmmlib_malloc((size_t) blk_size);
+        blkp[cblks] = (char *) malloc((size_t) blk_size);
         blksize[cblks] = blk_size;
         assert(blkp[cblks] != NULL);
     }
@@ -119,10 +117,10 @@ static void warmup(char **blkp, int num_chunks) {
 
     for(cblks=0; cblks < 4 * num_chunks; cblks++) {
         victim = lran2(&rgen) % num_chunks;
-        dmmlib_free(blkp[victim]);
+        free(blkp[victim]);
 
         blk_size = min_size + lran2(&rgen) % (max_size - min_size);
-        blkp[victim] = (char *) dmmlib_malloc((size_t) blk_size);
+        blkp[victim] = (char *) malloc((size_t) blk_size);
         blksize[victim] = blk_size;
         assert(blkp[victim] != NULL);
     }
@@ -145,11 +143,11 @@ static void * exercise_heap( void *pinput) {
     /* allocate NumBlocks chunks of random size */
     for(cblks=0; cblks < pdea->NumBlocks; cblks++) {
         victim = lran2(&pdea->rgen)%pdea->asize;
-        dmmlib_free(pdea->array[victim]);
+        free(pdea->array[victim]);
         pdea->cFrees++;
 
         blk_size = pdea->min_size+lran2(&pdea->rgen)%range;
-        pdea->array[victim] = (char *) dmmlib_malloc((size_t) blk_size);
+        pdea->array[victim] = (char *) malloc((size_t) blk_size);
 
         pdea->blksize[victim] = blk_size;
         assert(pdea->array[victim] != NULL);

+ 21 - 6
private-include/other.h

@@ -15,14 +15,29 @@
  *
  */
 
-#ifndef OTHER_H
-#define OTHER_H
+/**
+ * @file   allocator.h
+ * @author Ioannis Koutras (joko@microlab.ntua.gr)
+ * @date   August 2012
+ * @brief  Basic structures needed for the dmmlib allocator.
+ */
 
+#ifndef ALLOCATOR_H
+#define ALLOCATOR_H
 #include "dmm_config.h"
-#include <dmmlib/pool.h>
+#include "dmmlib/raw_block.h"
 
-size_t req_padding(size_t size);
+#ifdef HAVE_LOCKS
+#include <pthread.h>
+#endif /* HAVE_LOCKS */
 
-int map_thread_pool(void);
+/** The allocator structure of dmmlib. */
+typedef struct allocator_s {
+    raw_block_header_t *raw_block_head; /**< The head of the raw blocks list. */
+#ifdef HAVE_LOCKS
+    pthread_mutex_t creation_mutex; /**< Mutex to allow the creation of new raw
+                                      blocks. */
+#endif /* HAVE_LOCKS */
+} allocator_t;
 
-#endif /* OTHER_H */
+#endif /* ALLOCATOR_H */

+ 46 - 7
include/dmmlib/dmmlib.h

@@ -1,5 +1,5 @@
 /*
- *   Copyright 2011 Institute of Communication and Computer Systems (ICCS) 
+ *   Copyright 2012 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.
@@ -15,14 +15,53 @@
  *
  */
 
+/**
+ * @file   dmmlib.h
+ * @author Ioannis Koutras (joko@microlab.ntua.gr)
+ * @date   August 2012
+ * @brief  Memory allocation and de-allocation functions.
+ *
+ * This file should be used when linking directly dmmlib to your project.
+ * Warning: In case you also use the C standard library, do not forget to link
+ * dmmlib first or else your project will use C standard library's
+ * implementations for dynamic memory management.
+ */
+
 #ifndef DMMLIB_H
 #define DMMLIB_H
-#include "dmm_config.h"
-#include <dmmlib/pool.h>
-#include <dmmlib/custom_realloc.h>
+#include <dmmlib/allocator.h>
+
+/** Global variable storing allocator's settings */
+allocator_t systemallocator;
 
-#ifdef WITH_SINGLE_ALLOCATOR
-#include <dmmlib/single_allocator.h>
-#endif /* WITH_SINGLE_ALLOCATOR */
+/**
+ * Allocates size bytes by using the system's allocator.
+ * @param size Requested allocation size in bytes.
+ */
+void * malloc(size_t size);
+
+/**
+ * De-allocates the memory space pointed to by ptr.
+ * @param   ptr     The pointer to memory to free.
+ */
+void free(void *ptr);
+
+/**
+ * Try to change the size of an allocation
+ * @param   ptr	    The pointer to the data part of the original memory block.
+ * @param   size    The new desired size of the block.
+ *
+ * @return  The pointer to the new memory location.
+ */
+void * realloc(void *ptr, size_t size);
+
+/**
+ * Allocate enough space for a number of objects of a specific size.
+ * @param   count   The number of objects.
+ * @param   size    The size of one object.
+ *
+ * @return  A pointer to the allocated memory.
+ */
+void * calloc(size_t count, size_t size);
 
 #endif /* DMMLIB_H */

+ 44 - 0
include/dmmlib/dmmstats.h

@@ -0,0 +1,44 @@
+/*
+ *   Copyright 2012 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   dmmstats.h
+ * @author Ioannis Koutras (joko@microlab.ntua.gr)
+ * @date   September 2012
+ * @brief  Statistics data structure.
+ */
+
+#ifndef DMMSTATS_H
+#define DMMSTATS_H
+
+#include <stddef.h> /* for size_t */
+#include <inttypes.h>
+
+/** Statistics data structure. */
+typedef struct dmmstats_s {
+#ifdef REQUEST_SIZE_INFO
+    size_t total_mem_requested; /**< Total memory actively used by the
+                                  application. */
+#endif /* REQUEST_SIZE_INFO */
+    size_t total_mem_allocated; /**< Total memory allocated by the 
+                                  application. */
+    uint32_t live_objects; /**< Number of the currently used blocks. */
+    uint32_t num_malloc; /**< Number of malloc()'s served. */
+    uint32_t num_free; /**< Number of free()'s served. */
+} dmmstats_t;
+
+#endif /* DMMSTATS_H */

+ 0 - 93
include/dmmlib/pool.h

@@ -1,93 +0,0 @@
-/*
- *   Copyright 2011 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 	pool.h
- * \author 	Ioannis Koutras (joko@microlab.ntua.gr)
- * \date 	June, 2012
- * 	Basic structures needed for the dmmlib allocator.
- */
-
-#ifndef POOL_H
-#define POOL_H
-
-#include "dmm_config.h"
-
-#include <inttypes.h>
-#include <stdbool.h>
-#include <stddef.h> /* For size_t support */
-
-#ifdef HAVE_LOCKS
-#include <pthread.h>
-#endif /* HAVE_LOCKS */
-
-#include <dmmlib/raw_block.h>
-
-#ifdef LEON3
-typedef __uint32_t uint32_t ;
-#endif /* LEON3 */
-
-#ifdef WITH_KNOBS
-/**
- * A structure for knobs states (currently 5)
- * 
- * FIXME Have to check them
- *
- * */
-typedef uint8_t knob_state_t;
-#endif /* WITH_KNOBS */
-
-#ifdef WITH_KNOBS
-/** A structure to represent tunable parameters of a heap */
-typedef struct dmmknobs_s {
-	float frag_threshold; /**< Fragmentation threshold to enable coalescing
-				or not. */ 
-	uint32_t mem_threshold; /**< Memory size threshold. */
-#ifdef GOOD_FIT
-	float fit_percentage; /**< Fit percentage for good-fit searches. */
-#endif  /* GOOD_FIT */
-#ifdef POOL_VAR_FIT
-	/** Current search policy on the allocator's free lists. */
-	void *(*search_policy)(heap_t * heap, size_t requested_size);
-#endif /* HEAP_VAR_FIT */
-#ifdef COALESCING_VARIABLE
-	size_t max_coalesce_size; /**< Maximum coalesce size; -1 if coalescing
-				     is not supported */
-#endif /* COALESCING_VARIABLE */
-#ifdef SPLITTING_VARIABLE
-	size_t min_split_size; /**< Minimum split size. */
-#endif /* SPLITTING_VARIABLE */
-	/* FIXME Need to find explanation */
-	float empty_threshold; /**< Empty Threshold */
-	uint32_t percentage; /**< Percentage value */
-	knob_state_t frag_state; /**< The current state of fragmentation. */
-	knob_state_t foot_state; /**< The current state of footprint. */
-} dmmknobs_t;
-#endif /* WITH_KNOBS */
-
-/** The allocator structure of dmmlib. */
-typedef struct allocator_s {
-    raw_block_header_t *raw_block_head; /**< The head of the raw blocks list. */
-    pthread_mutex_t creation_mutex; /**< Mutex to allow the creation of new
-                                      pools. */
-#ifdef ALLOC_VAR_FIT
-	/** Current search policy on the allocator's free lists. */
-	void *(*search_policy)(heap_t * heap, size_t requested_size);
-#endif /* ALLOC_VAR_FIT */
-} allocator_t;
-
-#endif /* HEAP_H */

+ 0 - 32
include/dmmlib/print_stats.h

@@ -1,32 +0,0 @@
-/*
- *   Copyright 2011 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.
- *
- */
-
-#ifndef PRINT_STATS_H
-#define PRINT_STATS_H
-
-#include <dmmlib/heap.h>
-
-size_t get_used_space(heap_t *heap);
-size_t get_allocated_space(heap_t *heap);
-
-#ifdef REQUEST_SIZE_INFO
-size_t get_requested_space(heap_t *heap);
-#endif /* REQUEST_SIZE_INFO */
-
-void print_stats(allocator_t *allocator);
-
-#endif /* PRINT_STATS_H */

+ 11 - 30
include/dmmlib/raw_block.h

@@ -1,5 +1,5 @@
 /*
- *   Copyright 2011 Institute of Communication and Computer Systems (ICCS) 
+ *   Copyright 2012 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.
@@ -16,47 +16,28 @@
  */
 
 /**
- * \file        raw_block.h
- * \author 	Ioannis Koutras (joko@microlab.ntua.gr)
- * \date 	August, 2012
- *  
- * \brief       Raw block structure and functions.
+ * @file   raw_block.h
+ * @author Ioannis Koutras (joko@microlab.ntua.gr)
+ * @date   September 2012
+ * @brief  Raw block structure and functions.
  */
 
 #ifndef RAW_BLOCK_H
 #define RAW_BLOCK_H
-
-#include <stddef.h> /* for size_t */
-#include <inttypes.h>
-#include <pthread.h> /* FIXME To be removed once mutex is removed. */
-#include <dmmlib/block_header.h>
+#include "dmm_config.h"
 
 #ifdef WITH_STATS
-/** Statistics data structure. */
-typedef struct dmmstats_s {
-#ifdef REQUEST_SIZE_INFO
-    size_t total_mem_requested; /**< Total memory actively used by the
-                                  application. */
-#endif /* REQUEST_SIZE_INFO */
-    size_t total_mem_allocated; /**< Total memory allocated by the 
-                                  application. */
-    uint32_t live_objects; /**< Number of the currently used blocks. */
-    uint32_t num_malloc; /**< Number of malloc()'s served. */
-    uint32_t num_free; /**< Number of free()'s served. */
-} dmmstats_t;
+#include <dmmlib/dmmstats.h>
 #endif /* WITH_STATS */
+#ifdef HAVE_LOCKS
+#include <pthread.h> /* FIXME To be removed once mutex is removed. */
+#endif /* HAVE_LOCKS */
 
 /** The header structure of every raw block inside a heap. */
 typedef struct raw_block_header_s {
+    size_t size; /**< Total available size of the raw block. */
     struct raw_block_header_s *next_raw_block; /**< Pointer to the next raw
                                                  block. */
-    size_t size; /**< Total available size of the memory block. */
-    block_header_t *border_ptr; /**< Pointer to the memory block allocated last. */
-    size_t remaining_size; /**< Remaining, never allocated before, size. */
-    block_header_t *free_list_head; /**< Head of the free list of memory blocks. */
-#ifdef FIFO_SORT_POLICY
-    block_header_t *free_list_tail; /**< The tail of the free list. */
-#endif /* FIFO_SORT_POLICY */
 #ifdef WITH_STATS
     dmmstats_t dmm_stats; /**< Statistics of the heap. */
 #endif /* WITH_STATS */

+ 0 - 60
include/dmmlib/single_allocator.h

@@ -1,60 +0,0 @@
-/*
- *   Copyright 2011 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 	single_allocator.h
- * \author 	Ioannis Koutras (joko@microlab.ntua.gr)
- * \date 	September, 2011
- * 	Basic structures needed for the dmmlib allocator.
- */
-
-#ifndef SINGLE_ALLOCATOR_H
-#define SINGLE_ALLOCATOR_H
-
-#include <dmmlib/pool.h>
-
-/* In case stdlib.h is used, there is no need to redeclare
- * malloc() and free()
- */
-
-/**
- * Allocates size bytes by using the system's allocator.
- * \param   size    Requested allocation size in bytes.
- */
-void *dmmlib_malloc(size_t size);
-
-/**
- * De-allocates the memory space pointed to by ptr.
- * \param   ptr     The pointer to memory to free.
- */
-void dmmlib_free(void *ptr);
-
-/**
- * Try to change the size of an allocation
- * \param   ptr	    The pointer to the data part of the original memory block.
- * \param   size    The new desired size of the block.
- *
- * \return  The pointer to the data part of the memory block which
- * has the new, desired size.
- */
-void * dmmlib_realloc(void *ptr, size_t size);
-
-
-/** Global variable storing allocator's settings */
-allocator_t systemallocator;
-
-#endif /* SINGLE_ALLOCATOR_H */

include/dmmlib/block_header.h → private-include/freelist/block_header.h


+ 7 - 9
private-include/freelist/block_header_funcs.h

@@ -25,8 +25,8 @@
 #ifndef BLOCK_HEADER_FUNCS_H
 #define BLOCK_HEADER_FUNCS_H
 
-#include <dmmlib/block_header.h>
-#include <dmmlib/raw_block.h>
+#include "freelist/block_header.h"
+#include "freelist/freelist_rb.h"
 
 /**
  * \brief Get the address of the block header of a memory block.
@@ -83,7 +83,7 @@ size_t get_size_availability(block_header_t *ptr);
  * \param ptr 	The pointer to the data part of the current memory block.
  * \param size 	The size of the data part of the current memory block.
  */
-void set_size_and_free(raw_block_header_t *raw_block, block_header_t *ptr, size_t size);
+void set_size_and_free(freelist_rb_t *raw_block, block_header_t *ptr, size_t size);
 
 /**
  * Set the size of the memory block's data and mark it used
@@ -92,7 +92,7 @@ void set_size_and_free(raw_block_header_t *raw_block, block_header_t *ptr, size_
  * \param ptr 	The pointer to the data part of the current memory block.
  * \param size 	The size of the data part of the current memory block.
  */
-void set_size_and_used(raw_block_header_t *raw_block, block_header_t *ptr, size_t size);
+void set_size_and_used(freelist_rb_t *raw_block, block_header_t *ptr, size_t size);
 
 /**
  * Mark the memory block as used, as well as the previous_size element of the
@@ -101,7 +101,7 @@ void set_size_and_used(raw_block_header_t *raw_block, block_header_t *ptr, size_
  * \param raw_block The pointer to the raw block which includes the block.
  * \param ptr 	The pointer to the data part of the memory block.
  */
-void mark_used(raw_block_header_t *raw_block, block_header_t *ptr);
+void mark_used(freelist_rb_t *raw_block, block_header_t *ptr);
 
 /**
  * Mark the memory block as free, as well as the previous_size element of the
@@ -110,7 +110,7 @@ void mark_used(raw_block_header_t *raw_block, block_header_t *ptr);
  * \param raw_block The pointer to the raw block which includes the block.
  * \param ptr 	The pointer to the data part of the memory block.
  */
-void mark_free(raw_block_header_t *raw_block, block_header_t *ptr);
+void mark_free(freelist_rb_t *raw_block, block_header_t *ptr);
 
 /**
  * Set the availability and the size of the previous memory block
@@ -165,8 +165,6 @@ block_header_t * get_dlprevious(block_header_t *ptr);
  * \return The pointer to the data part of the next block.
  * \retval NULL There is no next block.
  */
-block_header_t * get_dlnext(raw_block_header_t *raw_block, block_header_t *ptr);
-
-
+block_header_t * get_dlnext(freelist_rb_t *raw_block, block_header_t *ptr);
 
 #endif /* BLOCK_HEADER_FUNCS_H */

+ 8 - 1
private-include/freelist/freelist_malloc.h

@@ -26,10 +26,17 @@
 #define FREELIST_MALLOC_H
 
 #include <dmmlib/raw_block.h>
-#include <dmmlib/block_header.h>
+
+#ifdef FL_RB_ONLY
+#define dmmlib_malloc(raw_block, size) freelist_malloc(raw_block, size)
+#endif /* FL_RB_ONLY */
 
 void * freelist_malloc(raw_block_header_t *raw_block, size_t size);
 
+#ifdef FL_RB_ONLY
+#define dmmlib_free(raw_block, size) freelist_free(raw_block, size)
+#endif /* FL_RB_ONLY */
+
 void freelist_free(raw_block_header_t *raw_block, void *ptr);
 
 #endif /* FREELIST_MALLOC_H */

+ 39 - 0
private-include/freelist/freelist_rb.h

@@ -0,0 +1,39 @@
+/*
+ *   Copyright 2012 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   freelist_rb.h
+ * @author Ioannis Koutras (joko@microlab.ntua.gr)
+ * @date   August 2012
+ * @brief  Freelist raw block structure and creation function.
+ */
+
+#ifndef FREELIST_RB_H
+#define FREELIST_RB_H
+#include "freelist/block_header.h"
+
+/** Data structure of the required elements for a free-list organized raw block.
+ */
+typedef struct freelist_rb_s {
+    block_header_t *border_ptr; /**< Pointer to the memory block allocated last. */
+    block_header_t *free_list_head; /**< Head of the free list of memory blocks. */
+#ifdef FIFO_SORT_POLICY
+    block_header_t *free_list_tail; /**< The tail of the free list. */
+#endif /* FIFO_SORT_POLICY */
+} freelist_rb_t;
+
+#endif /* FREELIST_RB_H */

+ 3 - 4
private-include/freelist/linked_lists/lifo_order.h

@@ -25,10 +25,9 @@
 
 #ifndef LIFO_ORDER_H
 #define LIFO_ORDER_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"
 
 #ifdef LIFO_SORT_POLICY
 #define add_block(raw_block, block) add_block_lifo_order(raw_block, block)
@@ -41,7 +40,7 @@
  * @param block The pointer of the block to be added.
  */
 void add_block_lifo_order(
-        raw_block_header_t *raw_block,
+        freelist_rb_t *raw_block,
         block_header_t *block);
 
 #endif /* LIFO_ORDER_H */

+ 3 - 3
private-include/freelist/linked_lists/linked_lists.h

@@ -33,8 +33,8 @@
 #include <sys/types.h>
 #endif /* LEON3 */
 
-#include <dmmlib/block_header.h>
-#include <dmmlib/raw_block.h>
+#include "freelist/block_header.h"
+#include "freelist/freelist_rb.h"
 
 #ifdef BLOCKS_IN_DLL
 
@@ -66,6 +66,6 @@ void * get_previous(void *ptr);
  * \param block A pointer to the block to be removed.
  * \param raw_block A pointer to the raw block.
  */
-void remove_block(block_header_t *block, raw_block_header_t *raw_block);
+void remove_block(block_header_t *block, freelist_rb_t *raw_block);
 
 #endif /* LINKED_LISTS_H */

+ 6 - 7
private-include/freelist/linked_lists/search_algorithms.h

@@ -25,9 +25,8 @@
 
 #ifndef LINKED_LISTS_SEARCH_ALGORITHMS_H
 #define LINKED_LISTS_SEARCH_ALGORITHMS_H
-
-#include <dmmlib/raw_block.h>
-#include <dmm_config.h>
+#include "dmm_config.h"
+#include "freelist/freelist_rb.h"
 
 /**
  * Perform a best-fit search on free lists for a block of a certain size
@@ -38,7 +37,7 @@
  * \return The pointer of the data part of the matched memory block.
  * \retval NULL No block was found.
  */
-block_header_t * best_fit_on_freelist(raw_block_header_t *raw_block, size_t requested_size);
+block_header_t * best_fit_on_freelist(freelist_rb_t *raw_block, size_t requested_size);
 
 #ifdef GOOD_FIT
 
@@ -51,7 +50,7 @@ block_header_t * best_fit_on_freelist(raw_block_header_t *raw_block, size_t requ
  * \return The pointer to the data part of the matched memory block.
  * \retval NULL No block was found.
  */
-block_header_t * good_fit_on_freelist(raw_block_header_t *raw_block, size_t requested_size);
+block_header_t * good_fit_on_freelist(freelist_rb_t *raw_block, size_t requested_size);
 
 #endif /* GOOD_FIT */
 
@@ -64,7 +63,7 @@ block_header_t * good_fit_on_freelist(raw_block_header_t *raw_block, size_t requ
  * \return The pointer of the data part of the matched memory block.
  * \retval NULL No block was found.
  */
-block_header_t * exact_fit_on_freelist(raw_block_header_t *raw_block, size_t requested_size);
+block_header_t * exact_fit_on_freelist(freelist_rb_t *raw_block, size_t requested_size);
 
 /**
  * Perform a first-fit search on free lists for a block of a certain size
@@ -75,7 +74,7 @@ block_header_t * exact_fit_on_freelist(raw_block_header_t *raw_block, size_t req
  * \return The pointer of the data part of the matched memory block.
  * \retval NULL No block was found.
  */
-block_header_t * first_fit_on_freelist(raw_block_header_t *raw_block, size_t requested_size);
+block_header_t * first_fit_on_freelist(freelist_rb_t *raw_block, size_t requested_size);
 
 #endif /* LINKED_LISTS_SEARCH_ALGORITHMS_H */
 

+ 1 - 1
private-include/request_memory.h

@@ -25,7 +25,7 @@
 #ifndef REQUEST_MEMORY_H
 #define REQUEST_MEMORY_H
 
-#include <stddef.h>
+#include <stddef.h> /* for size_t */
 
 /**
  * Requests memory address space from the OS.

+ 52 - 51
src/CMakeLists.txt

@@ -29,15 +29,61 @@ if (WITH_STATIC_LIB)
 endif (WITH_STATIC_LIB)
 
 set(dmmlib_SRCS
-  freelist/block_header_funcs.c
-  freelist/linked_lists/linked_lists.c
-  freelist/linked_lists/search_algorithms.c
-  freelist/freelist_malloc.c
+  dmmlib.c
   raw_block.c
-  other.c
-  debug.c
+  #debug.c FIXME
 )
 
+if(RAW_BLOCKS_TYPE STREQUAL "freelist")
+
+  set(dmmlib_SRCS
+    ${dmmlib_SRCS}
+    freelist/block_header_funcs.c
+    freelist/linked_lists/linked_lists.c
+    freelist/linked_lists/search_algorithms.c
+    freelist/freelist_malloc.c
+    )
+
+  if(SORT_POLICY STREQUAL "lifo")
+    set(dmmlib_SRCS
+      ${dmmlib_SRCS}
+      freelist/linked_lists/lifo_order.c
+      )
+  elseif(SORT_POLICY STREQUAL "fifo")
+    set(dmmlib_SRCS
+      ${dmmlib_SRCS}
+      freelist/linked_lists/fifo_order.c
+      )
+  elseif(SORT_POLICY STREQUAL "size")
+    set(dmmlib_SRCS
+      ${dmmlib_SRCS}
+      freelist/linked_lists/add_block_in_order.c
+      freelist/linked_lists/size_order.c
+      )
+  elseif(SORT_POLICY STREQUAL "address")
+    set(dmmlib_SRCS
+      ${dmmlib_SRCS}
+      freelist/linked_lists/add_block_in_order.c
+      freelist/linked_lists/address_order.c
+      )
+  endif(SORT_POLICY STREQUAL "lifo")
+
+  if(COALESCING_FIXED OR COALESCING_VARIABLE)
+    set(dmmlib_SRCS
+      ${dmmlib_SRCS}
+      freelist/coalesce.c
+      )
+  endif(COALESCING_FIXED OR COALESCING_VARIABLE)
+
+  if(SPLITTING_FIXED OR SPLITTING_VARIABLE)
+    set(dmmlib_SRCS
+      ${dmmlib_SRCS}
+      freelist/split.c
+      )
+  endif(SPLITTING_FIXED OR SPLITTING_VARIABLE)
+
+endif(RAW_BLOCKS_TYPE STREQUAL "freelist")
+
 if(WITH_SYSTEM_CALLS STREQUAL "none")
   set(NO_SYSTEM_CALLS ON)
 elseif(WITH_SYSTEM_CALLS STREQUAL "sbrk")
@@ -60,51 +106,6 @@ elseif(WITH_SYSTEM_CALLS STREQUAL "mmap")
 
 endif(WITH_SYSTEM_CALLS STREQUAL "none")
 
-if (WITH_SINGLE_ALLOCATOR)
-  set(dmmlib_SRCS
-    ${dmmlib_SRCS}
-    single_allocator.c
-  )
-endif (WITH_SINGLE_ALLOCATOR)
-
-if(SORT_POLICY STREQUAL "lifo")
-  set(dmmlib_SRCS
-    ${dmmlib_SRCS}
-    freelist/linked_lists/lifo_order.c
-  )
-elseif(SORT_POLICY STREQUAL "fifo")
-  set(dmmlib_SRCS
-    ${dmmlib_SRCS}
-    freelist/linked_lists/fifo_order.c
-  )
-elseif(SORT_POLICY STREQUAL "size")
-  set(dmmlib_SRCS
-    ${dmmlib_SRCS}
-    freelist/linked_lists/add_block_in_order.c
-    freelist/linked_lists/size_order.c
-  )
-elseif(SORT_POLICY STREQUAL "address")
-  set(dmmlib_SRCS
-    ${dmmlib_SRCS}
-    freelist/linked_lists/add_block_in_order.c
-    freelist/linked_lists/address_order.c
-  )
-endif(SORT_POLICY STREQUAL "lifo")
-
-if (COALESCING_FIXED OR COALESCING_VARIABLE)
-  set(dmmlib_SRCS
-    ${dmmlib_SRCS}
-    freelist/coalesce.c
-  )
-endif (COALESCING_FIXED OR COALESCING_VARIABLE)
-
-if (SPLITTING_FIXED OR SPLITTING_VARIABLE)
-  set(dmmlib_SRCS
-    ${dmmlib_SRCS}
-    freelist/split.c
-  )
-endif (SPLITTING_FIXED OR SPLITTING_VARIABLE)
-
 if (WITH_STATS)
   set(dmmlib_SRCS
     ${dmmlib_SRCS}

+ 1 - 1
src/debug.c

@@ -1,5 +1,5 @@
 #include <stdio.h>
-#include <dmmlib/block_header.h>
+#include "dmmlib/block_header.h"
 #include "freelist/block_header_funcs.h"
 #include "freelist/linked_lists/search_algorithms.h"
 #include "debug.h"

+ 36 - 46
src/single_allocator.c

@@ -1,5 +1,5 @@
 /*
- *   Copyright 2011 Institute of Communication and Computer Systems (ICCS) 
+ *   Copyright 2012 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.
@@ -16,23 +16,21 @@
  */
 
 /**
- * \file    single_allocator.c
- * \author  Ioannis Koutras (joko@microlab.ntua.gr)
- * \date    March, 2012
+ * @file   dmmlib.c
+ * @author Ioannis Koutras (joko@microlab.ntua.gr)
+ * @date   September 2012
  *
- * \brief   Implementations of malloc(), free() and realloc() calls while using
- * just one allocator.
+ * @brief  Implementations of malloc(), free() and calloc() calls.
  */
 
-#include <dmmlib/single_allocator.h>
+#include "dmmlib/dmmlib.h"
+#ifdef FL_RB_ONLY
 #include "freelist/freelist_malloc.h"
-#include "other.h"
-#include <dmmlib/block_header.h>
-#include <dmmlib/dmmlib.h>
+#include "freelist/block_header.h"
+#endif /* FL_RB_ONLY */
+#include <string.h> /* for memset() */
 
-#include <stdio.h>
-
-void * dmmlib_malloc(size_t size) {
+void * malloc(size_t size) {
     raw_block_header_t *raw_block, *new_raw_block;
     size_t allocation_size;
     void *ptr;
@@ -43,7 +41,7 @@ void * dmmlib_malloc(size_t size) {
     /* Try to find a raw block available for allocation */
 
     while(raw_block != NULL) {
-        ptr = freelist_malloc(raw_block, size);
+        ptr = dmmlib_malloc(raw_block, size);
         if(ptr != NULL) {
             break;
         }
@@ -76,7 +74,7 @@ void * dmmlib_malloc(size_t size) {
     return ptr;
 }
 
-void dmmlib_free(void *ptr) {
+void free(void *ptr) {
     raw_block_header_t *current_raw_block;
     bool found;
 
@@ -84,42 +82,34 @@ void dmmlib_free(void *ptr) {
 
     current_raw_block = systemallocator.raw_block_head;
     while(current_raw_block) {
-        if(current_raw_block->border_ptr != NULL) {
-            if(((char *)current_raw_block < (char *)ptr) &&
-                    ((char *)ptr < (char *)(current_raw_block->border_ptr))) {
-                found = true;
-                break;
-            }
+        if((char *)ptr - (char *)(current_raw_block) -
+                sizeof(raw_block_header_t) < current_raw_block->size) {
+            found = true;
+            break;
         }
         current_raw_block = current_raw_block->next_raw_block;
     }
 
     if(found == true) {
-        freelist_free(current_raw_block, ptr);
+        dmmlib_free(current_raw_block, ptr);
     }
 }
 
-/* void * realloc(void *ptr, size_t size) { */
-/*     allocator_t *allocator; */
-/*     heap_t *heap; */
-/*     int heap_id; */
-
-/*     allocator = &systemallocator; */
-/*     /1* Space aware allocators have to be already initialized, no need to do */
-/*      * that here. *1/ */
-/* #ifndef NO_SYSTEM_CALLS */
-/*     if(allocator->initialized != true) { */
-/*         initialize_allocator(allocator); */
-/*     } */
-/* #endif /1* NO_SYSTEM_CALLS *1/ */
-
-/*     /1* FIXME Space aware allocators currently use one heap *1/ */
-/* #ifdef NO_SYSTEM_CALLS */
-/*     heap_id = 0; */
-/* #else /1* NO_SYSTEM_CALLS *1/ */
-/*     heap_id = map_thread_heap(); */
-/* #endif /1* NO_SYSTEM_CALLS *1/ */
-/*     heap = &allocator->heaps[heap_id]; */
-
-/*     return custom_ahrealloc(allocator, heap, ptr, size); */
-/* } */
+void * calloc(size_t nmemb, size_t size) {
+    size_t i;
+    char *buf[nmemb];
+
+    if(nmemb == 0 || size == 0) {
+        return NULL;
+    }
+
+    i = 0;
+
+    while(i < nmemb) {
+        buf[i] = (char*)malloc(size);
+        memset(buf[i], '\0', size);
+        i++;
+    }
+
+    return buf[0];
+}

+ 5 - 5
src/freelist/block_header_funcs.c

@@ -39,7 +39,7 @@ size_t get_size_availability(block_header_t *ptr) {
     return ptr->size;
 }
 
-void set_size_and_free(raw_block_header_t *raw_block, block_header_t *ptr, size_t size) {
+void set_size_and_free(freelist_rb_t *raw_block, block_header_t *ptr, size_t size) {
     block_header_t *next_block_header;
 
     ptr->size = size << 1;
@@ -50,7 +50,7 @@ void set_size_and_free(raw_block_header_t *raw_block, block_header_t *ptr, size_
     }
 }
 
-void set_size_and_used(raw_block_header_t *raw_block, block_header_t *ptr, size_t size) {
+void set_size_and_used(freelist_rb_t *raw_block, block_header_t *ptr, size_t size) {
     block_header_t *next_block_header;
 
     ptr->size = size << 1;
@@ -62,7 +62,7 @@ void set_size_and_used(raw_block_header_t *raw_block, block_header_t *ptr, size_
     }
 }
 
-void mark_used(raw_block_header_t *raw_block, block_header_t *ptr) {
+void mark_used(freelist_rb_t *raw_block, block_header_t *ptr) {
     block_header_t *next_block_header;
 
     ptr->size |= 1;
@@ -73,7 +73,7 @@ void mark_used(raw_block_header_t *raw_block, block_header_t *ptr) {
     }
 }
 
-void mark_free(raw_block_header_t *raw_block, block_header_t *ptr) {
+void mark_free(freelist_rb_t *raw_block, block_header_t *ptr) {
     block_header_t *next_block_header;
     
     ptr->size &= (~ ((size_t) 0x1));
@@ -120,7 +120,7 @@ block_header_t * get_dlprevious(block_header_t *ptr) {
     return (block_header_t *) ((char *) ptr - HEADER_SIZE - get_previous_size(ptr));
 }
 
-block_header_t * get_dlnext(raw_block_header_t *raw_block, block_header_t *ptr) {
+block_header_t * get_dlnext(freelist_rb_t *raw_block, block_header_t *ptr) {
     if(raw_block->border_ptr != ptr) {
         return (block_header_t *) ((char *) ptr + get_size(ptr) + HEADER_SIZE);
     } else {

+ 61 - 24
src/freelist/freelist_malloc.c

@@ -25,7 +25,6 @@
 #include "freelist/block_header_funcs.h"
 #include "freelist/linked_lists/linked_lists.h"
 #include "freelist/linked_lists/search_algorithms.h"
-#include "other.h"
 
 #if defined (SPLITTING_FIXED) || defined (SPLITTING_VARIABLE)
 #include "freelist/split.h"
@@ -33,22 +32,50 @@
 
 #include "freelist/freelist_malloc.h"
 
-#include <stdio.h>
-
 #if defined (BEST_FIT)
-#define search_on_free(size) best_fit_on_freelist(raw_block, size)
+#define search_on_free(size) best_fit_on_freelist(rb_header, size)
 #elif defined (GOOD_FIT)
-#define search_on_free(size) good_fit_on_freelist(raw_block, size)
+#define search_on_free(size) good_fit_on_freelist(rb_header, size)
 #elif defined (EXACT_FIT)
-#define search_on_free(size) exact_fit_on_freelist(raw_block, size)
+#define search_on_free(size) exact_fit_on_freelist(rb_header, size)
 #elif defined (FIRST_FIT)
-#define search_on_free(size) first_fit_on_freelist(raw_block, size)
-#endif /* BEST_FIT */
+#define search_on_free(size) first_fit_on_freelist(rb_header, size)
+#endif /* BEST_FIT */ 
+
+size_t req_padding(size_t size);
+
+size_t req_padding(size_t size) {
+    size_t align;
+
+    if(size <= 32)
+        return 32;
+    if(size <= 64)
+        return 64;
+    if(size <= 128)
+        return 128;
+    if(size <= 256)
+        return 256;
+
+    align = size % 4;
+    if(align != 0) {
+        size += 4 - align;
+    }
+
+    return size;
+}
 
+/** Tries to allocate memory from a specific free-list organized raw block.
+ * @param raw_block The pointer of the raw block.
+ * @param size      The requested size.
+ * @retval          The address of the returned memory space.
+ */
 void * freelist_malloc(raw_block_header_t *raw_block, size_t size) {
+    freelist_rb_t *rb_header;
     block_header_t *ptr;
     size_t allocation_size, previous_size, previous_size_availability;
 
+    rb_header = (freelist_rb_t *)((char *)raw_block +
+            sizeof(raw_block_header_t));
     ptr = NULL;
 
 #ifdef HAVE_LOCKS
@@ -64,32 +91,34 @@ void * freelist_malloc(raw_block_header_t *raw_block, size_t size) {
 
         /* Try to split */
 #if defined (SPLITTING_FIXED) || defined (SPLITTING_VARIABLE)
-        split(raw_block, ptr, size);
+        split(rb_header, ptr, size);
 #endif /* (SPLITTING_FIXED) || (SPLITTING_VARIABLE) */
 
-        mark_used(raw_block, ptr);
+        mark_used(rb_header, ptr);
     } else {
 
         allocation_size = req_padding(size) + HEADER_SIZE;
-        if(allocation_size < raw_block->remaining_size) {
-            if(raw_block->border_ptr == NULL) {
+
+        if(allocation_size < (char *) raw_block + raw_block->size -
+                (char *) rb_header->border_ptr -
+                get_size(rb_header->border_ptr)) {
+            if(rb_header->border_ptr == (block_header_t *)((char *)rb_header +
+                        sizeof(freelist_rb_t))) {
                 previous_size_availability = 1; // Occupied and of 0 size
-                ptr = (block_header_t *)((char *)raw_block +
-                        sizeof(raw_block_header_t));
+                ptr = (block_header_t *)((char *)rb_header +
+                        sizeof(freelist_rb_t));
             } else {
-                previous_size = get_size(raw_block->border_ptr);
+                previous_size = get_size(rb_header->border_ptr);
                 previous_size_availability =
-                    get_size_availability(raw_block->border_ptr);
-                ptr = (block_header_t *)((char *)raw_block->border_ptr +
+                    get_size_availability(rb_header->border_ptr);
+                ptr = (block_header_t *)((char *)rb_header->border_ptr +
                         previous_size);
             }
 
-            // Update raw block metadata
-            raw_block->remaining_size -= allocation_size;
-            raw_block->border_ptr = ptr;
+            rb_header->border_ptr = ptr;
 
             // Update block metadata
-            set_size_and_used(raw_block, ptr, req_padding(size));
+            set_size_and_used(rb_header, ptr, req_padding(size));
             set_previous_size_availability(ptr, previous_size_availability);
 #ifdef REQUEST_SIZE_INFO
             set_requested_size(ptr, req_padding(size));
@@ -126,7 +155,15 @@ void * freelist_malloc(raw_block_header_t *raw_block, size_t size) {
 #include "freelist/coalesce.h"
 #endif /* COALESCING_FIXED || COALESCING_VARIABLE */
 
+/** Frees the memory block inside of a specific free-list organized raw block.
+ * @param raw_block The pointer of the raw block.
+ * @param ptr       The pointer of the memory block to be freed.
+ */
 void freelist_free(raw_block_header_t *raw_block, void *ptr) {
+    freelist_rb_t *rb_header;
+
+    rb_header = (freelist_rb_t *)((char *)raw_block +
+            sizeof(raw_block_header_t));
     ptr = get_header(ptr);
 
 #ifdef HAVE_LOCKS
@@ -138,10 +175,10 @@ void freelist_free(raw_block_header_t *raw_block, void *ptr) {
 #endif /* WITH_STATS */
 
 #if defined (COALESCING_FIXED) || defined (COALESCING_VARIABLE)
-    coalesce(raw_block, ptr);
+    coalesce(rb_header, ptr);
 #else
-    mark_free(raw_block, ptr);
-    add_block(raw_block, ptr);
+    mark_free(rb_header, ptr);
+    add_block(rb_header, ptr);
 #endif /* COALESCING_FIXED || COALESCING_VARIABLE */
 
 #ifdef WITH_STATS

+ 1 - 1
src/freelist/linked_lists/lifo_order.c

@@ -18,7 +18,7 @@
 #include "freelist/linked_lists/lifo_order.h"
 
 void add_block_lifo_order(
-        raw_block_header_t *raw_block,
+        freelist_rb_t *raw_block,
         block_header_t *block) {
     
     block->next = raw_block->free_list_head;

+ 1 - 1
src/freelist/linked_lists/linked_lists.c

@@ -30,7 +30,7 @@ void * get_previous(void *ptr) {
 #endif /* BLOCKS_IN_DLL */
 
 #ifdef BLOCKS_IN_SLL
-void remove_block(block_header_t *block, raw_block_header_t *raw_block) {
+void remove_block(block_header_t *block, freelist_rb_t *raw_block) {
 
     block_header_t *current_node, *previous_node;
 

+ 3 - 3
src/freelist/linked_lists/search_algorithms.c

@@ -28,7 +28,7 @@
  * time a new best candidate is found, so that we stop once a perfect block is
  * found.
  */
-block_header_t * best_fit_on_freelist(raw_block_header_t *raw_block, size_t requested_size) {
+block_header_t * best_fit_on_freelist(freelist_rb_t *raw_block, size_t requested_size) {
     block_header_t *current_block, *previous_block;
     block_header_t *best_block, *best_previous_block;
     size_t best_size, block_size;
@@ -147,7 +147,7 @@ void * good_fit_on_freelist(raw_block_header_t *raw_block, size_t requested_size
  * keep track of the previous block as well: The previous block must point to
  * the current block's next block once the current one is removed.
  */
-block_header_t * exact_fit_on_freelist(raw_block_header_t *raw_block, size_t requested_size) {
+block_header_t * exact_fit_on_freelist(freelist_rb_t *raw_block, size_t requested_size) {
     block_header_t *current_block, *previous_block, *ptr;
 
     previous_block = NULL;
@@ -181,7 +181,7 @@ block_header_t * exact_fit_on_freelist(raw_block_header_t *raw_block, size_t req
  * keep track of the previous block as well: The previous block must point to
  * the current block's next block once the current one is removed.
  */
-block_header_t * first_fit_on_freelist(raw_block_header_t *raw_block, size_t requested_size) {
+block_header_t * first_fit_on_freelist(freelist_rb_t *raw_block, size_t requested_size) {
     block_header_t *current_block, *previous_block, *ptr;
 
     previous_block = NULL;

+ 0 - 66
src/other.c

@@ -1,66 +0,0 @@
-/*
- *   Copyright 2011 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.
- *
- */
-
-#include "other.h"
-#include <pthread.h>
-
-size_t req_padding(size_t size) {
-    size_t align;
-
-    if(size <= 32)
-        return 32;
-    if(size <= 64)
-        return 64;
-    if(size <= 128)
-        return 128;
-    if(size <= 256)
-        return 256;
-
-    align = size % 4;
-    if(align != 0) {
-        size += 4 - align;
-    }
-
-    return size;
-}
-
-#ifdef WITH_FIXED_LISTS
-
-int map_size_to_list(heap_t *heap, size_t sz) {
-    int i;
-    maptable_node_t *node;
-    i = 0;
-    node = heap->maptable_head;
-    while(node) {
-#ifdef COUNT_HOPS
-        heap->dmm_stats.total_hops++;
-#endif /* COUNT_HOPS */
-        if(node->size == sz) {
-            return i;
-        }
-        i++;
-        node = node->next;
-    }
-    return -1;
-}
-
-#endif /* WITH_FIXED_LISTS */
-
-/* Random assignment */
-int map_thread_pool(void) {
-    return (int) (((unsigned long) pthread_self() >> 10) % NUM_POOLS);
-}

+ 16 - 5
src/raw_block.c

@@ -15,9 +15,15 @@
  *
  */
 
+#include "dmmlib/raw_block.h"
+
+#ifdef HAVE_LOCKS
 #include <pthread.h>
-#include <dmmlib/raw_block.h>
+#endif /* HAVE_LOCKS */
 #include "request_memory.h"
+#ifdef FL_RB_ONLY
+#include "freelist/freelist_rb.h"
+#endif /* FL_RB_ONLY */
 
 raw_block_header_t *create_new_raw_block(size_t raw_block_size) {
     void *ptr;
@@ -28,12 +34,17 @@ raw_block_header_t *create_new_raw_block(size_t raw_block_size) {
         return NULL;
     }
 
-    ((raw_block_header_t *)ptr)->next_raw_block = NULL;
     ((raw_block_header_t *)ptr)->size = raw_block_size;
-    ((raw_block_header_t *)ptr)->remaining_size = raw_block_size - sizeof(raw_block_header_t);
-    ((raw_block_header_t *)ptr)->border_ptr = NULL;
-    ((raw_block_header_t *)ptr)->free_list_head = NULL;
+    ((raw_block_header_t *)ptr)->next_raw_block = NULL;
+#ifdef FL_RB_ONLY
+    freelist_rb_t *fl_rb;
+    fl_rb = (freelist_rb_t *)((char *)ptr + sizeof(raw_block_header_t));
+    fl_rb->border_ptr = (block_header_t *)((char *)fl_rb + sizeof(freelist_rb_t));
+    fl_rb->free_list_head = NULL;
+#endif /* FL_RB_ONLY */
+#ifdef HAVE_LOCKS
     pthread_mutex_init(&((raw_block_header_t *)ptr)->mutex, NULL);
+#endif /* HAVE LOCKS */
 
     return (raw_block_header_t *)ptr;
 }