Bläddra i källkod

freelist refactoring

Ioannis Koutras 12 år sedan
förälder
incheckning
7ecf85adf2
45 ändrade filer med 1015 tillägg och 1201 borttagningar
  1. 85 27
      CMakeLists.txt
  2. 22 108
      DefineOptions.cmake
  3. 22 18
      dmm_config.h.in
  4. 6 4
      include/dmmlib/freelist/block_header.h
  5. 5 4
      include/dmmlib/freelist/freelist_rb.h
  6. 42 0
      private-include/freelist/fitting/best.h
  7. 42 0
      private-include/freelist/fitting/exact.h
  8. 43 0
      private-include/freelist/fitting/first.h
  9. 42 0
      private-include/freelist/fitting/good.h
  10. 54 0
      private-include/freelist/fitting_policy.h
  11. 0 59
      private-include/freelist/linked_lists/add_block_in_order.h
  12. 0 63
      private-include/freelist/linked_lists/address_order.h
  13. 0 58
      private-include/freelist/linked_lists/fifo_order.h
  14. 0 71
      private-include/freelist/linked_lists/linked_lists.h
  15. 0 80
      private-include/freelist/linked_lists/search_algorithms.h
  16. 0 63
      private-include/freelist/linked_lists/size_order.h
  17. 14 22
      private-include/freelist/linked_lists/add_block.h
  18. 41 0
      private-include/freelist/ordering/fifo.h
  19. 9 20
      private-include/freelist/linked_lists/lifo_order.h
  20. 40 0
      private-include/freelist/ordering/size.h
  21. 106 0
      private-include/freelist/ordering_policy.h
  22. 33 15
      src/CMakeLists.txt
  23. 1 1
      src/free.c
  24. 5 6
      src/freelist/coalesce.c
  25. 78 0
      src/freelist/fitting/best.c
  26. 53 0
      src/freelist/fitting/exact.c
  27. 55 0
      src/freelist/fitting/first.c
  28. 69 0
      src/freelist/fitting/good.c
  29. 3 3
      src/freelist/freelist_free.c
  30. 2 5
      src/freelist/freelist_debug.c
  31. 3 2
      src/freelist/initialize.c
  32. 0 85
      src/freelist/linked_lists/add_block_in_order.c
  33. 0 54
      src/freelist/linked_lists/address_order.c
  34. 0 43
      src/freelist/linked_lists/fifo_order.c
  35. 0 79
      src/freelist/linked_lists/linked_lists.c
  36. 0 211
      src/freelist/linked_lists/search_algorithms.c
  37. 0 54
      src/freelist/linked_lists/size_order.c
  38. 8 24
      src/freelist/freelist_malloc.c
  39. 45 0
      src/freelist/ordering/address.c
  40. 29 0
      src/freelist/ordering/fifo.c
  41. 5 8
      src/freelist/linked_lists/lifo_order.c
  42. 46 0
      src/freelist/ordering/size.c
  43. 3 12
      src/freelist/split.c
  44. 1 1
      src/malloc.c
  45. 3 1
      src/realloc.c

+ 85 - 27
CMakeLists.txt

@@ -12,15 +12,88 @@ include(DefineOptions.cmake)
 include(MacroEnsureOutOfSourceBuild)
 macro_ensure_out_of_source_build("${PROJECT_NAME} requires an out of source build. Please create a separate build directory and run 'cmake /path/to/${PROJECT_NAME} [options]' there.")
 
-if(CMAKE_COMPILER_IS_GNUCC AND LINUXTEST)
-  add_definitions(-std=c99)
-  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -pedantic -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wnested-externs -Winline -Wno-long-long -Wconversion -Wstrict-prototypes")  
-endif(CMAKE_COMPILER_IS_GNUCC AND LINUXTEST)
+if(CMAKE_COMPILER_IS_GNUCC)
+  add_definitions(-std=c99 -Wall -Wextra -pedantic -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wnested-externs -Winline -Wno-long-long -Wconversion -Wstrict-prototypes)
+endif(CMAKE_COMPILER_IS_GNUCC)
 
 if(WITH_SYSTEM_CALLS STREQUAL "mmap")
   set(PAGESIZE_ALIGN ON)
 endif(WITH_SYSTEM_CALLS STREQUAL "mmap")
 
