浏览代码

Support for various list ordering policies

Ioannis Koutras 13 年之前
父节点
当前提交
983676db07

+ 9 - 0
CMakeLists.txt

@@ -42,6 +42,15 @@ if(BLOCKS_ORGANIZATION STREQUAL "dll")
 else(BLOCKS_ORGANIZATION STREQUAL "dll")
   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 "Predefined lists of fixed-sized blocks: " ${WITH_FIXED_LISTS})
 message(STATUS "Heap Ownership per Block: " ${WITH_OWNERSHIP})
 message(STATUS "Have statistics: " ${WITH_STATS})

+ 14 - 1
DefineOptions.cmake

@@ -13,6 +13,8 @@ option(WITH_SHARED_LIB "Build a shared library" OFF)
 option(WITH_DOC "Build with documentation" OFF)
 option(REPLACE_MALLOC "Replace function calls" OFF)
 
+option(SORT_POLICY "Choose the block sorting policy, options are: lifo, fifo, size, address")
+
 set(NUM_HEAPS 1)
 
 if (NUM_HEAPS GREATER 1)
@@ -62,8 +64,9 @@ if (LEON3)
 endif (LEON3)
 
 if (LINUXTEST)
+  set(SORT_POLICY "fifo")
   set(WITH_MEMORY_SPACE_AWARENESS ON)
-  set(SEARCH_POLICY "good")
+  set(SEARCH_POLICY "best")
   set(FIT_PERCENTAGE 0.6f)
   set(HAVE_LOCKS OFF)
   set(WITH_EXAMPLES ON)
@@ -84,6 +87,16 @@ 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(WITH_SYSTEM_CALLS STREQUAL "mmap")
   set(WITH_MMAP ON)
 else(WITH_SYSTEM_CALLS STREQUAL "mmap")

+ 5 - 0
dmm_config.h.in

@@ -12,6 +12,11 @@
 
 #cmakedefine WITH_FIXED_LISTS
 
+#cmakedefine LIFO_SORT_POLICY
+#cmakedefine FIFO_SORT_POLICY
+#cmakedefine SIZE_SORT_POLICY
+#cmakedefine ADDRESS_SORT_POLICY
+
 #cmakedefine BEST_FIT
 #cmakedefine GOOD_FIT
 #ifdef GOOD_FIT

+ 6 - 0
include/dmmlib/heap.h

@@ -60,6 +60,9 @@ typedef uint8_t knob_state_t;
 typedef struct maptable_node_s {
 	unsigned int size; /**< The size of the blocks of the fixed list. */
 	void *fixed_list_head; /**< Pointer to the head node of the fixed list. */
+#ifdef FIFO_SORT_POLICY
+	void *fixed_list_tail; /**< Pointer to the tail node of the fixed list. */
+#endif /* FIFO_SORT_POLICY */
 	struct maptable_node_s *next; /**< Pointer to the next node of the
 					maptable. */
 } maptable_node_t;
@@ -118,6 +121,9 @@ typedef struct heap_s {
 	maptable_node_t *maptable_head; /**< The head of the maptable list. */
 #endif /* WITH_FIXED_LISTS */
 	void *free_list_head; /**< The head of the free list. */
+#ifdef FIFO_SORT_POLICY
+	void *free_list_tail; /**< The tail of the free list. */
+#endif /* FIFO_SORT_POLICY */
 #ifdef FUTURE_FEATURES
 	void *used_blocks_head; /**< The head of the used blocks list. */
 	void *rov_ptr; /**< Roving pointer. */

+ 48 - 0
private-include/linked_lists/add_block.h

@@ -0,0 +1,48 @@
+/*
+ *   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.h
+ * \author      Ioannis Koutras (joko@microlab.ntua.gr)
+ * \date        January, 2012
+ *  
+ * \brief Add a block in a linked list.
+ */
+
+#ifndef ADD_BLOCK_H
+#define ADD_BLOCK_H
+
+#include "dmm_config.h"
+
+#ifdef LIFO_SORT_POLICY
+#include "linked_lists/lifo_order.h"
+#endif /* LIFO_SORT_POLICY */
+
+#ifdef FIFO_SORT_POLICY
+#include "linked_lists/fifo_order.h"
+#endif /* LIFO_SORT_POLICY */
+
+#ifdef SIZE_SORT_POLICY
+#include "linked_lists/size_order.h"
+#endif /* LIFO_SORT_POLICY */
+
+#ifdef ADDRESS_SORT_POLICY
+#include "linked_lists/address_order.h"
+#endif /* LIFO_SORT_POLICY */
+
+#endif /* ADD_BLOCK_H */
+

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

@@ -0,0 +1,59 @@
+/*
+ *   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 */
+

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

@@ -0,0 +1,63 @@
+/*
+ *   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 */
+

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

@@ -0,0 +1,58 @@
+/*
+ *   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 */
+

+ 63 - 0
private-include/linked_lists/lifo_order.h

@@ -0,0 +1,63 @@
+/*
+ *   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        lifo_order.h
+ * \author      Ioannis Koutras (joko@microlab.ntua.gr)
+ * \date        January, 2012
+ *  
+ * \brief Add a block in a LIFO-ordered linked list.
+ */
+
+#ifndef LIFO_ORDER_H
+#define LIFO_ORDER_H
+
+#ifdef COUNT_HOPS
+#include <dmmlib/heap.h>
+#endif /* COUNT_HOPS */
+#include "dmm_config.h"
+
+#ifdef LIFO_SORT_POLICY
+#ifdef COUNT_HOPS
+#define add_block(heap, block, list) add_block_lifo_order(heap, block, list)
+#else /* COUNT_HOPS */
+#define add_block(block, list) add_block_lifo_order(block, list)
+#endif /* COUNT_HOPS */
+#endif /* LIFO_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 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_lifo_order(
+        heap_t *heap,
+        void **block,
+        void **starting_node);
+#else /* COUNT_HOPS */
+void add_block_lifo_order(
+        void **block,
+        void **starting_node);
+#endif /* COUNT_HOPS */
+
+#endif /* LIFO_ORDER_H */
+

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

