| 1 | # tlsf |
| 2 | Two-Level Segregated Fit memory allocator implementation. |
| 3 | Written by Matthew Conte (matt@baisoku.org). |
| 4 | Released under the BSD license. |
| 5 | |
| 6 | Features |
| 7 | -------- |
| 8 | * O(1) cost for malloc, free, realloc, memalign |
| 9 | * Extremely low overhead per allocation (4 bytes) |
| 10 | * Low overhead per TLSF management of pools (~3kB) |
| 11 | * Low fragmentation |
| 12 | * Compiles to only a few kB of code and data |
| 13 | * Support for adding and removing memory pool regions on the fly |
| 14 | |
| 15 | Caveats |
| 16 | ------- |
| 17 | * Currently, assumes architecture can make 4-byte aligned accesses |
| 18 | * Not designed to be thread safe; the user must provide this |
| 19 | |
| 20 | Notes |
| 21 | ----- |
| 22 | This code was based on the TLSF 1.4 spec and documentation found at: |
| 23 | |
| 24 | http://www.gii.upv.es/tlsf/main/docs |
| 25 | |
| 26 | It also leverages the TLSF 2.0 improvement to shrink the per-block overhead from 8 to 4 bytes. |
| 27 | |
| 28 | History |
| 29 | ------- |
| 30 | 2016/04/10 - v3.1 |
| 31 | * Code moved to github |
| 32 | * tlsfbits.h rolled into tlsf.c |
| 33 | * License changed to BSD |
| 34 | |
| 35 | 2014/02/08 - v3.0 |
| 36 | * This version is based on improvements from 3DInteractive GmbH |
| 37 | * Interface changed to allow more than one memory pool |
| 38 | * Separated pool handling from control structure (adding, removing, debugging) |
| 39 | * Control structure and pools can still be constructed in the same memory block |
| 40 | * Memory blocks for control structure and pools are checked for alignment |
| 41 | * Added functions to retrieve control structure size, alignment size, min and max block size, overhead of pool structure, and overhead of a single allocation |
| 42 | * Minimal Pool size is tlsf_block_size_min() + tlsf_pool_overhead() |
| 43 | * Pool must be empty when it is removed, in order to allow O(1) removal |
| 44 | |
| 45 | 2011/10/20 - v2.0 |
| 46 | * 64-bit support |
| 47 | * More compiler intrinsics for ffs/fls |
| 48 | * ffs/fls verification during TLSF creation in debug builds |
| 49 | |
| 50 | 2008/04/04 - v1.9 |
| 51 | * Add tlsf_heap_check, a heap integrity check |
| 52 | * Support a predefined tlsf_assert macro |
| 53 | * Fix realloc case where block should shrink; if adjacent block is in use, execution would go down the slow path |
| 54 | |
| 55 | 2007/02/08 - v1.8 |
| 56 | * Fix for unnecessary reallocation in tlsf_realloc |
| 57 | |
| 58 | 2007/02/03 - v1.7 |
| 59 | * tlsf_heap_walk takes a callback |
| 60 | * tlsf_realloc now returns NULL on failure |
| 61 | * tlsf_memalign optimization for 4-byte alignment |
| 62 | * Usage of size_t where appropriate |
| 63 | |
| 64 | 2006/11/21 - v1.6 |
| 65 | * ffs/fls broken out into tlsfbits.h |
| 66 | * tlsf_overhead queries per-pool overhead |
| 67 | |
| 68 | 2006/11/07 - v1.5 |
| 69 | * Smart realloc implementation |
| 70 | * Smart memalign implementation |
| 71 | |
| 72 | 2006/10/11 - v1.4 |
| 73 | * Add some ffs/fls implementations |
| 74 | * Minor code footprint reduction |
| 75 | |
| 76 | 2006/09/14 - v1.3 |
| 77 | * Profiling indicates heavy use of blocks of size 1-128, so implement small block handling |
| 78 | * Reduce pool overhead by about 1kb |
| 79 | * Reduce minimum block size from 32 to 12 bytes |
| 80 | * Realloc bug fix |
| 81 | |
| 82 | 2006/09/09 - v1.2 |
| 83 | * Add tlsf_block_size |
| 84 | * Static assertion mechanism for invariants |
| 85 | * Minor bugfixes |
| 86 | |
| 87 | 2006/09/01 - v1.1 |
| 88 | * Add tlsf_realloc |
| 89 | * Add tlsf_walk_heap |
| 90 | |
| 91 | 2006/08/25 - v1.0 |
| 92 | * First release |