+# Checking free-list setups
+if(RAW_BLOCKS_TYPE STREQUAL "freelist")
+  set(FL_RB_ONLY ON)
+
+  if(FITTING_POLICY STREQUAL "best")
+    set(BEST_FIT ON)
+  elseif(FITTING_POLICY STREQUAL "exact")
+    set(EXACT_FIT ON)
+  elseif(FITTING_POLICY STREQUAL "first")
+    set(FIRST_FIT ON)
+  elseif(FITTING_POLICY STREQUAL "good")
+    if(NOT DEFINED GOOD_FIT_PERCENTAGE)
+      message(FATAL_ERROR "You have to set GOOD_FIT_PERCENTAGE by using -DGOOD_FIT_PERCENTAGE={0.f}.")
+    endif(NOT DEFINED GOOD_FIT_PERCENTAGE)
+    set(GOOD_FIT ON)
+  else(FITTING_POLICY STREQUAL "best")
+    message(FATAL_ERROR "Could not identify the fitting policy of the freelist organization.")
+  endif(FITTING_POLICY STREQUAL "best")
+  
+  if(ORDERING_POLICY STREQUAL "address")
+    set(ADDRESS_ORDERED ON)
+  elseif(ORDERING_POLICY STREQUAL "fifo")
+    set(FIFO_ORDERED ON)
+  elseif(ORDERING_POLICY STREQUAL "lifo")
+    set(LIFO_ORDERED ON)
+  elseif(ORDERING_POLICY STREQUAL "size")
+    set(SIZE_ORDERED ON)
+  endif(ORDERING_POLICY STREQUAL "address")
+  
+  if(WITH_COALESCING STREQUAL "fixed")
+    if(NOT DEFINED MAX_COALESCE_SIZE)
+      message(FATAL_ERROR "You have to set MAX_COALESCE_SIZE by using -DMAX_COALESCE_SIZE={int}.")
+    endif(NOT DEFINED MAX_COALESCE_SIZE)
+    set(COALESCING_FIXED ON)
+  elseif(WITH_COALESCING STREQUAL "variable")
+    if(NOT DEFINED MAX_COALESCE_SIZE)
+      message(FATAL_ERROR "You have to set MAX_COALESCE_SIZE by using -DMAX_COALESCE_SIZE={int}.")
+    endif(NOT DEFINED MAX_COALESCE_SIZE)
+    set(COALESCING_VARIABLE ON)
+  endif(WITH_COALESCING STREQUAL "fixed")
+  
+  if(WITH_SPLITTING STREQUAL "fixed")
+    if(NOT DEFINED MIN_SPLITTING_SIZE)
+      message(FATAL_ERROR "You have to set MIN_SPLITTING_SIZE by using -DMIN_SPLITTING_SIZE={int}.")
+    endif(NOT DEFINED MIN_SPLITTING_SIZE)
+    set(SPLITTING_FIXED ON)
+  elseif(WITH_SPLITTING STREQUAL "variable")
+    if(NOT DEFINED MIN_SPLITTING_SIZE)
+      message(FATAL_ERROR "You have to set MIN_SPLITTING_SIZE by using -DMIN_SPLITTING_SIZE={int}.")
+    endif(NOT DEFINED MIN_SPLITTING_SIZE)
+    set(WITH_KNOBS ON)
+    set(SPLITTING_VARIABLE ON)
+  endif(WITH_SPLITTING STREQUAL "fixed")
+
+  if(COALESCE_AFTER_SPLIT)
+    if(WITH_SPLITTING STREQUAL "never")
+      message(FATAL_ERROR "You have to set WITH_SPLITTING to fixed or variable if you want to coalesce after split.")
+    endif(WITH_SPLITTING STREQUAL "never")
+    if(WITH_COALESCING STREQUAL "never")
+      message(FATAL_ERROR "You have to set WITH_COALESCING to fixed or variable if you want to coalesce after split.")
+    endif(WITH_COALESCING STREQUAL "never")
+  endif(COALESCE_AFTER_SPLIT)
+
+# Checking bitmap setups
+elseif(RAW_BLOCKS_TYPE STREQUAL "bitmap")
+
+  set(BITMAP_RB_ONLY ON)
+
+endif(RAW_BLOCKS_TYPE STREQUAL "freelist")
+
+if(STATS STREQUAL "global")
+  set(WITH_ALLOCATOR_STATS ON)
+endif(STATS STREQUAL "global")
+
 configure_file (
 	"${PROJECT_SOURCE_DIR}/dmm_config.h.in"
 	"${PROJECT_BINARY_DIR}/dmm_config.h"
@@ -31,11 +104,11 @@ include_directories("${PROJECT_BINARY_DIR}")
 add_subdirectory(include)
 add_subdirectory(src)
 
-if (WITH_EXAMPLES)
+if(WITH_EXAMPLES)
   add_subdirectory(examples)
 endif (WITH_EXAMPLES)
 
-if (WITH_DOC)
+if(WITH_DOC)
   add_subdirectory(doc)
 endif (WITH_DOC)
 
@@ -46,10 +119,6 @@ message(STATUS "POSIX locking mechanisms: " ${HAVE_LOCKS})
 
 message(STATUS "Raw blocks type: " ${RAW_BLOCKS_TYPE})
 
-if(RAW_BLOCKS_TYPE STREQUAL "bitmap")
-  message(STATUS "Bitmap cell resolution: " ${BITMAP_RESOLUTION} " bytes")
-endif(RAW_BLOCKS_TYPE STREQUAL "bitmap")
-
 if(RAW_BLOCKS_TYPE STREQUAL "freelist")
 
   if(BLOCKS_ORGANIZATION STREQUAL "dll")
@@ -58,24 +127,11 @@ if(RAW_BLOCKS_TYPE STREQUAL "freelist")
     message(STATUS "Block organization: Singly-Linked Lists")
   endif(BLOCKS_ORGANIZATION STREQUAL "dll")
 
-  if(SORT_POLICY STREQUAL "lifo")
-    message(STATUS "Block sorting policy: LIFO-ordered")
-  elseif(SORT_POLICY STREQUAL "fifo")
-    message(STATUS "Block sorting policy: FIFO-ordered")
-  elseif(SORT_POLICY STREQUAL "size")
-    message(STATUS "Block sorting policy: Size-ordered")
-  elseif(SORT_POLICY STREQUAL "address")
-    message(STATUS "Block sorting policy: Address-ordered")
-  endif(SORT_POLICY STREQUAL "lifo")
-
-  message(STATUS "Search policy: " ${SEARCH_POLICY})
-  if(ALLOC_VAR_FIT OR HEAP_VAR_FIT)
-    message(STATUS "Initial search policy: " ${INITIAL_SEARCH_POLICY})
-  endif(ALLOC_VAR_FIT OR HEAP_VAR_FIT)
-
+  message(STATUS "Fitting policy: " ${FITTING_POLICY})
   if(GOOD_FIT)
-    message(STATUS "Acceptable fit percentage: " ${FIT_PERCENTAGE})
+    message(STATUS "Acceptable fit percentage: " ${GOOD_FIT_PERCENTAGE})
   endif(GOOD_FIT)
+  message(STATUS "Ordering policy: " ${ORDERING_POLICY})
 
   message(STATUS "Coalescing: " ${WITH_COALESCING})
   if(MAX_COALESCE_SIZE)
@@ -100,6 +156,9 @@ if(RAW_BLOCKS_TYPE STREQUAL "freelist")
     endif(COALESCE_AFTER_SPLIT)
   endif(MIN_SPLITTING_SIZE)
 
+elseif(RAW_BLOCKS_TYPE STREQUAL "bitmap")
+  message(STATUS "Bitmap cell resolution: " ${BITMAP_RESOLUTION} " bytes")
+
 endif(RAW_BLOCKS_TYPE STREQUAL "freelist")
 
 message(STATUS "Have statistics: " ${STATS})
@@ -108,4 +167,3 @@ message(STATUS "Support for debug functions: " ${WITH_DEBUG})
 message(STATUS "Adaptivity: " ${WITH_ADAPTIVITY})
 message(STATUS "Support for realloc(): " ${WITH_REALLOC})
 message(STATUS "********************************************")
-

+ 22 - 108
DefineOptions.cmake

@@ -11,32 +11,29 @@ 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(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(BITMAP_RESOLUTION 256 CACHE INTEGER "Choose the size of cells in bitmap-organised raw blocks")
-
 set(REQUEST_SIZE_INFO ON)
 
-set(WITH_SYSTEM_CALLS "none")
+# Free-list Settings
 
-set(SEARCH_POLICY "best")
-set(FIT_PERCENTAGE 0.8)
-set(INITIAL_SEARCH_POLICY "best")
+set(FITTING_POLICY "best" CACHE STRING "Choose the fitting policy in freelist-organized raw blocks, options are: best, exact, first, good")
+
+set(ORDERING_POLICY "lifo" CACHE STRING "Choose the ordering policy in freelist-organized raw blocks, options are: address, fifo, lifo, size")
 
 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)
 
-set(BLOCKS_ORGANIZATION "sll" "Blocks organized in singly linked lists")
+# Bitmap Settings
 
-option(WITH_OWNERSHIP "Build with ownership information in blocks" OFF)
+set(BITMAP_RESOLUTION 256 CACHE INTEGER "Choose the size of cells in bitmap-organised raw blocks")
+
+# Presets
 
 option(P2012 "Build for P2012 runtime" OFF)
 option(LEON3 "Build for Leon3" OFF)
-option(LINUXTEST "Build a case for Linux" ON) 
+option(LINUX "Build for Linux" OFF) 
 
-if (P2012)
+if(P2012)
   set(WITH_SYSTEM_CALLS "none")
   set(HAVE_LOCKS OFF)
   set(WITH_STATIC_LIB ON)
@@ -48,9 +45,10 @@ if (P2012)
   set(STATS "none")
   set(TRACE_LEVEL 0)
   set(WITH_DEBUG OFF)
-endif (P2012)
+  set(WITH_REALLOC OFF)
+endif(P2012)
 
-if (LEON3)
+if(LEON3)
   set(WITH_SYSTEM_CALLS "none")
   set(HAVE_LOCKS OFF)
   set(WITH_STATIC_LIB ON)
@@ -60,107 +58,23 @@ if (LEON3)
   set(WITH_COALESCING "never")
   set(WITH_SPLITTING "never")
   set(BLOCKS_ORGANIZATION "sll")
-endif (LEON3)
+endif(LEON3)
 
-if (LINUXTEST)
+if(LINUX)
   set(WITH_SYSTEM_CALLS "mmap")
   set(SYS_ALLOC_SIZE 4194304)
-  set(SORT_POLICY "lifo")
-  set(SEARCH_POLICY "first")
-  set(FIT_PERCENTAGE 0.6f)
+  set(FITTING_POLICY "first")
+  set(ORDERING_POLICY "lifo")
+  set(GOOD_FIT_PERCENTAGE 0.6f)
   set(HAVE_LOCKS ON)
   set(WITH_EXAMPLES ON)
   set(WITH_COALESCING "fixed")
   set(MAX_COALESCE_SIZE 60000)
   set(WITH_SPLITTING "fixed")
   set(MIN_SPLITTING_SIZE 300)
-  set(COALESCE_AFTER_SPLIT ON)
+  set(COALESCE_AFTER_SPLIT OFF)
   set(WITH_SHARED_LIB ON)
-  set(WITH_STATIC_LIB ON)
+  set(WITH_STATIC_LIB OFF)
   set(WITH_REALLOC ON)
   set(WITH_DOC ON)
-endif (LINUXTEST)
-
-if(RAW_BLOCKS_TYPE STREQUAL "freelist")
-  set(FL_RB_ONLY ON)
-elseif(RAW_BLOCKS_TYPE STREQUAL "bitmap")
-  set(BITMAP_RB_ONLY ON)
-endif(RAW_BLOCKS_TYPE STREQUAL "freelist")
-
-if(STATS STREQUAL "rawblock")
-  set(WITH_RAWBLOCK_STATS ON)
-elseif(STATS STREQUAL "global")
-  set(WITH_ALLOCATOR_STATS ON)
-endif(STATS STREQUAL "rawblock")
-
-if(COALESCE_AFTER_SPLIT)
-  if(WITH_SPLITTING STREQUAL "never")
-         message(FATAL_ERROR "You have to set WITH_SPLITTING to fixed or variable if you want to coalesce after split.")
-  endif(WITH_SPLITTING STREQUAL "never")
-  if(WITH_COALESCING STREQUAL "never")
-    message(FATAL_ERROR "You have to set WITH_COALESCING to fixed or variable if you want to coalesce after split.")
-  endif(WITH_COALESCING STREQUAL "never")
-endif(COALESCE_AFTER_SPLIT)
-
-if(BLOCKS_ORGANIZATION STREQUAL "dll")
-	set(BLOCKS_IN_DLL ON)
-else(BLOCKS_ORGANIZATION STREQUAL "dll")
-	set(BLOCKS_IN_SLL ON)
-endif(BLOCKS_ORGANIZATION STREQUAL "dll")
-
-if(SORT_POLICY STREQUAL "lifo")
-  set(LIFO_SORT_POLICY ON)
-elseif(SORT_POLICY STREQUAL "fifo")
-	set(FIFO_SORT_POLICY ON)
-elseif(SORT_POLICY STREQUAL "size")
-  set(SIZE_SORT_POLICY ON)
-elseif(SORT_POLICY STREQUAL "address")
-  set(ADDRESS_SORT_POLICY ON)
-endif(SORT_POLICY STREQUAL "lifo")
-
-
-if(SEARCH_POLICY STREQUAL "best")
-  set(BEST_FIT ON)
-elseif(SEARCH_POLICY STREQUAL "good")
-  set(GOOD_FIT ON)
-  set(WITH_KNOBS ON)
-elseif(SEARCH_POLICY STREQUAL "exact")
-  set(EXACT_FIT ON)
-elseif(SEARCH_POLICY STREQUAL "first")
-  set(FIRST_FIT ON)
-elseif(SEARCH_POLICY STREQUAL "allocvar")
-  set(ALLOC_VAR_FIT ON)
-elseif(SEARCH_POLICY STREQUAL "heapvar")
-  set(HEAP_VAR_FIT ON)
-endif(SEARCH_POLICY STREQUAL "best")
-
-if(WITH_COALESCING STREQUAL "fixed")
-  if(NOT DEFINED MAX_COALESCE_SIZE)
-    message(FATAL_ERROR "You have to set MAX_COALESCE_SIZE by using -DMAX_COALESCE_SIZE={size}.")
-  endif(NOT DEFINED MAX_COALESCE_SIZE)
-  set(COALESCING_FIXED ON)
-elseif(WITH_COALESCING STREQUAL "variable")
-  if(NOT DEFINED MAX_COALESCE_SIZE)
-    message(FATAL_ERROR "You have to set MAX_COALESCE_SIZE by using -DMAX_COALESCE_SIZE={size}.")
-  endif(NOT DEFINED MAX_COALESCE_SIZE)
-  set(WITH_KNOBS ON)
-  if (MULTIPLE_HEAPS)
-    # Coalescing on multiple heaps requires heap ownership information per
-    # block
-    set(WITH_OWNERSHIP ON)
-  endif (MULTIPLE_HEAPS)
-  set(COALESCING_VARIABLE ON)
-endif(WITH_COALESCING STREQUAL "fixed")
-
-if(WITH_SPLITTING STREQUAL "fixed")
-  if(NOT DEFINED MIN_SPLITTING_SIZE)
-	  message(FATAL_ERROR "You have to set MIN_SPLITTING_SIZE by using -DMIN_SPLITTING_SIZE={size}.")
-  endif(NOT DEFINED MIN_SPLITTING_SIZE)
-  set(SPLITTING_FIXED ON)
-elseif(WITH_SPLITTING STREQUAL "variable")
-  if(NOT DEFINED MIN_SPLITTING_SIZE)
-	  message(FATAL_ERROR "You have to set MIN_SPLITTING_SIZE by using -DMIN_SPLITTING_SIZE={size}.")
-  endif(NOT DEFINED MIN_SPLITTING_SIZE)
-  set(WITH_KNOBS ON)
-  set(SPLITTING_VARIABLE ON)
-endif(WITH_SPLITTING STREQUAL "fixed")
+endif(LINUX)

+ 22 - 18
dmm_config.h.in

@@ -1,6 +1,8 @@
 #ifndef DMM_CONFIG_H
 #define DMM_CONFIG_H
 
+/* General Settings */
+
 #cmakedefine FL_RB_ONLY
 #cmakedefine BITMAP_RB_ONLY
 #cmakedefine SYS_ALLOC_SIZE @SYS_ALLOC_SIZE@
@@ -8,29 +10,33 @@
 
 #cmakedefine TRACE_LEVEL @TRACE_LEVEL@
 
-#cmakedefine LIFO_SORT_POLICY
-#cmakedefine FIFO_SORT_POLICY
-#cmakedefine SIZE_SORT_POLICY
-#cmakedefine ADDRESS_SORT_POLICY
+/* Free-list Settings */
+#ifdef FL_RB_ONLY
+
+/* Fitting Policies */
 
 #cmakedefine BEST_FIT
-#cmakedefine GOOD_FIT
-#ifdef GOOD_FIT
-#cmakedefine FIT_PERCENTAGE @FIT_PERCENTAGE@
-#endif /* GOOD_FIT */
 #cmakedefine EXACT_FIT
 #cmakedefine FIRST_FIT
-#cmakedefine ALLOC_VAR_FIT
-#cmakedefine HEAP_VAR_FIT
-#if defined (ALLOC_VAR_FIT) || defined (HEAP_VAR_FIT)
-#cmakedefine INITIAL_SEARCH_POLICY "@INITIAL_SEARCH_POLICY@"
-#endif /* defined (ALLOC_VAR_FIT) || defined (HEAP_VAR_FIT) */
+#cmakedefine GOOD_FIT
+#cmakedefine GOOD_FIT_PERCENTAGE @GOOD_FIT_PERCENTAGE@
+
+/* Ordering Policies */
+
+#cmakedefine ADDRESS_ORDERED
+#cmakedefine FIFO_ORDERED
+#cmakedefine LIFO_ORDERED
+#cmakedefine SIZE_ORDERED
+
+/* Coalescing Settings */
 
 #cmakedefine COALESCING_FIXED
 #cmakedefine COALESCING_VARIABLE
 
 #cmakedefine MAX_COALESCE_SIZE @MAX_COALESCE_SIZE@
 
+/* Splitting Settings */
+
 #cmakedefine SPLITTING_FIXED
 #cmakedefine SPLITTING_VARIABLE
 
@@ -38,6 +44,9 @@
 
 #cmakedefine COALESCE_AFTER_SPLIT
 
+#endif /* FL_RB_ONLY */
+
+/* Bitmap Settings */
 #ifdef BITMAP_RB_ONLY
 
 /** How many bytes per cell should be used */
@@ -56,11 +65,6 @@
 
 #cmakedefine WITH_ADAPTIVITY
 
-#cmakedefine BLOCKS_IN_SLL
-#cmakedefine BLOCKS_IN_DLL
-
-#cmakedefine WITH_OWNERSHIP
-
 #define MIN_FRAG_THRESHOLD 0.05
 
 #cmakedefine WITH_REALLOC

+ 6 - 4
include/dmmlib/freelist/block_header.h

@@ -30,6 +30,7 @@
 #include <stdbool.h>
 
 #include "dmm_config.h"
+#include "dmmlib/lists.h"
 
 /** The header structure of every memory block inside a heap. */
 typedef struct block_header_s {
@@ -41,12 +42,13 @@ typedef struct block_header_s {
     size_t previous_size; /**< The LSB represents the availability of the
                             previous block, the rest the size of the data
                             part of the previous block in the memory space */
-    struct block_header_s *next; /**< The pointer to the next memory block in the list */
-#ifdef BLOCKS_IN_DLL
-    struct block_header_s *previous; /**< The pointer to the previous node in the list */
-#endif /* BLOCKS_IN_DLL */
+    /** Pointer to the next memory block in the list */
+    SLIST_ENTRY(block_header_s) pointers;
 } block_header_t;
 
+/** The head element of a singly-linked list of block_header_t records */
+SLIST_HEAD(fl_head_s, block_header_s);
+
 /**
  * The size of the header in number of bytes
  */

+ 5 - 4
include/dmmlib/freelist/freelist_rb.h

@@ -25,16 +25,17 @@
 #ifndef FREELIST_RB_H
 #define FREELIST_RB_H
 #include "dmmlib/freelist/block_header.h"
+#include "dmmlib/lists.h"
 
 /** Data structure of the required elements for a free-list organized raw block.
  */
 typedef struct freelist_rb_s {
     size_t remaining_size; /**< The remaining size for new memory blocks. */
     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 */
+    struct fl_head_s fl_head; /**< Head of the free list of memory blocks. */
+#ifdef FIFO_ORDERED
+    block_header_t *fl_tail; /**< The tail of the free list. */
+#endif /* FIFO_ORDERED */
 } freelist_rb_t;
 
 #endif /* FREELIST_RB_H */

+ 42 - 0
private-include/freelist/fitting/best.h

@@ -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        best.h
+ * \author 	Ioannis Koutras (joko@microlab.ntua.gr)
+ * \date        October 2012
+ *  
+ * \brief Best-fit search algorithm for freelist-organized raw blocks.
+ */
+
+#ifndef FL_BEST_FIT_H
+#define FL_BEST_FIT_H
+#include "dmmlib/freelist/freelist_rb.h"
+#include "dmmlib/freelist/block_header.h"
+
+/**
+ * Performs a best-fit search on a list for a block of a certain size
+ *
+ * \param raw_block      The freelist-organized raw block.
+ * \param requested_size The desired size of the block.
+ *
+ * \return The pointer to the matched memory block.
+ * \retval NULL No block was found.
+ */
+block_header_t * fl_best_fit(freelist_rb_t *raw_block, size_t requested_size);
+
+#endif /* FL_BEST_FIT_H */

+ 42 - 0
private-include/freelist/fitting/exact.h

@@ -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        exact.h
+ * \author 	Ioannis Koutras (joko@microlab.ntua.gr)
+ * \date        October 2012
+ *  
+ * \brief Exact-fit search algorithm for freelist-organized raw blocks.
+ */
+
+#ifndef FL_EXACT_FIT_H
+#define FL_EXACT_FIT_H
+#include "dmmlib/freelist/freelist_rb.h"
+#include "dmmlib/freelist/block_header.h"
+
+/**
+ * Performs an exact-fit search on a list for a block of a certain size
+ *
+ * \param raw_block      The freelist-organized raw block.
+ * \param requested_size The desired size of the block.
+ *
+ * \return The pointer to the matched memory block.
+ * \retval NULL No block was found.
+ */
+block_header_t * fl_exact_fit(freelist_rb_t *raw_block, size_t requested_size);
+
+#endif /* FL_FIRST_FIT_H */

+ 43 - 0
private-include/freelist/fitting/first.h

@@ -0,0 +1,43 @@
+/*
+ *   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        first.h
+ * \author 	Ioannis Koutras (joko@microlab.ntua.gr)
+ * \date        October 2012
+ *  
+ * \brief First-fit search algorithm for freelist-organized raw blocks.
+ */
+
+#ifndef FL_FIRST_FIT_H
+#define FL_FIRST_FIT_H
+#include "dmmlib/freelist/freelist_rb.h"
+#include "dmmlib/freelist/block_header.h"
+
+/**
+ * Performs a first-fit search on a freelist-organized raw block for a block of
+ * a certain size.
+ *
+ * \param raw_block      The freelist-organized raw block.
+ * \param requested_size The desired size of the block.
+ *
+ * \return The pointer to the matched memory block.
+ * \retval NULL No block was found.
+ */
+block_header_t * fl_first_fit(freelist_rb_t *raw_block, size_t requested_size);
+
+#endif /* FL_FIRST_FIT_H */

+ 42 - 0
private-include/freelist/fitting/good.h

@@ -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        good.h
+ * \author 	Ioannis Koutras (joko@microlab.ntua.gr)
+ * \date        October 2012
+ *  
+ * \brief Good-fit search algorithm for freelist-organized raw blocks.
+ */
+
+#ifndef FL_GOOD_FIT_H
+#define FL_GOOD_FIT_H
+#include "dmmlib/freelist/freelist_rb.h"
+#include "dmmlib/freelist/block_header.h"
+
+/**
+ * Performs a good-fit search on a list for a block of a certain size
+ *
+ * \param raw_block      The freelist-organized raw block.
+ * \param requested_size The desired size of the block.
+ *
+ * \return The pointer to the matched memory block.
+ * \retval NULL No block was found.
+ */
+block_header_t * fl_good_fit(freelist_rb_t *raw_block, size_t requested_size);
+
+#endif /* GOOD_FIT_H */

+ 54 - 0
private-include/freelist/fitting_policy.h

@@ -0,0 +1,54 @@
+/*
+ *   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        freelist/fitting_policy.h
+ * \author 	Ioannis Koutras (joko@microlab.ntua.gr)
+ * \date        October 2012
+ *  
+ * \brief Defines the default fitting policy in freelist-organized raw blocks.
+ */
+
+#ifndef FL_FITTING_POLICY_H
+#define FL_FITTING_POLICY_H
+
+#include "dmm_config.h"
+
+/**
+ * @def SEARCH_LIST
+ * Tries to find an available free memory block by using the default search
+ * method.
+ *
+ * @param raw_block The freelist-organized raw block
+ * @param size      The requested size
+ */
+
+#if defined (BEST_FIT)
+#include "freelist/fitting/best.h"
+#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, size)
+#elif defined (FIRST_FIT)
+#include "freelist/fitting/first.h"
+#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, size)
+#endif /* BEST_FIT */ 
+
+#endif /* FL_FITTING_POLICY_H */

+ 0 - 59
private-include/freelist/linked_lists/add_block_in_order.h

@@ -1,59 +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        add_block_in_order.h
- * \author      Ioannis Koutras (joko@microlab.ntua.gr)
- * \date        January, 2012
- *  
- * \brief Add a block in an ordered linked list.
- */
-
-#ifndef ADD_BLOCK_IN_ORDER_H
-#define ADD_BLOCK_IN_ORDER_H
-
-#include <stdbool.h>
-#include "dmm_config.h"
-#ifdef COUNT_HOPS
-#include <dmmlib/heap.h>
-#endif /* COUNT_HOPS */
-
-/**
- * Adds a block in an ordered list.
- *
- * @param block The pointer of the data part of the block to be added.
- * @param starting_node The pointer to the starting memory block of the list.
- * @param search_condition Function pointer of the search condition.
- */
-#ifdef COUNT_HOPS
-/*
- * @param heap A pointer to the heap which manages the block.
- */
-void add_block_in_order(
-        heap_t *heap,
-        void **block,
-        void **starting_node,
-        bool (*search_condition)(void *block, void* comparing_block));
-#else /* COUNT_HOPS */
-void add_block_in_order(
-        void **block,
-        void **starting_node,
-        bool (*search_condition)(void *block, void* comparing_block));
-#endif /* COUNT_HOPS */
-
-#endif /* ADD_BLOCK_IN_ORDER_H */
-

+ 0 - 63
private-include/freelist/linked_lists/address_order.h

@@ -1,63 +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        address_order.h
- * \author      Ioannis Koutras (joko@microlab.ntua.gr)
- * \date        January, 2012
- *  
- * \brief Add a block in an address-ordered linked list.
- */
-
-#ifndef ADDRESS_ORDER_H
-#define ADDRESS_ORDER_H
-
-#ifdef COUNT_HOPS
-#include <dmmlib/heap.h>
-#endif /* COUNT_HOPS */
-#include "dmm_config.h"
-
-#ifdef ADDRESS_SORT_POLICY
-#ifdef COUNT_HOPS
-#define add_block(heap, block, list) add_block_address_order(heap, block, list)
-#else /* COUNT_HOPS */
-#define add_block(block, list) add_block_address_order(block, list)
-#endif /* COUNT_HOPS */
-#endif /* ADDRESS_SORT_POLICY */
-
-/**
- * Adds a block in an address-ordered list.
- *
- * @param block The pointer of the data part of the block to be added.
- * @param starting_node The pointer to the starting memory block of the list.
- */
-#ifdef COUNT_HOPS
-/*
- * @param heap A pointer to the heap which manages the block.
- */
-void add_block_address_order(
-        heap_t *heap,
-        void **block,
-        void **starting_node);
-#else /* COUNT_HOPS */
-void add_block_address_order(
-        void **block,
-        void **starting_node);
-#endif /* COUNT_HOPS */
-
-#endif /* ADDRESS_ORDER_H */
-

+ 0 - 58
private-include/freelist/linked_lists/fifo_order.h

@@ -1,58 +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        fifo_order.h
- * \author      Ioannis Koutras (joko@microlab.ntua.gr)
- * \date        January, 2012
- *  
- * \brief Add a block in a FIFO-ordered linked list.
- */
-
-#ifndef FIFO_ORDER_H
-#define FIFO_ORDER_H
-
-#ifdef COUNT_HOPS
-#include <dmmlib/heap.h>
-#endif /* COUNT_HOPS */
-#include "dmm_config.h"
-
-#ifdef FIFO_SORT_POLICY
-#ifdef COUNT_HOPS
-#define add_block(heap, block, head, tail) add_block_fifo_order(heap, block, head, tail)
-#else /* COUNT_HOPS */
-#define add_block(block, head, tail) add_block_fifo_order(block, head, tail)
-#endif /* COUNT_HOPS */
-#endif /* FIFO_SORT_POLICY */
-
-/**
- * Adds a block in a LIFO-ordered list.
- *
- * @param block The pointer of the data part of the block to be added.
- * @param head_node The pointer to the head memory block of the list.
- * @param tail_node The pointer to the tail memory block of the list.
- */
-void add_block_fifo_order(
-#ifdef COUNT_HOPS
-        heap_t *heap, /**< A pointer to the heap which manages the block. */
-#endif /* COUNT_HOPS */
-        void **block,
-        void **head_node,
-        void **tail_node);
-
-#endif /* FIFO_ORDER_H */
-

+ 0 - 71
private-include/freelist/linked_lists/linked_lists.h

@@ -1,71 +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 	linked_lists.h
- * \author 	Ioannis Koutras (joko@microlab.ntua.gr)
- * \date 	September, 2011
- *  
- * \brief Linked list node header structure and functions.
- */
-
-#ifndef LINKED_LISTS_H
-#define LINKED_LISTS_H
-
-#include "dmm_config.h"
-#ifndef LEON3
-#include <stdint.h>
-#else
-#include <sys/types.h>
-#endif /* LEON3 */
-
-#include "dmmlib/freelist/block_header.h"
-#include "dmmlib/freelist/freelist_rb.h"
-
-#ifdef BLOCKS_IN_DLL
-
-/**
- * Set the previous memory block of a block in a linked list.
- *
- * \param block             The pointer to the data part of the current memory
- * block.
- * \param previous_block    The pointer to the data part of the previous memory
- * block.
- */
-void set_previous(void *previous, void *previous_block);
-
-/**
- * Get the previous memory block in a linked list.
- *
- * \param ptr The pointer to the data part of the current memory block.
- *
- * \return The pointer of the data part of the previous (in list) memory block.
- * \retval NULL There is no previous memory block in the list.
- */
-void * get_previous(void *ptr);
-
-#endif /* BLOCKS_IN_DLL */
-
-/**
- * Removes a memory block from a linked list of memory blocks.
- *
- * \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, freelist_rb_t *raw_block);
-
-#endif /* LINKED_LISTS_H */

+ 0 - 80
private-include/freelist/linked_lists/search_algorithms.h

@@ -1,80 +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 	search_algorithms.h
- * \author 	Ioannis Koutras (joko@microlab.ntua.gr)
- * \date 	September, 2011
- *  
- * \brief Various search algorithms for linked list structures used on DMMLib.
- */
-
-#ifndef LINKED_LISTS_SEARCH_ALGORITHMS_H
-#define LINKED_LISTS_SEARCH_ALGORITHMS_H
-#include "dmm_config.h"
-#include "dmmlib/freelist/freelist_rb.h"
-
-/**
- * Perform a best-fit search on free lists for a block of a certain size
- *
- * \param raw_block The raw block whose fixed list should be accessed.
- * \param requested_size The desired size of the block.
- *
- * \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(freelist_rb_t *raw_block, size_t requested_size);
-
-#ifdef GOOD_FIT
-
-/**
- * Perform a good-fit search on the free list
- *
- * \param raw_block The raw block whose fixed list should be accessed.
- * \param requested_size The desired size of the block.
- *
- * \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(freelist_rb_t *raw_block, size_t requested_size);
-
-#endif /* GOOD_FIT */
-
-/**
- * Perform an exact-fit search on free lists for a block of a certain size
- *
- * \param raw_block The raw block whose fixed list should be accessed.
- * \param requested_size The desired size of the block.
- *
- * \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(freelist_rb_t *raw_block, size_t requested_size);
-
-/**
- * Perform a first-fit search on free lists for a block of a certain size
- *
- * \param raw_block The raw block whose fixed list should be accessed.
- * \param requested_size The desired size of the block.
- *
- * \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(freelist_rb_t *raw_block, size_t requested_size);
-
-#endif /* LINKED_LISTS_SEARCH_ALGORITHMS_H */
-

+ 0 - 63
private-include/freelist/linked_lists/size_order.h

@@ -1,63 +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        size_order.h
- * \author      Ioannis Koutras (joko@microlab.ntua.gr)
- * \date        January, 2012
- *  
- * \brief Add a block in a size-ordered linked list.
- */
-
-#ifndef SIZE_ORDER_H
-#define SIZE_ORDER_H
-
-#ifdef COUNT_HOPS
-#include <dmmlib/heap.h>
-#endif /* COUNT_HOPS */
-#include "dmm_config.h"
-
-#ifdef SIZE_SORT_POLICY
-#ifdef COUNT_HOPS
-#define add_block(heap, block, list) add_block_size_order(heap, block, list)
-#else /* COUNT_HOPS */
-#define add_block(block, list) add_block_size_order(block, list)
-#endif /* COUNT_HOPS */
-#endif /* SIZE_SORT_POLICY */
-
-/**
- * Adds a block in a size-ordered list.
- *
- * @param block The pointer of the data part of the block to be added.
- * @param starting_node The pointer to the starting memory block of the list.
- */
-#ifdef COUNT_HOPS
-/*
- * @param heap A pointer to the heap which manages the block.
- */
-void add_block_size_order(
-        heap_t *heap,
-        void **block,
-        void **starting_node);
-#else /* COUNT_HOPS */
-void add_block_size_order(
-        void **block,
-        void **starting_node);
-#endif /* COUNT_HOPS */
-
-#endif /* SIZE_ORDER_H */
-

+ 14 - 22
private-include/freelist/linked_lists/add_block.h

@@ -16,33 +16,25 @@
  */
 
 /**
- * \file        add_block.h
+ * \file        address.h
  * \author      Ioannis Koutras (joko@microlab.ntua.gr)
- * \date        January, 2012
+ * \date        October 2012
  *  
- * \brief Add a block in a linked list.
+ * \brief Add a block in an address-ordered linked list.
  */
 
-#ifndef ADD_BLOCK_H
-#define ADD_BLOCK_H
+#ifndef FL_ADDRESS_ORDER_H
+#define FL_ADDRESS_ORDER_H
 
-#include "dmm_config.h"
+#include "dmmlib/freelist/block_header.h"
 
-#ifdef LIFO_SORT_POLICY
-#include "freelist/linked_lists/lifo_order.h"
-#endif /* LIFO_SORT_POLICY */
-
-#ifdef FIFO_SORT_POLICY
-#include "freelist/linked_lists/fifo_order.h"
-#endif /* LIFO_SORT_POLICY */
-
-#ifdef SIZE_SORT_POLICY
-#include "freelist/linked_lists/size_order.h"
-#endif /* LIFO_SORT_POLICY */
-
-#ifdef ADDRESS_SORT_POLICY
-#include "freelist/linked_lists/address_order.h"
-#endif /* LIFO_SORT_POLICY */
+/**
+ * Adds a block in an address-ordered list.
+ *
+ * @param head  The head of the list.
+ * @param block The memory block to be added.
+ */
+void add_to_address_ordered(struct fl_head_s *head, block_header_t *block);
 
-#endif /* ADD_BLOCK_H */
+#endif /* FL_ADDRESS_ORDER_H */
 

+ 41 - 0
private-include/freelist/ordering/fifo.h

@@ -0,0 +1,41 @@
+/*
+ *   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        fifo.h
+ * \author      Ioannis Koutras (joko@microlab.ntua.gr)
+ * \date        October 2012
+ *  
+ * \brief Add a block in a FIFO-ordered freelist-organized raw block.
+ */
+
+#ifndef FL_FIFO_ORDER_H
+#define FL_FIFO_ORDER_H
+
+#include "dmmlib/freelist/freelist_rb.h"
+#include "dmmlib/freelist/block_header.h"
+
+/**
+ * Adds a block in a FIFO-ordered list freelist-organized raw block.
+ *
+ * @param raw_block The raw block.
+ * @param block     The memory block to be added.
+ */
+void add_to_fifo_ordered(freelist_rb_t *raw_block, block_header_t *block);
+
+#endif /* FL_FIFO_ORDER_H */
+

+ 9 - 20
private-include/freelist/linked_lists/lifo_order.h

@@ -16,37 +16,26 @@
  */
 
 /**
- * \file        lifo_order.h
+ * \file        size.h
  * \author      Ioannis Koutras (joko@microlab.ntua.gr)
- * \date        January, 2012
+ * \date        October 2012
  *  
  * \brief Add a block in a LIFO-ordered linked list.
  */
 
-#ifndef LIFO_ORDER_H
-#define LIFO_ORDER_H
-#include "dmm_config.h"
+#ifndef FL_LIFO_ORDER_H
+#define FL_LIFO_ORDER_H
+
 #include "dmmlib/freelist/freelist_rb.h"
 #include "dmmlib/freelist/block_header.h"
 
-#ifdef LIFO_SORT_POLICY
-/** Adds a block in a linked list.
- *
- * @param raw_block The pointer to the raw block.
- * @param block The pointer of the block to be added.
- */
-#define add_block(raw_block, block) add_block_lifo_order(raw_block, block)
-#endif /* LIFO_SORT_POLICY */
-
 /**
  * Adds a block in a LIFO-ordered list.
  *
- * @param raw_block The pointer to the raw block.
- * @param block The pointer of the block to be added.
+ * @param raw_block The raw block.
+ * @param block     The memory block to be added.
  */
-void add_block_lifo_order(
-        freelist_rb_t *raw_block,
-        block_header_t *block);
+void add_to_lifo_ordered(freelist_rb_t *raw_block, block_header_t *block);
 
-#endif /* LIFO_ORDER_H */
+#endif /* FL_LIFO_ORDER_H */
 

+ 40 - 0
private-include/freelist/ordering/size.h

@@ -0,0 +1,40 @@
+/*
+ *   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        size.h
+ * \author      Ioannis Koutras (joko@microlab.ntua.gr)
+ * \date        October 2012
+ *  
+ * \brief Add a block in a size-ordered linked list.
+ */
+
+#ifndef FL_SIZE_ORDER_H
+#define FL_SIZE_ORDER_H
+
+#include "dmmlib/freelist/block_header.h"
+
+/**
+ * Adds a block in a size-ordered list.
+ *
+ * @param head  The head of the list.
+ * @param block The memory block to be added.
+ */
+void add_to_size_ordered(struct fl_head_s *head, block_header_t *block);
+
+#endif /* FL_SIZE_ORDER_H */
+

+ 106 - 0
private-include/freelist/ordering_policy.h

@@ -0,0 +1,106 @@
+/*
+ *   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        freelist/ordering_policy.h
+ * \author 	Ioannis Koutras (joko@microlab.ntua.gr)
+ * \date        October 2012
+ *  
+ * \brief Defines the default ordering policy in freelist-organized raw blocks.
+ */
+
+#ifndef FL_ORDERING_POLICY_H
+#define FL_ORDERING_POLICY_H
+
+#include "dmm_config.h"
+
+#include "dmmlib/lists.h"
+
+/**
+ * @def ADD_BLOCK
+ * Adds a block to the list of free memory blocks by using the default ordering
+ * policy.
+ *
+ * @param block The block to be added.
+ */
+
+#if defined (ADDRESS_ORDERED)
+#include "freelist/ordering/address.h"
+#define ADD_BLOCK(block) add_to_address_ordered(raw_block, block)
+
+#elif defined (FIFO_ORDERED)
+#include "freelist/ordering/fifo.h"
+#define ADD_BLOCK(block) add_to_fifo_ordered(raw_block, block)
+
+#elif defined (LIFO_ORDERED)
+#include "freelist/ordering/lifo.h"
+#define ADD_BLOCK(block) add_to_lifo_ordered(raw_block, block)
+
+#elif defined (SIZE_ORDERED)
+#include "freelist/ordering/size.h"
+#define ADD_BLOCK(block) add_to_size_ordered(raw_block, block)
+
+#endif /* ADDRESS_ORDERED */
+
+
+/**
+ * @def REMOVE_FSLLIST_HEAD
+ * Removes the top block of the list of free memory blocks.
+ *
+ * @param raw_block The pointer to the freelist-organized raw block.
+ */
+
+/**
+ * @def REMOVE_FSLLIST
+ * Removes a memory block from the list of free memory blocks.
+ *
+ * @param raw_block    The pointer to the freelist-organized raw block.
+ * @param memory_block The pointer to the memory block to be removed.
+ */
+
+#ifndef FIFO_ORDERED
+#define REMOVE_FSLLIST_HEAD(raw_block)                \
+    SLIST_REMOVE_HEAD(&raw_block->fl_head, pointers);
+
+#define REMOVE_FSLLIST(raw_block, memory_block)                            \
+SLIST_REMOVE(&raw_block->fl_head, memory_block, block_header_s, pointers);
+
+#else /* FIFO_ORDERED */
+#define REMOVE_FSLLIST_HEAD(raw_block)                       \
+    if(raw_block->fl_tail == raw_block->fl_head.slh_first) { \
+        raw_block->fl_tail = NULL;                           \
+    }                                                        \
+    SLIST_REMOVE_HEAD(&raw_block->fl_head, pointers);
+
+#define REMOVE_FSLLIST(raw_block, memory_block) do {               \
+    if ((&raw_block->fl_head)->slh_first == memory_block) {        \
+        REMOVE_FSLLIST_HEAD(raw_block);                            \
+    } else {						           \
+        block_header_t *curelm = (&raw_block->fl_head)->slh_first; \
+        while(curelm->pointers.sle_next != memory_block)           \
+            curelm = curelm->pointers.sle_next;                    \
+        if(raw_block->fl_tail == curelm->pointers.sle_next) {      \
+            raw_block->fl_tail = curelm;                           \
+        }                                                          \
+        curelm->pointers.sle_next =                                \
+            curelm->pointers.sle_next->pointers.sle_next;          \
+    }							           \
+} while (/*CONSTCOND*/0)
+
+#endif /* FIFO_ORDERED */
+
+#endif /* FL_ORDERING_POLICY_H */

+ 33 - 15
src/CMakeLists.txt

@@ -49,36 +49,54 @@ 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
-    freelist/freelist_free.c
+    freelist/malloc.c
+    freelist/free.c
     freelist/initialize.c
     )
 