@@ -0,0 +1,63 @@
+/*
+ *   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 */
+

+ 1 - 0
private-include/split.h

@@ -19,6 +19,7 @@
 #define SPLIT_H
 
 #include <dmmlib/heap.h>
+#include "dmm_config.h"
 
 /**
  * Splits a memory block to two blocks: one with the requested size and the

+ 24 - 0
src/CMakeLists.txt

@@ -47,6 +47,30 @@ if (HAVE_LOCKS)
   )
 endif (HAVE_LOCKS)
 
+if(SORT_POLICY STREQUAL "lifo")
+  set(dmmlib_SRCS
+    ${dmmlib_SRCS}
+    linked_lists/lifo_order.c
+  )
+elseif(SORT_POLICY STREQUAL "fifo")
+  set(dmmlib_SRCS
+    ${dmmlib_SRCS}
+    linked_lists/fifo_order.c
+  )
+elseif(SORT_POLICY STREQUAL "size")
+  set(dmmlib_SRCS
+    ${dmmlib_SRCS}
+    linked_lists/add_block_in_order.c
+    linked_lists/size_order.c
+  )
+elseif(SORT_POLICY STREQUAL "address")
+  set(dmmlib_SRCS
+    ${dmmlib_SRCS}
+    linked_lists/add_block_in_order.c
+    linked_lists/address_order.c
+  )
+endif(SORT_POLICY STREQUAL "lifo")
+
 if (COALESCING_FIXED OR COALESCING_VARIABLE)
   set(dmmlib_SRCS
     ${dmmlib_SRCS}

+ 41 - 4
src/custom_free.c

@@ -24,6 +24,7 @@
 #if defined (COALESCING_FIXED) || defined (COALESCING_VARIABLE)
 #include "coalesce.h"
 #endif /* COALESCING_FIXED || COALESCING_VARIABLE */
+#include "linked_lists/add_block.h"
 #ifdef WITH_ADAPTIVITY
 #include "dmm_adaptor.h"
 #endif /* WITH_ADAPTIVITY */
@@ -175,7 +176,19 @@ void custom_ahfree(allocator_t *allocator, heap_t* heap, void *ptr) {
                 current_maptable_node = current_maptable_node->next;
             }
         }
-        push_block(&ptr, &current_maptable_node->fixed_list_head);
+#ifdef COUNT_HOPS
+#ifdef FIFO_SORT_POLICY
+        add_block(heap, &ptr, &current_maptable_node->fixed_list_head, &current_maptable_node->fixed_list_tail);
+#else /* FIFO_SORT_POLICY */
+        add_block(heap, &ptr, &current_maptable_node->fixed_list_head);
+#endif /* FIFO_SORT_POLICY */
+#else /* COUNT_HOPS */
+#ifdef FIFO_SORT_POLICY
+        add_block(&ptr, &current_maptable_node->fixed_list_head, &current_maptable_node->fixed_list_tail);
+#else /* FIFO_SORT_POLICY */
+        add_block(&ptr, &current_maptable_node->fixed_list_head);
+#endif /* FIFO_SORT_POLICY */
+#endif /* COUNT_HOPS */
     } else { /* put it in the free list */
 #endif /* WITH_FIXED_LISTS */
 #if defined (COALESCING_FIXED) || defined (COALESCING_VARIABLE)
@@ -183,10 +196,34 @@ void custom_ahfree(allocator_t *allocator, heap_t* heap, void *ptr) {
          * coalesced
          */
         if(!coalesced) {
-            push_block(&ptr, &heap->free_list_head);
+#ifdef COUNT_HOPS
+#ifdef FIFO_SORT_POLICY
+            add_block(heap, &ptr, &heap->free_list_head, &heap->free_list_tail);
+#else /* FIFO_SORT_POLICY */
+            add_block(heap, &ptr, &heap->free_list_head);
+#endif /* FIFO_SORT_POLICY */
+#else /* COUNT_HOPS */
+#ifdef FIFO_SORT_POLICY
+            add_block(&ptr, &heap->free_list_head, &heap->free_list_tail);
+#else /* FIFO_SORT_POLICY */
+            add_block(&ptr, &heap->free_list_head);
+#endif /* FIFO_SORT_POLICY */
+#endif /* COUNT_HOPS */
         }
-#else
-        push_block(&ptr, &heap->free_list_head);
+#else /* COALESCING_FIXED || COALESCING_VARIABLE */
+#ifdef COUNT_HOPS
+#ifdef FIFO_SORT_POLICY
+        add_block(heap, &ptr, &heap->free_list_head, &heap->free_list_tail);
+#else /* FIFO_SORT_POLICY */
+        add_block(heap, &ptr, &heap->free_list_head);
+#endif /* FIFO_SORT_POLICY */
+#else /* COUNT_HOPS */
+#ifdef FIFO_SORT_POLICY
+        add_block(&ptr, &heap->free_list_head, &heap->free_list_tail);
+#else /* FIFO_SORT_POLICY */
+        add_block(&ptr, &heap->free_list_head);
+#endif /* FIFO_SORT_POLICY */
+#endif /* COUNT_HOPS */
 #endif /* COALESCING_FIXED || COALESCING_VARIABLE */
 #ifdef WITH_FIXED_LISTS
     }

+ 85 - 0
src/linked_lists/add_block_in_order.c

@@ -0,0 +1,85 @@
+/*
+ *   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 */
+        }
+    }
+}
+

