1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/pkg/tlsf/patch.txt

579 lines
22 KiB
Plaintext
Raw Normal View History

diff --git Makefile Makefile
new file mode 100644
index 0000000..a51d6c2
--- /dev/null
+++ Makefile
@@ -0,0 +1,3 @@
+MODULE = tlsf
+
+include $(RIOTBASE)/Makefile.base
diff --git tlsf-malloc.c tlsf-malloc.c
new file mode 100644
index 0000000..cb16af8
--- /dev/null
+++ tlsf-malloc.c
@@ -0,0 +1,44 @@
+#include "irq.h"
+#include "tlsf-malloc.h"
+
+#include <string.h>
+
+void *TLSF_MALLOC_NAME(malloc)(size_t bytes)
+{
+ unsigned old_state = irq_disable();
+ void *result = tlsf_malloc(bytes);
+ irq_restore(old_state);
+ return result;
+}
+
+void *TLSF_MALLOC_NAME(calloc)(size_t count, size_t bytes)
+{
+ void *result = tlsf_malloc(count * bytes);
+ if (result) {
+ memset(result, 0, count * bytes);
+ }
+ return result;
+}
+
+void *TLSF_MALLOC_NAME(memalign)(size_t align, size_t bytes)
+{
+ unsigned old_state = irq_disable();
+ void *result = tlsf_memalign(align, bytes);
+ irq_restore(old_state);
+ return result;
+}
+
+void *TLSF_MALLOC_NAME(realloc)(void *ptr, size_t size)
+{
+ unsigned old_state = irq_disable();
+ void *result = tlsf_realloc(ptr, size);
+ irq_restore(old_state);
+ return result;
+}
+
+void TLSF_MALLOC_NAME(free)(void *ptr)
+{
+ unsigned old_state = irq_disable();
+ tlsf_free(ptr);
+ irq_restore(old_state);
+}
diff --git tlsf-malloc.h tlsf-malloc.h
new file mode 100644
index 0000000..2d8bb4d
--- /dev/null
+++ tlsf-malloc.h
@@ -0,0 +1,26 @@
+#ifndef __TLSF_MALLOC_H
+#define __TLSF_MALLOC_H
+
+#include <stdbool.h>
+#include <stddef.h>
+
+#include "tlsf.h"
+
+#ifndef TLSF_MALLOC_PREFIX
+# define TLSF_MALLOC_PREFIX
+#endif
+#define __TLSF_MALLOC_NAME(A, B) A ## B
+#define _TLSF_MALLOC_NAME(A, B) __TLSF_MALLOC_NAME(A, B)
+#define TLSF_MALLOC_NAME(NAME) _TLSF_MALLOC_NAME(TLSF_MALLOC_PREFIX, NAME)
+
+void *TLSF_MALLOC_NAME(malloc)(size_t bytes);
+
+void *TLSF_MALLOC_NAME(calloc)(size_t count, size_t bytes);
+
+void *TLSF_MALLOC_NAME(memalign)(size_t align, size_t bytes);
+
+void *TLSF_MALLOC_NAME(realloc)(void *ptr, size_t size);
+
+void TLSF_MALLOC_NAME(free)(void *ptr);
+
+#endif
diff --git tlsf.c tlsf.c
index 3fb5ebd..99c84b2 100644
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
--- tlsf.c
+++ tlsf.c
@@ -25,4 +24,0 @@ enum tlsf_private
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
-#if defined (TLSF_64BIT)
- /* All allocation sizes and addresses are aligned to 8 bytes. */
- ALIGN_SIZE_LOG2 = 3,
-#else
@@ -30,3 +26,2 @@ enum tlsf_private
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
- ALIGN_SIZE_LOG2 = 2,
-#endif
- ALIGN_SIZE = (1 << ALIGN_SIZE_LOG2),
+#define ALIGN_SIZE_LOG2 (2)
+#define ALIGN_SIZE (1 << ALIGN_SIZE_LOG2)
@@ -45,7 +39,0 @@ enum tlsf_private
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
-#if defined (TLSF_64BIT)
- /*
- ** TODO: We can increase this to support larger sizes, at the expense
- ** of more overhead in the TLSF structure.
- */
- FL_INDEX_MAX = 32,
-#else
@@ -53 +40,0 @@ enum tlsf_private
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
-#endif
@@ -73 +60 @@ enum tlsf_private
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
-#define tlsf_assert assert
+#define tlsf_assert(X) do { if (0) { (void) (X); } } while (0)
@@ -147 +134 @@ static const size_t block_start_offset =
-static const size_t block_size_min =
+static const size_t block_size_min =
@@ -165,0 +153 @@ typedef struct control_t
+static control_t *control;
2016-05-27 12:22:28 +02:00
@@ -168,0 +157,4 @@ typedef ptrdiff_t tlsfptr_t;
+#ifdef DEVELHELP
+void *default_pool;
+#endif
+
@@ -345 +337 @@ static void mapping_search(size_t size, int* fli, int* sli)
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
-static block_header_t* search_suitable_block(control_t* control, int* fli, int* sli)
+static block_header_t* search_suitable_block(int* fli, int* sli)
@@ -354 +346 @@ static block_header_t* search_suitable_block(control_t* control, int* fli, int*
- unsigned int sl_map = control->sl_bitmap[fl] & (~0 << sl);
+ unsigned int sl_map = control->sl_bitmap[fl] & (((unsigned int)~0) << sl);
@@ -358 +350 @@ static block_header_t* search_suitable_block(control_t* control, int* fli, int*
- const unsigned int fl_map = control->fl_bitmap & (~0 << (fl + 1));
+ const unsigned int fl_map = control->fl_bitmap & (((unsigned int)~0) << (fl + 1));
2016-05-27 12:22:28 +02:00
@@ -378 +370 @@ static block_header_t* search_suitable_block(control_t* control, int* fli, int*
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
-static void remove_free_block(control_t* control, block_header_t* block, int fl, int sl)
+static void remove_free_block(block_header_t* block, int fl, int sl)
2016-05-27 12:22:28 +02:00
@@ -407 +399 @@ static void remove_free_block(control_t* control, block_header_t* block, int fl,
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
-static void insert_free_block(control_t* control, block_header_t* block, int fl, int sl)
+static void insert_free_block(block_header_t* block, int fl, int sl)
2016-05-27 12:22:28 +02:00
@@ -428 +420 @@ static void insert_free_block(control_t* control, block_header_t* block, int fl,
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
-static void block_remove(control_t* control, block_header_t* block)
+static void block_remove(block_header_t* block)
2016-05-27 12:22:28 +02:00
@@ -432 +424 @@ static void block_remove(control_t* control, block_header_t* block)
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
- remove_free_block(control, block, fl, sl);
+ remove_free_block(block, fl, sl);
2016-05-27 12:22:28 +02:00
@@ -436 +428 @@ static void block_remove(control_t* control, block_header_t* block)
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
-static void block_insert(control_t* control, block_header_t* block)
+static void block_insert(block_header_t* block)
2016-05-27 12:22:28 +02:00
@@ -440 +432 @@ static void block_insert(control_t* control, block_header_t* block)
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
- insert_free_block(control, block, fl, sl);
+ insert_free_block(block, fl, sl);
2016-05-27 12:22:28 +02:00
@@ -481 +473 @@ static block_header_t* block_absorb(block_header_t* prev, block_header_t* block)
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
-static block_header_t* block_merge_prev(control_t* control, block_header_t* block)
+static block_header_t* block_merge_prev(block_header_t* block)
2016-05-27 12:22:28 +02:00
@@ -488 +480 @@ static block_header_t* block_merge_prev(control_t* control, block_header_t* bloc
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
- block_remove(control, prev);
+ block_remove(prev);
2016-05-27 12:22:28 +02:00
@@ -496 +488 @@ static block_header_t* block_merge_prev(control_t* control, block_header_t* bloc
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
-static block_header_t* block_merge_next(control_t* control, block_header_t* block)
+static block_header_t* block_merge_next(block_header_t* block)
2016-05-27 12:22:28 +02:00
@@ -504 +496 @@ static block_header_t* block_merge_next(control_t* control, block_header_t* bloc
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
- block_remove(control, next);
+ block_remove(next);
2016-05-27 12:22:28 +02:00
@@ -512 +504 @@ static block_header_t* block_merge_next(control_t* control, block_header_t* bloc
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
-static void block_trim_free(control_t* control, block_header_t* block, size_t size)
+static void block_trim_free(block_header_t* block, size_t size)
2016-05-27 12:22:28 +02:00
@@ -520 +512 @@ static void block_trim_free(control_t* control, block_header_t* block, size_t si
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
- block_insert(control, remaining_block);
+ block_insert(remaining_block);
2016-05-27 12:22:28 +02:00
@@ -525 +517 @@ static void block_trim_free(control_t* control, block_header_t* block, size_t si
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
-static void block_trim_used(control_t* control, block_header_t* block, size_t size)
+static void block_trim_used(block_header_t* block, size_t size)
2016-05-27 12:22:28 +02:00
@@ -534,2 +526,2 @@ static void block_trim_used(control_t* control, block_header_t* block, size_t si
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
- remaining_block = block_merge_next(control, remaining_block);
- block_insert(control, remaining_block);
+ remaining_block = block_merge_next(remaining_block);
+ block_insert(remaining_block);
2016-05-27 12:22:28 +02:00
@@ -539 +531 @@ static void block_trim_used(control_t* control, block_header_t* block, size_t si
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
-static block_header_t* block_trim_free_leading(control_t* control, block_header_t* block, size_t size)
+static block_header_t* block_trim_free_leading(block_header_t* block, size_t size)
2016-05-27 12:22:28 +02:00
@@ -549 +541 @@ static block_header_t* block_trim_free_leading(control_t* control, block_header_
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
- block_insert(control, block);
+ block_insert(block);
2016-05-27 12:22:28 +02:00
@@ -555 +547 @@ static block_header_t* block_trim_free_leading(control_t* control, block_header_
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
-static block_header_t* block_locate_free(control_t* control, size_t size)
+static block_header_t* block_locate_free(size_t size)
2016-05-27 12:22:28 +02:00
@@ -563 +555 @@ static block_header_t* block_locate_free(control_t* control, size_t size)
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
- block = search_suitable_block(control, &fl, &sl);
+ block = search_suitable_block(&fl, &sl);
2016-05-27 12:22:28 +02:00
@@ -569 +561 @@ static block_header_t* block_locate_free(control_t* control, size_t size)
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
- remove_free_block(control, block, fl, sl);
+ remove_free_block(block, fl, sl);
2016-05-27 12:22:28 +02:00
@@ -575 +567 @@ static block_header_t* block_locate_free(control_t* control, size_t size)
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
-static void* block_prepare_used(control_t* control, block_header_t* block, size_t size)
+static void* block_prepare_used(block_header_t* block, size_t size)
2016-05-27 12:22:28 +02:00
@@ -580 +572 @@ static void* block_prepare_used(control_t* control, block_header_t* block, size_
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
- block_trim_free(control, block, size);
+ block_trim_free(block, size);
2016-05-27 12:22:28 +02:00
@@ -588 +580 @@ static void* block_prepare_used(control_t* control, block_header_t* block, size_
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
-static void control_construct(control_t* control)
+static void control_construct(void)
2016-05-27 12:22:28 +02:00
@@ -605,0 +598 @@ static void control_construct(control_t* control)
+#ifdef DEVELHELP
@@ -608,0 +602 @@ static void control_construct(control_t* control)
+typedef void (*tlsf_walker)(void* ptr, size_t size, int used);
@@ -610 +604 @@ static void control_construct(control_t* control)
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
-typedef struct integrity_t
2016-05-27 12:22:28 +02:00
+static void default_walker(void* ptr, size_t size, int used)
@@ -612,20 +606,2 @@ typedef struct integrity_t
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
- int prev_status;
- int status;
-} integrity_t;
-
-#define tlsf_insist(x) { tlsf_assert(x); if (!(x)) { status--; } }
-
-static void integrity_walker(void* ptr, size_t size, int used, void* user)
-{
- block_header_t* block = block_from_ptr(ptr);
- integrity_t* integ = tlsf_cast(integrity_t*, user);
- const int this_prev_status = block_is_prev_free(block) ? 1 : 0;
- const int this_status = block_is_free(block) ? 1 : 0;
- const size_t this_block_size = block_size(block);
-
- int status = 0;
- tlsf_insist(integ->prev_status == this_prev_status && "prev status incorrect");
- tlsf_insist(size == this_block_size && "block size incorrect");
-
- integ->prev_status = this_status;
- integ->status += status;
2016-05-27 12:22:28 +02:00
+ printf("\tMemory @ %p is %s, size: %u (block: %p)\n", ptr, used ? "used" : "free",
+ (unsigned int)size, (void*) block_from_ptr(ptr));
@@ -634 +610 @@ static void integrity_walker(void* ptr, size_t size, int used, void* user)
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
-int tlsf_check(tlsf_t tlsf)
2016-05-27 12:22:28 +02:00
+void tlsf_walk_pool(void *pool)
@@ -636,7 +612 @@ int tlsf_check(tlsf_t tlsf)
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
- int i, j;
-
- control_t* control = tlsf_cast(control_t*, tlsf);
- int status = 0;
-
- /* Check that the free lists and bitmaps are accurate. */
- for (i = 0; i < FL_INDEX_COUNT; ++i)
2016-05-27 12:22:28 +02:00
+ if (!pool)
@@ -644,37 +614 @@ int tlsf_check(tlsf_t tlsf)
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
- for (j = 0; j < SL_INDEX_COUNT; ++j)
- {
- const int fl_map = control->fl_bitmap & (1 << i);
- const int sl_list = control->sl_bitmap[i];
- const int sl_map = sl_list & (1 << j);
- const block_header_t* block = control->blocks[i][j];
-
- /* Check that first- and second-level lists agree. */
- if (!fl_map)
- {
- tlsf_insist(!sl_map && "second-level map must be null");
- }
-
- if (!sl_map)
- {
- tlsf_insist(block == &control->block_null && "block list must be null");
- continue;
- }
-
- /* Check that there is at least one free block. */
- tlsf_insist(sl_list && "no free blocks in second-level map");
- tlsf_insist(block != &control->block_null && "block should not be null");
-
- while (block != &control->block_null)
- {
- int fli, sli;
- tlsf_insist(block_is_free(block) && "block should be free");
- tlsf_insist(!block_is_prev_free(block) && "blocks should have coalesced");
- tlsf_insist(!block_is_free(block_next(block)) && "blocks should have coalesced");
- tlsf_insist(block_is_prev_free(block_next(block)) && "block should be free");
- tlsf_insist(block_size(block) >= block_size_min && "block not minimum size");
-
- mapping_insert(block_size(block), &fli, &sli);
- tlsf_insist(fli == i && sli == j && "block size indexed in wrong list");
- block = block->next_free;
- }
- }
2016-05-27 12:22:28 +02:00
+ pool = default_pool;
@@ -682,15 +615,0 @@ int tlsf_check(tlsf_t tlsf)
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
-
- return status;
-}
-
-#undef tlsf_insist
-
-static void default_walker(void* ptr, size_t size, int used, void* user)
-{
- (void)user;
- printf("\t%p %s size: %x (%p)\n", ptr, used ? "used" : "free", (unsigned int)size, block_from_ptr(ptr));
-}
-
-void tlsf_walk_pool(pool_t pool, tlsf_walker walker, void* user)
-{
- tlsf_walker pool_walker = walker ? walker : default_walker;
2016-05-27 12:22:28 +02:00
@@ -702 +621 @@ void tlsf_walk_pool(pool_t pool, tlsf_walker walker, void* user)
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
- pool_walker(
2016-05-27 12:22:28 +02:00
+ default_walker(
@@ -705,2 +624 @@ void tlsf_walk_pool(pool_t pool, tlsf_walker walker, void* user)
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
- !block_is_free(block),
- user);
2016-05-27 12:22:28 +02:00
+ !block_is_free(block));
@@ -720,0 +639 @@ size_t tlsf_block_size(void* ptr)
+#endif
@@ -722,49 +641 @@ size_t tlsf_block_size(void* ptr)
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
-int tlsf_check_pool(pool_t pool)
-{
- /* Check that the blocks are physically correct. */
- integrity_t integ = { 0, 0 };
- tlsf_walk_pool(pool, integrity_walker, &integ);
-
- return integ.status;
-}
-
-/*
-** Size of the TLSF structures in a given memory block passed to
-** tlsf_create, equal to the size of a control_t
-*/
-size_t tlsf_size()
-{
- return sizeof(control_t);
-}
-
-size_t tlsf_align_size()
-{
- return ALIGN_SIZE;
-}
-
-size_t tlsf_block_size_min()
-{
- return block_size_min;
-}
-
-size_t tlsf_block_size_max()
-{
- return block_size_max;
-}
-
-/*
-** Overhead of the TLSF structures in a given memory block passes to
-** tlsf_add_pool, equal to the overhead of a free block and the
-** sentinel block.
-*/
-size_t tlsf_pool_overhead()
-{
- return 2 * block_header_overhead;
-}
-
-size_t tlsf_alloc_overhead()
-{
- return block_header_overhead;
-}
-
-pool_t tlsf_add_pool(tlsf_t tlsf, void* mem, size_t bytes)
+int tlsf_add_pool(void* mem, size_t bytes)
2016-05-27 12:22:28 +02:00
@@ -775 +646 @@ pool_t tlsf_add_pool(tlsf_t tlsf, void* mem, size_t bytes)
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
- const size_t pool_overhead = tlsf_pool_overhead();
+ const size_t pool_overhead = 2 * block_header_overhead;
2016-05-27 12:22:28 +02:00
@@ -787,6 +658 @@ pool_t tlsf_add_pool(tlsf_t tlsf, void* mem, size_t bytes)
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
-#if defined (TLSF_64BIT)
- printf("tlsf_add_pool: Memory size must be between 0x%x and 0x%x00 bytes.\n",
- (unsigned int)(pool_overhead + block_size_min),
- (unsigned int)((pool_overhead + block_size_max) / 256));
-#else
- printf("tlsf_add_pool: Memory size must be between %u and %u bytes.\n",
+ printf("tlsf_add_pool: Memory size must be between %u and %u bytes.\n",
2016-05-27 12:22:28 +02:00
@@ -795 +660,0 @@ pool_t tlsf_add_pool(tlsf_t tlsf, void* mem, size_t bytes)
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
-#endif
2016-05-27 12:22:28 +02:00
@@ -808 +673 @@ pool_t tlsf_add_pool(tlsf_t tlsf, void* mem, size_t bytes)
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
- block_insert(tlsf_cast(control_t*, tlsf), block);
+ block_insert(block);
2016-05-27 12:22:28 +02:00
@@ -816,13 +681,3 @@ pool_t tlsf_add_pool(tlsf_t tlsf, void* mem, size_t bytes)
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
- return mem;
-}
-
-void tlsf_remove_pool(tlsf_t tlsf, pool_t pool)
-{
- control_t* control = tlsf_cast(control_t*, tlsf);
- block_header_t* block = offset_to_block(pool, -(int)block_header_overhead);
-
- int fl = 0, sl = 0;
-
- tlsf_assert(block_is_free(block) && "block should be free");
- tlsf_assert(!block_is_free(block_next(block)) && "next block should not be free");
- tlsf_assert(block_size(block_next(block)) == 0 && "next block size should be zero");
2016-05-27 12:22:28 +02:00
+#ifdef DEVELHELP
+ default_pool = mem;
+#endif
@@ -830,2 +685 @@ void tlsf_remove_pool(tlsf_t tlsf, pool_t pool)
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
- mapping_insert(block_size(block), &fl, &sl);
- remove_free_block(control, block, fl, sl);
+ return 1;
2016-05-27 12:22:28 +02:00
@@ -838,2 +692 @@ void tlsf_remove_pool(tlsf_t tlsf, pool_t pool)
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
-#if _DEBUG
-int test_ffs_fls()
+void tlsf_create(void* mem)
2016-05-27 12:22:28 +02:00
@@ -841,34 +693,0 @@ int test_ffs_fls()
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
- /* Verify ffs/fls work properly. */
- int rv = 0;
- rv += (tlsf_ffs(0) == -1) ? 0 : 0x1;
- rv += (tlsf_fls(0) == -1) ? 0 : 0x2;
- rv += (tlsf_ffs(1) == 0) ? 0 : 0x4;
- rv += (tlsf_fls(1) == 0) ? 0 : 0x8;
- rv += (tlsf_ffs(0x80000000) == 31) ? 0 : 0x10;
- rv += (tlsf_ffs(0x80008000) == 15) ? 0 : 0x20;
- rv += (tlsf_fls(0x80000008) == 31) ? 0 : 0x40;
- rv += (tlsf_fls(0x7FFFFFFF) == 30) ? 0 : 0x80;
-
-#if defined (TLSF_64BIT)
- rv += (tlsf_fls_sizet(0x80000000) == 31) ? 0 : 0x100;
- rv += (tlsf_fls_sizet(0x100000000) == 32) ? 0 : 0x200;
- rv += (tlsf_fls_sizet(0xffffffffffffffff) == 63) ? 0 : 0x400;
-#endif
-
- if (rv)
- {
- printf("tlsf_create: %x ffs/fls tests failed!\n", rv);
- }
- return rv;
-}
-#endif
-
-tlsf_t tlsf_create(void* mem)
-{
-#if _DEBUG
- if (test_ffs_fls())
- {
- return 0;
- }
-#endif
-
2016-05-27 12:22:28 +02:00
@@ -879 +698 @@ tlsf_t tlsf_create(void* mem)
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
- return 0;
+ return;
2016-05-27 12:22:28 +02:00
@@ -882 +701 @@ tlsf_t tlsf_create(void* mem)
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
- control_construct(tlsf_cast(control_t*, mem));
2016-05-27 12:22:28 +02:00
+ control = tlsf_cast(control_t*, mem);
@@ -884,14 +703 @@ tlsf_t tlsf_create(void* mem)
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
- return tlsf_cast(tlsf_t, mem);
-}
-
-tlsf_t tlsf_create_with_pool(void* mem, size_t bytes)
-{
- tlsf_t tlsf = tlsf_create(mem);
- tlsf_add_pool(tlsf, (char*)mem + tlsf_size(), bytes - tlsf_size());
- return tlsf;
-}
-
-void tlsf_destroy(tlsf_t tlsf)
-{
- /* Nothing to do. */
- (void)tlsf;
+ control_construct();
2016-05-27 12:22:28 +02:00
@@ -900 +706 @@ void tlsf_destroy(tlsf_t tlsf)
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
-pool_t tlsf_get_pool(tlsf_t tlsf)
+void tlsf_create_with_pool(void* mem, size_t bytes)
2016-05-27 12:22:28 +02:00
@@ -902 +708,2 @@ pool_t tlsf_get_pool(tlsf_t tlsf)
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
- return tlsf_cast(pool_t, (char*)tlsf + tlsf_size());
+ tlsf_create(mem);
+ tlsf_add_pool((char*)mem + sizeof(control_t), bytes - sizeof(control_t));
2016-05-27 12:22:28 +02:00
@@ -905 +712 @@ pool_t tlsf_get_pool(tlsf_t tlsf)
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
-void* tlsf_malloc(tlsf_t tlsf, size_t size)
+void* tlsf_malloc(size_t size)
2016-05-27 12:22:28 +02:00
@@ -907 +713,0 @@ void* tlsf_malloc(tlsf_t tlsf, size_t size)
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
- control_t* control = tlsf_cast(control_t*, tlsf);
2016-05-27 12:22:28 +02:00
@@ -909,2 +715,2 @@ void* tlsf_malloc(tlsf_t tlsf, size_t size)
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
- block_header_t* block = block_locate_free(control, adjust);
- return block_prepare_used(control, block, adjust);
+ block_header_t* block = block_locate_free(adjust);
+ return block_prepare_used(block, adjust);
2016-05-27 12:22:28 +02:00
@@ -913 +719 @@ void* tlsf_malloc(tlsf_t tlsf, size_t size)
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
-void* tlsf_memalign(tlsf_t tlsf, size_t align, size_t size)
+void* tlsf_memalign(size_t align, size_t size)
2016-05-27 12:22:28 +02:00
@@ -915 +720,0 @@ void* tlsf_memalign(tlsf_t tlsf, size_t align, size_t size)
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
- control_t* control = tlsf_cast(control_t*, tlsf);
2016-05-27 12:22:28 +02:00
@@ -932 +737 @@ void* tlsf_memalign(tlsf_t tlsf, size_t align, size_t size)
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
- block_header_t* block = block_locate_free(control, aligned_size);
+ block_header_t* block = block_locate_free(aligned_size);
2016-05-27 12:22:28 +02:00
@@ -960 +765 @@ void* tlsf_memalign(tlsf_t tlsf, size_t align, size_t size)
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
- block = block_trim_free_leading(control, block, gap);
+ block = block_trim_free_leading(block, gap);
2016-05-27 12:22:28 +02:00
@@ -964 +769 @@ void* tlsf_memalign(tlsf_t tlsf, size_t align, size_t size)
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
- return block_prepare_used(control, block, adjust);
+ return block_prepare_used(block, adjust);
2016-05-27 12:22:28 +02:00
@@ -967 +772 @@ void* tlsf_memalign(tlsf_t tlsf, size_t align, size_t size)
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
-void tlsf_free(tlsf_t tlsf, void* ptr)
+void tlsf_free(void* ptr)
2016-05-27 12:22:28 +02:00
@@ -972 +776,0 @@ void tlsf_free(tlsf_t tlsf, void* ptr)
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
- control_t* control = tlsf_cast(control_t*, tlsf);
2016-05-27 12:22:28 +02:00
@@ -976,3 +780,3 @@ void tlsf_free(tlsf_t tlsf, void* ptr)
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
- block = block_merge_prev(control, block);
- block = block_merge_next(control, block);
- block_insert(control, block);
+ block = block_merge_prev(block);
+ block = block_merge_next(block);
+ block_insert(block);
2016-05-27 12:22:28 +02:00
@@ -995 +799 @@ void tlsf_free(tlsf_t tlsf, void* ptr)
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
-void* tlsf_realloc(tlsf_t tlsf, void* ptr, size_t size)
+void* tlsf_realloc(void* ptr, size_t size)
2016-05-27 12:22:28 +02:00
@@ -997 +800,0 @@ void* tlsf_realloc(tlsf_t tlsf, void* ptr, size_t size)
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
- control_t* control = tlsf_cast(control_t*, tlsf);
2016-05-27 12:22:28 +02:00
@@ -1003 +806 @@ void* tlsf_realloc(tlsf_t tlsf, void* ptr, size_t size)
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
- tlsf_free(tlsf, ptr);
+ tlsf_free(ptr);
2016-05-27 12:22:28 +02:00
@@ -1008 +811 @@ void* tlsf_realloc(tlsf_t tlsf, void* ptr, size_t size)
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
- p = tlsf_malloc(tlsf, size);
+ p = tlsf_malloc(size);
2016-05-27 12:22:28 +02:00
@@ -1027 +830 @@ void* tlsf_realloc(tlsf_t tlsf, void* ptr, size_t size)
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
- p = tlsf_malloc(tlsf, size);
+ p = tlsf_malloc(size);
2016-05-27 12:22:28 +02:00
@@ -1032 +835 @@ void* tlsf_realloc(tlsf_t tlsf, void* ptr, size_t size)
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
- tlsf_free(tlsf, ptr);
+ tlsf_free(ptr);
2016-05-27 12:22:28 +02:00
@@ -1040 +843 @@ void* tlsf_realloc(tlsf_t tlsf, void* ptr, size_t size)
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
- block_merge_next(control, block);
+ block_merge_next(block);
2016-05-27 12:22:28 +02:00
@@ -1045 +848 @@ void* tlsf_realloc(tlsf_t tlsf, void* ptr, size_t size)
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
- block_trim_used(control, block, adjust);
+ block_trim_used(block, adjust);
diff --git tlsf.h tlsf.h
2016-05-27 12:22:28 +02:00
index 72496a1..6c945e5 100644
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
--- tlsf.h
+++ tlsf.h
@@ -25,5 +24,0 @@ extern "C" {
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
-/* tlsf_t: a TLSF structure. Can contain 1 to N pools. */
-/* pool_t: a block of memory that TLSF can manage. */
-typedef void* tlsf_t;
-typedef void* pool_t;
-
@@ -31,4 +26,2 @@ typedef void* pool_t;
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
-tlsf_t tlsf_create(void* mem);
-tlsf_t tlsf_create_with_pool(void* mem, size_t bytes);
-void tlsf_destroy(tlsf_t tlsf);
-pool_t tlsf_get_pool(tlsf_t tlsf);
+void tlsf_create(void* mem);
+void tlsf_create_with_pool(void* mem, size_t bytes);
@@ -37,2 +30 @@ pool_t tlsf_get_pool(tlsf_t tlsf);
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
-pool_t tlsf_add_pool(tlsf_t tlsf, void* mem, size_t bytes);
-void tlsf_remove_pool(tlsf_t tlsf, pool_t pool);
+int tlsf_add_pool(void* mem, size_t bytes);
2016-05-27 12:22:28 +02:00
@@ -41,7 +33,4 @@ void tlsf_remove_pool(tlsf_t tlsf, pool_t pool);
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
-void* tlsf_malloc(tlsf_t tlsf, size_t bytes);
-void* tlsf_memalign(tlsf_t tlsf, size_t align, size_t bytes);
-void* tlsf_realloc(tlsf_t tlsf, void* ptr, size_t size);
-void tlsf_free(tlsf_t tlsf, void* ptr);
-
-/* Returns internal block size, not original request size */
-size_t tlsf_block_size(void* ptr);
2016-05-27 12:22:28 +02:00
+void* tlsf_malloc(size_t bytes);
+void* tlsf_memalign(size_t align, size_t bytes);
+void* tlsf_realloc(void* ptr, size_t size);
+void tlsf_free(void* ptr);
@@ -49,14 +38,3 @@ size_t tlsf_block_size(void* ptr);
Add TLSF (two level segregated fit) PKG This is my second take on #669, because I was asked to separate it from #764. This change adds a malloc implementation as a PKG, which uses *TLSF* (two level segregated fit). The patch file removes the 64bit capatibilities, debug functions, and the option to have multiple "control blocks" (a control block holds multiple memory pools). It wraps `malloc()` and friends in `disableIRQ() … restoreIRQ()`. The implemention does not support 16bit platforms, yet, but probably only some constants would need fixing. I limited the maximum size of a memory pool to 2**30 bytes = 1GB. This PKG is not meant to be used by applicitions directly, but by the boards. The board's initialition code needs to call `int tlsf_add_pool(void *mem, size_t bytes)` for every free memory region it has. If the board in using newlib, then this call needs to happen before the first call to `puts`, `printf`, and friends, because newlib allocates the control data IO streams (stdin, stdout, stderr) on the heap. Adding a small (e.g. 1kB) pool before proper board initialization would be a possible solution. Please read the additional information in the website of the implementator, http://tlsf.baisoku.org/: > TLSF (two level segregated fit) is a relatively new memory allocator designed for embedded systems. It boasts constant time O(1) malloc/free response time and a 4-byte block overhead. Though it typically is slightly slower than other allocators such as dlmalloc, it has no worst-case behavior. > The original implementation, which comes alongside the white paper, is distributed under the GNU GPL/LGPL. The code found here is an original implementation, released into the public domain, therefore is not subject to any licensing restrictions. > Features: - O(1) cost for malloc, free, realloc, memalign - Extremely low overhead per allocation (4 bytes) - Low overhead per pool (~3kB) - Low fragmentation - Compiles to only a few kB of code and data > Caveats: - Currently, assumes architecture can make 4-byte aligned accesses - Not designed to be thread safe; the user must provide this > Known Issues: Due to the internal block structure size and the implementation details of tlsf_memalign, there is worst-case behavior when requesting small (<16 byte) blocks aligned to 8-byte boundaries. Overuse of memalign will generally increase fragmentation, but this particular case will leave lots of unusable "holes" in the heap. The solution would be to internally align all blocks to 8 bytes, but this will require significantl changes to the implementation. Contact me if you are interested.
2014-05-20 03:17:09 +02:00
-/* Overheads/limits of internal structures. */
-size_t tlsf_size();
-size_t tlsf_align_size();
-size_t tlsf_block_size_min();
-size_t tlsf_block_size_max();
-size_t tlsf_pool_overhead();
-size_t tlsf_alloc_overhead();
-
-/* Debugging. */
-typedef void (*tlsf_walker)(void* ptr, size_t size, int used, void* user);
-void tlsf_walk_pool(pool_t pool, tlsf_walker walker, void* user);
-/* Returns nonzero if any internal consistency check fails. */
-int tlsf_check(tlsf_t tlsf);
-int tlsf_check_pool(pool_t pool);
2016-05-27 12:22:28 +02:00
+#ifdef DEVELHELP
+void tlsf_walk_pool(void *pool);
+#endif