-  if(SORT_POLICY STREQUAL "lifo")
+  if(FITTING_POLICY STREQUAL "best")
     set(dmmlib_SRCS
       ${dmmlib_SRCS}
-      freelist/linked_lists/lifo_order.c
+      freelist/fitting/best.c
       )
-  elseif(SORT_POLICY STREQUAL "fifo")
+  elseif(FITTING_POLICY STREQUAL "exact")
     set(dmmlib_SRCS
       ${dmmlib_SRCS}
-      freelist/linked_lists/fifo_order.c
+      freelist/fitting/exact.c
       )
-  elseif(SORT_POLICY STREQUAL "size")
+  elseif(FITTING_POLICY STREQUAL "first")
     set(dmmlib_SRCS
       ${dmmlib_SRCS}
-      freelist/linked_lists/add_block_in_order.c
-      freelist/linked_lists/size_order.c
+      freelist/fitting/first.c
       )
-  elseif(SORT_POLICY STREQUAL "address")
+  elseif(FITTING_POLICY STREQUAL "good")
     set(dmmlib_SRCS
       ${dmmlib_SRCS}
-      freelist/linked_lists/add_block_in_order.c
-      freelist/linked_lists/address_order.c
+      freelist/fitting/good.c
       )
-  endif(SORT_POLICY STREQUAL "lifo")
+  endif(FITTING_POLICY STREQUAL "best")
+
+  if(ORDERING_POLICY STREQUAL "address")
+    set(dmmlib_SRCS
+      ${dmmlib_SRCS}
+      freelist/ordering/address.c
+      )
+  elseif(ORDERING_POLICY STREQUAL "fifo")
+    set(dmmlib_SRCS
+      ${dmmlib_SRCS}
+      freelist/ordering/fifo.c
+      )
+  elseif(ORDERING_POLICY STREQUAL "lifo")
+    set(dmmlib_SRCS
+      ${dmmlib_SRCS}
+      freelist/ordering/lifo.c
+      )
+  elseif(ORDERING_POLICY STREQUAL "size")
+    set(dmmlib_SRCS
+      ${dmmlib_SRCS}
+      freelist/ordering/size.c
+      )
+  endif(ORDERING_POLICY STREQUAL "address")
 
   if(COALESCING_FIXED OR COALESCING_VARIABLE)
     set(dmmlib_SRCS

+ 1 - 1
src/free.c

@@ -16,7 +16,7 @@
  */
 
 /**
- * @file   free.c
+ * @file   src/free.c
  * @author Ioannis Koutras (joko@microlab.ntua.gr)
  * @date   September 2012
  *

+ 5 - 6
src/freelist/coalesce.c

@@ -16,9 +16,8 @@
  */
 
 #include "freelist/coalesce.h"
-#include "freelist/linked_lists/add_block.h"
-#include "freelist/linked_lists/linked_lists.h"
 #include "freelist/block_header_funcs.h"
+#include "freelist/ordering_policy.h"
 
 void coalesce(freelist_rb_t *raw_block, block_header_t *ptr) {
     size_t max_coal_size;
@@ -68,7 +67,7 @@ void coalesce(freelist_rb_t *raw_block, block_header_t *ptr) {
     /* Check if Previous + Current + Next is ok */
     if(three_blocks_size <= max_coal_size) {
         /* Remove the next block from the free list */
-        remove_block(next_block, raw_block);
+        REMOVE_FSLLIST(raw_block, next_block);
         /* Update border pointer if the next block was the border pointer */
         if(raw_block->border_ptr == next_block) {
             raw_block->border_ptr = previous_block;
@@ -91,12 +90,12 @@ void coalesce(freelist_rb_t *raw_block, block_header_t *ptr) {
  
     /* Check if Current + Next is ok */
     if(current_next_size <= max_coal_size) {
-        remove_block(next_block, raw_block);
+        REMOVE_FSLLIST(raw_block, next_block);
         if(raw_block->border_ptr == next_block) {
             raw_block->border_ptr = ptr;
         }
         set_size_and_free(raw_block, ptr, current_next_size);
-        add_block(raw_block, ptr);
+        ADD_BLOCK(ptr);
         return;
     }
 
@@ -104,6 +103,6 @@ void coalesce(freelist_rb_t *raw_block, block_header_t *ptr) {
      * list
      */
     mark_free(raw_block, ptr);
-    add_block(raw_block, ptr);
+    ADD_BLOCK(ptr);
     return;
 }

+ 78 - 0
src/freelist/fitting/best.c

@@ -0,0 +1,78 @@
+/*
+ *   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.
+ *
+ */
+
+#include "dmm_config.h"
+
+#include "freelist/fitting/best.h"
+#include "freelist/ordering_policy.h"
+#include "freelist/block_header_funcs.h"
+
+/**
+ * \details In order to remove a block from a singly linked list, we need to
+ * 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.
+ * Normally the best fit search alogrithm would have to traverse the whole list
+ * in order to find the best block. However, a check is being performed each
+ * time a new best candidate is found, so that we stop once a perfect block is
+ * found.
+ */
+block_header_t * fl_best_fit(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;
+
+    previous_block = NULL;
+    best_previous_block = NULL;
+    best_block = NULL;
+    best_size = (size_t) -1; /* SIZE_MAX */
+    
+    SLIST_FOREACH(current_block, &raw_block->fl_head, pointers) {
+        block_size = get_size(current_block);
+        if(block_size >= requested_size) {
+            if(block_size < best_size) {
+                best_block = current_block;
+                best_size = block_size;
+                best_previous_block = previous_block;
+                /* If the requested size is found, there is no need to keep
+                 * searching for a better sized block */
+                if(best_size == requested_size) {
+                    break;
+                }
+            }
+        }
+        previous_block = current_block;
+    } 
+
+    /* Remove the block from the list
+     * Note: no need to iterate through the list as the block is already found
+     */
+    if(best_block != NULL) {
+        if((raw_block->fl_head).slh_first == best_block) {
+            REMOVE_FSLLIST_HEAD(raw_block);
+        } else {
+#ifdef FIFO_ORDERED
+            if(raw_block->fl_tail == best_block) {
+                raw_block->fl_tail = best_previous_block;
+            }
+#endif /* FIFO_ORDERED */
+            best_previous_block->pointers.sle_next =
+                best_block->pointers.sle_next;
+        }
+    }
+
+    return best_block;
+}

+ 53 - 0
src/freelist/fitting/exact.c

@@ -0,0 +1,53 @@
+/*
+ *   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.
+ *
+ */
+
+#include "freelist/fitting/exact.h"
+#include "freelist/ordering_policy.h"
+#include "freelist/block_header_funcs.h"
+
+/**
+ * \details In order to remove a block from a singly linked list, we need to
+ * 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 * fl_exact_fit(freelist_rb_t *raw_block, size_t requested_size) {
+    block_header_t *current_block, *previous_block, *ptr;
+
+    ptr = NULL;
+    previous_block = NULL;
+
+    SLIST_FOREACH(current_block,&raw_block->fl_head, pointers) {
+        if(get_size(current_block) == requested_size) {
+            if((raw_block->fl_head).slh_first == current_block) {
+                REMOVE_FSLLIST_HEAD(raw_block);
+            } else {
+#ifdef FIFO_ORDERED
+                if(raw_block->fl_tail == current_block) {
+                    raw_block->fl_tail = previous_block;
+                }
+#endif /* FIFO_ORDERED */
+                previous_block->pointers.sle_next =
+                    current_block->pointers.sle_next;
+            }
+            ptr = current_block;
+            break;
+        }
+        previous_block = current_block;
+    }
+
+    return ptr;
+}

+ 55 - 0
src/freelist/fitting/first.c

@@ -0,0 +1,55 @@
+/*
+ *   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.
+ *
+ */
+
+#include "dmm_config.h"
+
+#include "freelist/fitting/first.h"
+#include "freelist/ordering_policy.h"
+#include "freelist/block_header_funcs.h"
+
+/**
+ * \details In order to remove a block from a singly linked list, we need to
+ * 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 * fl_first_fit(freelist_rb_t *raw_block, size_t requested_size) {
+    block_header_t *current_block, *previous_block, *ptr;
+
+    ptr = NULL;
+    previous_block = NULL;
+
+    SLIST_FOREACH(current_block, &raw_block->fl_head, pointers) {
+        if(get_size(current_block) >= requested_size) {
+            if((&raw_block->fl_head)->slh_first == current_block) {
+                REMOVE_FSLLIST_HEAD(raw_block);
+            } else {
+#ifdef FIFO_ORDERED
+                if(raw_block->fl_tail == current_block) {
+                    raw_block->fl_tail = previous_block;
+                }
+#endif /* FIFO_ORDERED */
+                previous_block->pointers.sle_next =
+                    current_block->pointers.sle_next;
+            }
+            ptr = current_block;
+            break;
+        }
+        previous_block = current_block;
+    }
+
+    return ptr;
+}