+ 54 - 0
src/linked_lists/address_order.c

@@ -0,0 +1,54 @@
+/*
+ *   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 */
+

+ 43 - 0
src/linked_lists/fifo_order.c

@@ -0,0 +1,43 @@
+/*
+ *   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);
+}
+

+ 40 - 0
src/linked_lists/lifo_order.c

@@ -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.
+ *
+ */
+
+#include "block_header.h"
+#include "linked_lists/lifo_order.h"
+
+void add_block_lifo_order(
+#ifdef COUNT_HOPS
+        heap_t *heap,
+#endif /* COUNT_HOPS */
+        void **block,
+        void **starting_node) {
+    if(*starting_node != NULL) {
+#ifdef BLOCKS_IN_DLL
+        set_previous(*starting_node, *block);
+#endif /* BLOCKS_IN_DLL */
+        set_next(*block, *starting_node);
+    } else {
+        set_next(*block, NULL);
+    }
+#ifdef BLOCKS_IN_DLL
+    set_previous(*block, NULL);
+#endif /* BLOCKS_IN_DLL */
+    *starting_node = *block;
+}
+

+ 54 - 0
src/linked_lists/size_order.c

@@ -0,0 +1,54 @@
+/*
+ *   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 */
+

+ 28 - 3
src/split.c

@@ -17,8 +17,8 @@
 
 #include "block_header.h"
 #include "other.h"
+#include "linked_lists/add_block.h"
 #include "split.h"
-#include "dmm_config.h"
 
 void split(allocator_t *allocator, heap_t *heap, void *ptr,
         size_t req_size) {
@@ -53,10 +53,35 @@ void split(allocator_t *allocator, heap_t *heap, void *ptr,
                 current_maptable_node = current_maptable_node->next;
             }
         }
-        push_block(&new_block, &current_maptable_node->fixed_list_head);
+#ifdef COUNT_HOPS
+#ifdef FIFO_SORT_POLICY
+        add_block(heap, &new_block, &current_maptable_node->fixed_list_head, &current_maptable_node->fixed_list_tail);
+#else /* FIFO_SORT_POLICY */
+        add_block(heap, &new_block, &current_maptable_node->fixed_list_head);
+#endif /* FIFO_SORT_POLICY */
+#else /* COUNT_HOPS */
+#ifdef FIFO_SORT_POLICY
+        add_block(&new_block, &current_maptable_node->fixed_list_head, &current_maptable_node->fixed_list_tail);
+#else /* FIFO_SORT_POLICY */
+        add_block(&new_block, &current_maptable_node->fixed_list_head);
+#endif /* FIFO_SORT_POLICY */
+#endif /* COUNT_HOPS */
     } else { /* put it in the free list */
 #endif /* WITH_FIXED_LISTS */
-        push_block(&new_block, &heap->free_list_head);
+
+#ifdef COUNT_HOPS
+#ifdef FIFO_SORT_POLICY
+        add_block(heap, &new_block, &heap->free_list_head, &heap->free_list_tail);
+#else /* FIFO_SORT_POLICY */
+        add_block(heap, &new_block, &heap->free_list_head);
+#endif /* FIFO_SORT_POLICY */
+#else /* COUNT_HOPS */
+#ifdef FIFO_SORT_POLICY
+        add_block(&new_block, &heap->free_list_head, &heap->free_list_tail);
+#else /* FIFO_SORT_POLICY */
+        add_block(&new_block, &heap->free_list_head);
+#endif /* FIFO_SORT_POLICY */
+#endif /* COUNT_HOPS */
 #ifdef WITH_FIXED_LISTS
     }
 #endif /* WITH_FIXED_LISTS */