zephyr/lib/os
Andy Ross aa4227754c lib/os: Add sys_heap, a new/simpler/faster memory allocator
The existing mem_pool implementation has been an endless source of
frustration.  It's had alignment bugs, it's had racy behavior.  It's
never been particularly fast.  It's outrageously complicated to
configure statically.  And while its fragmentation resistance and
overhead on small blocks is good, it's space efficiencey has always
been very poor due to the four-way buddy scheme.

This patch introduces sys_heap.  It's a more or less conventional
segregated fit allocator with power-of-two buckets.  It doesn't expose
its level structure to the user at all, simply taking an arbitrarily
aligned pointer to memory.  It stores all metadata inside the heap
region.  It allocates and frees by simple pointer and not block ID.
Static initialization is trivial, and runtime initialization is only a
few cycles to format and add one block to a list header.

It has excellent space efficiency.  Chunks can be split arbitrarily in
8 byte units.  Overhead is only four bytes per allocated chunk (eight
bytes for heaps >256kb or on 64 bit systems), plus a log2-sized array
of 2-word bucket headers.  No coarse alignment restrictions on blocks,
they can be split and merged (in units of 8 bytes) arbitrarily.

It has good fragmentation resistance.  Freed blocks are always
immediately merged with adjacent free blocks.  Allocations are
attempted from a sample of the smallest bucket that might fit, falling
back rapidly to the smallest block guaranteed to fit.  Split memory
remaining in the chunk is always returned immediately to the heap for
other allocation.

It has excellent performance with firmly bounded runtime.  All
operations are constant time (though there is a search of the smallest
bucket that has a compile-time-configurable upper bound, setting this
to extreme values results in an effectively linear search of the
list), objectively fast (about a hundred instructions) and amenable to
locked operation.  No more need for fragile lock relaxation trickery.

It also contains an extensive validation and stress test framework,
something that was sorely lacking in the previous implementation.

Note that sys_heap is not a compatible API with sys_mem_pool and
k_mem_pool.  Partial wrappers for those (now-) legacy APIs will appear
later and a deprecation strategy needs to be chosen.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-04-14 10:05:55 -07:00
..
assert.c assert: Completely remove file info and condition expression 2020-01-13 13:59:55 +01:00
base64.c global: Remove leading/trailing blank lines in files 2019-12-11 19:17:27 +01:00
CMakeLists.txt lib/os: Add sys_heap, a new/simpler/faster memory allocator 2020-04-14 10:05:55 -07:00
crc7_sw.c cleanup: include/: move crc.h to sys/crc.h 2019-06-27 22:55:49 -04:00
crc8_sw.c lib: os: fix signed and unsigend comparison warnings 2020-04-03 18:06:59 -04:00
crc16_sw.c cleanup: include/: move crc.h to sys/crc.h 2019-06-27 22:55:49 -04:00
crc32_sw.c cleanup: include/: move crc.h to sys/crc.h 2019-06-27 22:55:49 -04:00
dec.c global: Remove leading/trailing blank lines in files 2019-12-11 19:17:27 +01:00
fdtable.c cleanup: include/: move misc/speculation.h to sys/speculation.h 2019-06-27 22:55:49 -04:00
heap-validate.c lib/os: Add sys_heap, a new/simpler/faster memory allocator 2020-04-14 10:05:55 -07:00
heap.c lib/os: Add sys_heap, a new/simpler/faster memory allocator 2020-04-14 10:05:55 -07:00
heap.h lib/os: Add sys_heap, a new/simpler/faster memory allocator 2020-04-14 10:05:55 -07:00
hex.c kernel: lib: Add convert functions for hex strings and binary arrays 2019-07-16 12:44:18 +02:00
json.c cleanup: include/: move misc/util.h to sys/util.h 2019-06-27 22:55:49 -04:00
Kconfig lib/os: Add sys_heap, a new/simpler/faster memory allocator 2020-04-14 10:05:55 -07:00
mempool.c lib: os: fix signed and unsigend comparison warnings 2020-04-03 18:06:59 -04:00
mutex.c kernel/timeout: Make timeout arguments an opaque type 2020-03-31 19:40:47 -04:00
notify.c sys: add generic asynchronous notification infrastructure 2020-04-06 16:41:41 +02:00
onoff.c sys: onoff: generalize and shorten API 2020-04-06 16:41:41 +02:00
printk.c lib: os: fix signed and unsigend comparison warnings 2020-04-03 18:06:59 -04:00
rb.c cleanup: include/: move misc/rb.h to sys/rb.h 2019-06-27 22:55:49 -04:00
ring_buffer.c cleanup: include/: move ring_buffer.h to sys/ring_buffer.h 2019-06-27 22:55:49 -04:00
sem.c kernel/timeout: Make timeout arguments an opaque type 2020-03-31 19:40:47 -04:00
thread_entry.c lib: os: remove dead code 2019-06-18 09:08:01 -04:00
timeutil.c lib/timeutil: avoid implementation-defined behavior 2019-09-19 20:49:51 -04:00
work_q.c global: Remove leading/trailing blank lines in files 2019-12-11 19:17:27 +01:00