+ 69 - 0
src/freelist/fitting/good.c

@@ -0,0 +1,69 @@
+/*
+ *   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.
+ *
+ */
+
+#include "dmm_config.h"
+
+#include "freelist/fitting/good.h"
+#include "freelist/ordering_policy.h"
+#include "freelist/block_header_funcs.h"
+
+block_header_t * fl_good_fit(freelist_rb_t *raw_block, size_t requested_size) {
+    block_header_t *current_block, *previous_block;
+    block_header_t *good_block, *good_previous_block;
+    size_t good_size, block_size, ideal_size;
+
+    previous_block = NULL;
+    good_previous_block = NULL;
+    good_block = NULL;
+    good_size = (size_t) -1; /* SIZE_MAX */
+    ideal_size = (size_t) ((float) requested_size / GOOD_FIT_PERCENTAGE);
+    
+    SLIST_FOREACH(current_block, &raw_block->fl_head, pointers) {
+        block_size = get_size(current_block);
+        if(block_size >= requested_size) {
+            if(block_size < good_size) {
+                good_block = current_block;
+                good_size = block_size;
+                good_previous_block = previous_block;
+                /* If the requested size is found, there is no need to keep
+                 * searching for a better sized block */
+                if(good_size <= ideal_size) {
+                    break;
+                }
+            }
+        }
+        previous_block = current_block;
+    } 
+
+    /* Remove the block from the list */
+    /* Note: remove_block() is not used because the block is already found */
+    if(good_block != NULL) {
+        if((raw_block->fl_head).slh_first == good_block) {
+            REMOVE_FSLLIST_HEAD(raw_block);
+        } else {
+#ifdef FIFO_ORDERED
+            if(raw_block->fl_tail == good_block) {
+                raw_block->fl_tail = good_previous_block;
+            }
+#endif /* FIFO_ORDERED */
+            good_previous_block->pointers.sle_next =
+                good_block->pointers.sle_next;
+        }
+    }
+
+    return good_block;
+}

+ 3 - 3
src/freelist/freelist_free.c

@@ -16,7 +16,7 @@
  */
 
 /**
- * @file   freelist_free.c
+ * @file   freelist/free.c
  * @author Ioannis Koutras
  * @brief  free() implementation for freelist-organised raw blocks
  */
@@ -24,7 +24,7 @@
 #include "dmmlib/freelist/freelist.h"
 
 #include "freelist/block_header_funcs.h"
-#include "freelist/linked_lists/add_block.h"
+#include "freelist/ordering_policy.h"
 #if defined (COALESCING_FIXED) || defined (COALESCING_VARIABLE)
 #include "freelist/coalesce.h"
 #endif /* COALESCING_FIXED || COALESCING_VARIABLE */
@@ -60,7 +60,7 @@ void freelist_free(freelist_rb_t *raw_block, void *ptr) {
     coalesce(raw_block, block);
 #else
     mark_free(raw_block, block);
-    add_block(raw_block, block);
+    ADD_BLOCK(block);
 #endif /* COALESCING_FIXED || COALESCING_VARIABLE */
 
 }

+ 2 - 5
src/freelist/freelist_debug.c

@@ -26,7 +26,6 @@
 
 #include "dmmlib/freelist/block_header.h"
 #include "freelist/block_header_funcs.h"
-#include "freelist/linked_lists/search_algorithms.h"
 
 #include "trace.h"
 
@@ -38,14 +37,12 @@ void get_memory_blocks(freelist_rb_t *raw_block) {
     block_header_t *memory_block;
     int counter;
 
-    memory_block = raw_block->free_list_head;
-    counter = 0;
+    counter = 1;
 
-    while(memory_block) {
+    SLIST_FOREACH(memory_block, &raw_block->fl_head, pointers) {
         counter++;
         TRACE_1("Free memory block at %p with size %zu\n",
                 (void *)memory_block, get_size(memory_block));
-        memory_block = memory_block->next;
     }
 
     TRACE_1("Raw block at %p has %d memory blocks\n",

+ 3 - 2
src/freelist/initialize.c

@@ -23,7 +23,7 @@
  * @brief  Implementation of free-list initialization.
  */
 
-
+#include "dmmlib/lists.h"
 #include "dmmlib/freelist/initialize.h"
 #include "dmmlib/freelist/freelist_rb.h"
 
@@ -32,7 +32,8 @@ void initialize_freelist(void *address, size_t available_size) {
 
     fl_rb->remaining_size = available_size - sizeof(freelist_rb_t);
     fl_rb->border_ptr = NULL;
-    fl_rb->free_list_head = NULL;
+    
+    SLIST_INIT(&fl_rb->fl_head);
 
     return;
 }

+ 0 - 85
src/freelist/linked_lists/add_block_in_order.c

@@ -1,85 +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 <stddef.h>
-#include "linked_lists/add_block_in_order.h"
-#include "linked_lists/linked_lists.h"
-
-#ifdef COUNT_HOPS
-void add_block_in_order(
-        heap_t *heap,
-        void **block,
-        void **starting_node,
-        bool (*search_condition)(void *block, void* comparing_block)) {
-#else /* COUNT_HOPS */
-void add_block_in_order(
-        void **block,
-        void **starting_node,
-        bool (*search_condition)(void *block, void* comparing_block)) {
-#endif /* COUNT_HOPS */
-    void *current_node;
-    bool added;
-#ifdef BLOCKS_IN_SLL
-    void *previous_node;
-
-    previous_node = NULL;
-#endif /* BLOCKS_IN_SLL */
-
-    added = false;
-
-    /* if the list is empty, put the block in the list's head */
-    if(*starting_node == NULL) {
-        *starting_node = *block;
-        set_next(*block, NULL);
-#ifdef BLOCKS_IN_DLL
-        set_previous(*block, NULL);
-#endif /* BLOCKS_IN_DLL */
-    } else {
-        /* traverse the list to find the right spot to put the block */
-        for(current_node = *starting_node; current_node != NULL;
-                current_node = get_next(current_node)) {
-#ifdef COUNT_HOPS
-            heap->dmm_stats.total_hops++;
-#endif /* COUNT_HOPS */
-            if(search_condition(*block, current_node) == true) {
-#ifdef BLOCKS_IN_SLL
-                if(previous_node != NULL) {
-                    set_next(previous_node, *block);
-                }
-#else /* BLOCKS_IN_SLL */
-                if(get_previous(current_node) != NULL) {
-                    set_next(get_previous(current_node), *block);
-                }
-                set_previous(*block, get_previous(current_node);
-                set_previous(current_node, *block);
-#endif /* BLOCKS_IN_SLL */
-                set_next(*block, current_node);
-                added = true;
-                break;
-            }
-            previous_node = current_node;
-        }
-        /* in case no spot was found, put the block last */
-        if(added == false) {
-            set_next(previous_node, *block);
-#ifdef BLOCKS_IN_DLL
-            set_previous(*block, previous_node);
-#endif /* BLOCKS_IN_DLL */
-        }
-    }
-}
-

+ 0 - 54
src/freelist/linked_lists/address_order.c

@@ -1,54 +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 <stdbool.h>
-#include "block_header.h"
-#include "linked_lists/add_block_in_order.h"
-#include "linked_lists/address_order.h"
-
-bool has_smaller_address(void* block, void* comparing_block);
-
-bool has_smaller_address(void* block, void* comparing_block) {
-    if(block < comparing_block) {
-        return true;
-    } else {
-        return false;
-    }
-}
-
-#ifdef COUNT_HOPS
-void add_block_address_order(
-        heap_t *heap,
-        void **block,
-        void **starting_node) {
-    add_block_in_order(
-            heap,
-            block,
-            starting_node,
-            has_smaller_address);
-}
-#else /* COUNT_HOPS */
-void add_block_address_order(
-        void **block,
-        void **starting_node) {
-    add_block_in_order(
-            block,
-            starting_node,
-            has_smaller_address);
-}
-#endif /* COUNT_HOPS */
-

+ 0 - 43
src/freelist/linked_lists/fifo_order.c

@@ -1,43 +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 "block_header.h"
-#include "linked_lists/fifo_order.h"
-
-void add_block_fifo_order(
-#ifdef COUNT_HOPS
-        heap_t *heap,
-#endif /* COUNT_HOPS */
-        void **block,
-        void **head_node,
-        void **tail_node) {
-    /* The tail node is updated only during add_block().
-     * As a result, it is required to check the head node to see if the list is
-     * empty.
-     */
-    if(*head_node == NULL || *tail_node == NULL) {
-        *head_node = *block;
-    } else {
-#ifdef BLOCKS_IN_DLL
-        set_previous(*block, *tail_node);
-#endif /* BLOCKS_IN_DLL */
-        set_next(*tail_node, *block);
-    }
-    *tail_node = *block;
-    set_next(*block, NULL);
-}
-

+ 0 - 79
src/freelist/linked_lists/linked_lists.c

@@ -1,79 +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 "freelist/linked_lists/linked_lists.h"
-
-#ifdef BLOCKS_IN_DLL
-
-void set_previous(block_header_t *ptr, block_header_t *previous_block) {
-    ptr->previous = previous_block;
-}
-
-void * get_previous(void *ptr) {
-    return (void *) ptr->previous;
-}
-
-#endif /* BLOCKS_IN_DLL */
-
-#ifdef BLOCKS_IN_SLL
-void remove_block(block_header_t *block, freelist_rb_t *raw_block) {
-
-    block_header_t *current_node, *previous_node;
-
-    previous_node = NULL;
-
-    /* Traverse a list starting from the starting node until block is found. */
-    for(current_node = raw_block->free_list_head; current_node != NULL;
-            current_node = current_node->next) {
-        if(current_node == block) {
-            if(current_node == raw_block->free_list_head) {
-                raw_block->free_list_head = block->next;
-            } else {
-                previous_node->next = block->next;
-            }
-            break;
-        }
-        previous_node = current_node;
-    }
-}
-#endif /* BLOCKS_IN_SLL */
-
-#ifdef BLOCKS_IN_DLL
-void remove_block(void **block, void **starting_node) {
-    void *previous_block, *next_block;
-
-    /* No need to traverse the list, just check if the block is the starting
-     * node of the list.
-     */
-
-    previous_block = get_previous(*block);
-    next_block = get_next(*block);
-
-    if(*block == *starting_node) {
-        *starting_node = previous_block;
-    }
-
-    if(previous_block != NULL) {
-        set_next(previous_block, next_block);
-    }
-
-    if(next_block != NULL) {
-        set_previous(next_block, previous_block);
-    }
-
-}
-#endif /* BLOCKS_IN_DLL */

+ 0 - 211
src/freelist/linked_lists/search_algorithms.c

@@ -1,211 +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 <stdio.h>
-#include "freelist/linked_lists/search_algorithms.h"
-#include "freelist/block_header_funcs.h"
-
-/**
- * \details In order to remove a block from a singly linked list, we need to
- * 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.
- * Normally the best fit search alogrithm would have to traverse the whole list
- * in order to find the best block. However, a check is being performed each
- * time a new best candidate is found, so that we stop once a perfect block is
- * found.
- */
-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;
-
-    current_block = NULL;
-    previous_block = NULL;
-    best_previous_block = NULL;
-    best_block = NULL;
-    best_size = (size_t) -1; /* SIZE_MAX */
-    block_size = 0;
-
-    for(current_block = raw_block->free_list_head; current_block != NULL;
-            current_block = current_block->next) {
-        block_size = get_size(current_block);
-        if(block_size >= requested_size) {
-            if(block_size < best_size) {
-                best_block = current_block;
-                best_size = get_size(current_block);
-                best_previous_block = previous_block;
-                /* If the requested size is found, there is no need to keep
-                 * searching for a better sized block */
-                if(best_size == requested_size) {
-                    break;
-                }
-            }
-        }
-        previous_block = current_block;
-    } 
-
-    /* Remove the block from the list */
-    /* Note: remove_block() is not used because the block is already found */
-    if(best_block != NULL) {
-        if(best_block == raw_block->free_list_head) {
-            raw_block->free_list_head = best_block->next;
-#ifdef BLOCKS_IN_DLL
-            if(heap->free_list_head != NULL) {
-                set_previous(heap->free_list_head, NULL);
-            }
-#endif /* BLOCKS_IN_DLL */
-        } else {
-            best_previous_block->next = best_block->next;
-#ifdef BLOCKS_IN_DLL
-            if(get_next(best_block) != NULL) {
-                set_previous(get_next(best_block), best_previous_block);
-            }
-#endif /* BLOCKS_IN_DLL */
-        }
-    }
-
-    return best_block;
-}
-
-#ifdef GOOD_FIT
-
-void * good_fit_on_freelist(raw_block_header_t *raw_block, size_t requested_size) {
-    void *current_block, *previous_block;
-    void *best_block, *best_previous_block;
-    size_t best_size, block_size;
-
-    current_block = NULL;
-    previous_block = NULL;
-    best_previous_block = NULL;
-    best_block = NULL;
-    best_size = (size_t) -1; /* SIZE_MAX */
-    block_size = 0;
-
-    for(current_block = heap->free_list_head; current_block != NULL;
-            current_block = get_next(current_block)) {
-#ifdef COUNT_HOPS
-        heap->dmm_stats.total_hops++;
-#endif /* COUNT_HOPS */
-        block_size = get_size(current_block);
-        if(block_size >= requested_size) {
-            if(block_size < best_size) {
-                best_block = current_block;
-                best_size = get_size(current_block);
-                best_previous_block = previous_block;
-		/* If the block size fits the relaxed requirements, then there
-		 * is no need to keep searching for a better sized block */
-                if(heap->dmm_knobs.fit_percentage * best_size <= requested_size) {
-                    break;
-                }
-            }
-        }
-        previous_block = current_block;
-    } 
-
-    /* Remove the block from the list */
-    /* Note: remove_block() is not used because the block is already found */
-    if(best_block != NULL) {
-        if(best_block == heap->free_list_head) {
-            heap->free_list_head = get_next(best_block);
-#ifdef BLOCKS_IN_DLL
-            if(heap->free_list_head != NULL) {
-                set_previous(heap->free_list_head, NULL);
-            }
-#endif /* BLOCKS_IN_DLL */
-        } else {
-            set_next(best_previous_block, get_next(best_block));
-#ifdef BLOCKS_IN_DLL
-            if(get_next(best_block) != NULL) {
-                set_previous(get_next(best_block), best_previous_block);
-            }
-#endif /* BLOCKS_IN_DLL */
-        }
-    }
-
-    return best_block;
-}
-
-#endif /* GOOD_FIT */
-
-
-/**
- * \details In order to remove a block from a singly linked list, we need to
- * 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(freelist_rb_t *raw_block, size_t requested_size) {
-    block_header_t *current_block, *previous_block, *ptr;
-
-    previous_block = NULL;
-    ptr = NULL;
-
-    for(current_block = raw_block->free_list_head; current_block != NULL;
-            current_block = current_block->next) {
-        if(get_size(current_block) == requested_size) {
-            if(current_block == raw_block->free_list_head) {
-                raw_block->free_list_head = current_block->next;
-#ifdef BLOCKS_IN_DLL
-                set_previous(heap->free_list_head, NULL);
-#endif /* BLOCKS_IN_DLL */
-            } else {
-                previous_block->next = current_block->next;
-#ifdef BLOCKS_IN_DLL
-                set_previous(get_next(current_block), previous_block);
-#endif /* BLOCKS_IN_DLL */
-            }
-            ptr = current_block;
-            break;
-        }
-        previous_block = current_block;
-    } 
-
-    return ptr;
-}
-
-/**
- * \details In order to remove a block from a singly linked list, we need to
- * 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(freelist_rb_t *raw_block, size_t requested_size) {
-    block_header_t *current_block, *previous_block, *ptr;
-
-    previous_block = NULL;
-    ptr = NULL;
-
-    for(current_block = raw_block->free_list_head; current_block != NULL;
-            current_block = current_block->next) {
-        if(get_size(current_block) >= requested_size) {
-            if(current_block == raw_block->free_list_head) {
-                raw_block->free_list_head = current_block->next;
-#ifdef BLOCKS_IN_DLL
-                set_previous(heap->free_list_head, NULL);
-#endif /* BLOCKS_IN_DLL */
-            } else {
-                previous_block->next = current_block->next;
-#ifdef BLOCKS_IN_DLL
-                set_previous(get_next(current_block), previous_block);
-#endif /* BLOCKS_IN_DLL */
-            }
-            ptr = current_block;
-            break;
-        }
-        previous_block = current_block;
-    } 
-
-    return ptr;
-}

+ 0 - 54
src/freelist/linked_lists/size_order.c

@@ -1,54 +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 <stdbool.h>
-#include "block_header.h"
-#include "linked_lists/add_block_in_order.h"
-#include "linked_lists/size_order.h"
-
-bool has_smaller_size(void* block, void* comparing_block);
-
-bool has_smaller_size(void* block, void* comparing_block) {
-    if(get_size(block) < get_size(comparing_block)) {
-        return true;
-    } else {
-        return false;
-    }
-}
-
-#ifdef COUNT_HOPS
-void add_block_size_order(
-        heap_t *heap,
-        void **block,
-        void **starting_node) {
-    add_block_in_order(
-            heap,
-            block,
-            starting_node,
-            has_smaller_size);
-}
-#else /* COUNT_HOPS */
-void add_block_size_order(
-        void **block,
-        void **starting_node) {
-    add_block_in_order(
-            block,
-            starting_node,
-            has_smaller_size);
-}
-#endif /* COUNT_HOPS */
-

+ 8 - 24
src/freelist/freelist_malloc.c

@@ -16,7 +16,7 @@
  */
 
 /**
- * @file   freelist_malloc.c
+ * @file   freelist/malloc.c
  * @author Ioannis Koutras
  * @date   September 2012
  * @brief  malloc() implementation for freelist-organised raw blocks
@@ -24,9 +24,10 @@
 
 #include "dmmlib/freelist/freelist.h"
 
+#include <inttypes.h>
+
+#include "freelist/fitting_policy.h"
 #include "freelist/block_header_funcs.h"
-#include "freelist/linked_lists/linked_lists.h"
-#include "freelist/linked_lists/search_algorithms.h"
 
 #if defined (SPLITTING_FIXED) || defined (SPLITTING_VARIABLE)
 #include "freelist/split.h"
@@ -39,21 +40,6 @@
 #include "dmmlib/dmmlib.h"
 #endif /* WITH_ALLOCATOR_STATS */
 
-/**
- * Tries to find the best available free memory block
- *
- * @param size The requested size
- */
-#if defined (BEST_FIT)
-#define search_on_free(size) best_fit_on_freelist(raw_block, size)
-#elif defined (GOOD_FIT)
-#define search_on_free(size) good_fit_on_freelist(raw_block, size)
-#elif defined (EXACT_FIT)
-#define search_on_free(size) exact_fit_on_freelist(raw_block, size)
-#elif defined (FIRST_FIT)
-#define search_on_free(size) first_fit_on_freelist(raw_block, size)
-#endif /* BEST_FIT */ 
-
 size_t req_padding(size_t size);
 
 /** Tries to align the input to 32, 64, 128, 256 or to a multiple of 4 if it is
@@ -90,9 +76,7 @@ void * freelist_malloc(freelist_rb_t *raw_block, size_t size) {
     block_header_t *ptr;
     size_t allocation_size, previous_size, previous_size_availability;
 
-    ptr = NULL;
-
-    ptr = search_on_free(size);
+    ptr = SEARCH_LIST(raw_block, size);
 
     if(ptr != NULL) {
 #ifdef REQUEST_SIZE_INFO
@@ -112,13 +96,13 @@ void * freelist_malloc(freelist_rb_t *raw_block, size_t size) {
         if(allocation_size <= raw_block->remaining_size) {
             if(raw_block->border_ptr == NULL) {
                 previous_size_availability = 1; // Occupied and of 0 size
-                ptr = (block_header_t *)((char *)raw_block +
+                ptr = (block_header_t *)((uintptr_t) raw_block +
                         sizeof(freelist_rb_t));
             } else {
                 previous_size = get_size(raw_block->border_ptr);
                 previous_size_availability =
                     get_size_availability(raw_block->border_ptr);
-                ptr = (block_header_t *)((char *)raw_block->border_ptr +
+                ptr = (block_header_t *)((uintptr_t) raw_block->border_ptr +
                         HEADER_SIZE + previous_size);
             }
 
@@ -146,7 +130,7 @@ void * freelist_malloc(freelist_rb_t *raw_block, size_t size) {
                 get_size(ptr) + HEADER_SIZE);
 #endif /* WITH_ALLOCATOR_STATS */
 
-        return (void *)((char *)ptr + HEADER_SIZE);
+        return (void *)((uintptr_t) ptr + HEADER_SIZE);
     } else {
         return NULL;
     }

+ 45 - 0
src/freelist/ordering/address.c

@@ -0,0 +1,45 @@
+/*
+ *   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.
+ *
+ */
+
+#include "freelist/ordering/address.h"
+#include "freelist/block_header_funcs.h"
+
+#include <inttypes.h>
+
+void add_to_address_ordered(struct fl_head_s *head, block_header_t *block) {
+    block_header_t *current_block, *next_block;
+
+    if(head->slh_first == NULL) {
+        SLIST_INSERT_HEAD(head, block, pointers);
+    } else {
+        SLIST_FOREACH(current_block, head, pointers) {
+            next_block = current_block->pointers.sle_next;
+            if(next_block != NULL) {
+                if((uintptr_t) next_block > (uintptr_t) block) {
+                    current_block->pointers.sle_next = block;
+                    block->pointers.sle_next = next_block;
+                    break;
+                }
+            } else { /* We are on the end of the list, add the block there */
+                current_block->pointers.sle_next = block;
+                block->pointers.sle_next = NULL;
+                break;
+            }
+        }
+    }
+    return;
+}

+ 29 - 0
src/freelist/ordering/fifo.c

@@ -0,0 +1,29 @@
+/*
+ *   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.
+ *
+ */
+
+#include "freelist/ordering/fifo.h"
+#include "freelist/block_header_funcs.h"
+
+void add_to_fifo_ordered(freelist_rb_t *raw_block, block_header_t *block) {
+    if(raw_block->fl_tail != NULL) {
+        raw_block->fl_tail->pointers.sle_next = block;
+        block->pointers.sle_next = NULL;
+    } else {
+        SLIST_INSERT_HEAD(&raw_block->fl_head, block, pointers);
+    }
+    raw_block->fl_tail = block;
+}

+ 5 - 8
src/freelist/linked_lists/lifo_order.c

@@ -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.
@@ -15,12 +15,9 @@
  *
  */
 
-#include "freelist/linked_lists/lifo_order.h"
+#include "freelist/ordering/lifo.h"
+#include "freelist/block_header_funcs.h"
 
-void add_block_lifo_order(
-        freelist_rb_t *raw_block,
-        block_header_t *block) {
-    
-    block->next = raw_block->free_list_head;
-    raw_block->free_list_head = block;
+void add_to_lifo_ordered(freelist_rb_t *raw_block, block_header_t *block) {
+    SLIST_INSERT_HEAD(&raw_block->fl_head, block, pointers);
 }

+ 46 - 0
src/freelist/ordering/size.c

@@ -0,0 +1,46 @@
+/*
+ *   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.
+ *
+ */
+
+#include "freelist/ordering/size.h"
+#include "freelist/block_header_funcs.h"
+
+void add_to_size_ordered(struct fl_head_s *head, block_header_t *block) {
+    block_header_t *current_block, *next_block;
+    size_t block_size;
+
+    block_size = get_size(block);
+
+    if(head->slh_first == NULL) {
+        SLIST_INSERT_HEAD(head, block, pointers);
+    } else {
+        SLIST_FOREACH(current_block, head, pointers) {
+            next_block = current_block->pointers.sle_next;
+            if(next_block != NULL) {
+                if(get_size(next_block) > block_size) {
+                    current_block->pointers.sle_next = block;
+                    block->pointers.sle_next = next_block;
+                    break;
+                }
+            } else { /* We are on the end of the list, add the block there */
+                current_block->pointers.sle_next = block;
+                block->pointers.sle_next = NULL;
+                break;
+            }
+        }
+    }
+    return;
+}

+ 3 - 12
src/freelist/split.c

@@ -18,11 +18,7 @@
 #include "freelist/split.h"
 
 #include "freelist/block_header_funcs.h"
-#include "freelist/linked_lists/add_block.h"
-
-#ifdef COALESCE_AFTER_SPLIT
-#include "freelist/linked_lists/linked_lists.h" // for remove_block()
-#endif /* COALESCE_AFTER_SPLIT */
+#include "freelist/ordering_policy.h"
 
 void split(freelist_rb_t *raw_block, block_header_t *ptr, size_t req_size) {
     size_t new_size;
@@ -79,7 +75,7 @@ void split(freelist_rb_t *raw_block, block_header_t *ptr, size_t req_size) {
     if(next_block != NULL && is_free(next_block) == true) {
         current_next_size = new_size + get_size(next_block) + HEADER_SIZE;
         if(current_next_size <= max_coal_size) {
-            remove_block(next_block, raw_block);
+            REMOVE_FSLLIST(raw_block, next_block);
             if(raw_block->border_ptr == next_block) {
                 raw_block->border_ptr = new_block;
             }
@@ -91,10 +87,5 @@ void split(freelist_rb_t *raw_block, block_header_t *ptr, size_t req_size) {
 
     set_size_and_free(raw_block, new_block, new_size);
 
-#ifdef FIFO_SORT_POLICY
-    add_block(&new_block, &heap->free_list_head, &heap->free_list_tail);
-#else /* FIFO_SORT_POLICY */
-    add_block(raw_block, new_block);
-#endif /* FIFO_SORT_POLICY */
-
+    ADD_BLOCK(new_block);
 }

+ 1 - 1
src/malloc.c

@@ -16,7 +16,7 @@
  */
 
 /**
- * @file   malloc.c
+ * @file   src/malloc.c
  * @author Ioannis Koutras (joko@microlab.ntua.gr)
  * @date   September 2012
  *

+ 3 - 1
src/realloc.c

@@ -31,8 +31,8 @@
 
 #include "release_memory.h"
 #include <sys/mman.h>
-
 #include <string.h>
+#include <inttypes.h>
 
 #ifdef WITH_DEBUG
 #include "debug.h"
@@ -103,7 +103,9 @@ void * realloc(void *ptr, size_t size) {
 
         } else { /* We have to create a new big block */
 
+#ifdef WITH_ALLOCATOR_STATS
             size_t size_diff = full_size - owner_raw_block->size;
+#endif /* WITH_ALLOCATOR_STATS */
 
             raw_block_header_t *new_block = create_raw_block(full_size,
                     BIGBLOCK);