zephyr/include
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
..
app_memory kernel: fix k_mem_partition data types 2019-12-12 14:48:42 -08:00
arch arch: arc: optimize the arc v2 interrupt unit driver 2020-04-06 11:17:38 -07:00
audio doc: reference: Add pages for audio 2020-03-18 11:47:24 +01:00
bluetooth Bluetooth: host: Fix scan filter_dup parameter on big endian systems 2020-04-08 17:58:53 +03:00
canbus doc: doxygen: add missing groups and categorise 2020-03-14 13:01:03 -04:00
cmsis_rtos_v1
cmsis_rtos_v2 global: Remove leading/trailing blank lines in files 2019-12-11 19:17:27 +01:00
console console: Remove deprecated function console_register_line_input 2019-09-18 19:14:25 -05:00
crypto docs: crypto: crypto API documentation 2020-03-14 13:01:03 -04:00
data treewide: avoid address-of-compound-literal idiom in headers 2019-12-18 21:53:17 +01:00
debug include: debug: remove old stack functions 2020-03-14 13:10:19 -04:00
devicetree doc: devicetree: change doxygen groups 2020-04-13 22:38:13 -04:00
dfu DFU: add init function with area id as parameter 2020-03-10 15:07:27 +02:00
disk doc: reference: Add disk access API 2020-03-18 11:47:24 +01:00
display
drivers sensor: bq274xx: Add BQ27421 driver 2020-04-13 11:50:41 -05:00
dt-bindings drivers: dma: i2s: stm32: I2S Master DMA support 2020-04-09 19:57:08 +02:00
fs fs: littlefs: force alignment for buffers 2020-04-11 15:33:35 -04:00
linker net: Remove leftovers for obsolete net stacks shell command 2020-04-01 10:41:58 -04:00
logging logging: Fix LOG_LEVEL_SET macro 2020-03-26 08:04:02 -04:00
mgmt subsys/mgmt: Enabling mynewt-core version of tinycbor 2020-03-17 11:58:18 +01:00
net net: mqtt: Refactor because of timeout overhaul 2020-04-09 21:58:42 +03:00
posix pthread: add setname/getname glibc extensions 2020-03-10 15:15:34 +02:00
power power: add system power management direct force mode. 2020-01-24 21:37:40 -05:00
random doc: doxygen: add missing groups and categorise 2020-03-14 13:01:03 -04:00
settings doc: doxygen: add missing groups and categorise 2020-03-14 13:01:03 -04:00
shell global: Replace BUILD_ASSERT_MSG() with BUILD_ASSERT() 2020-03-31 07:18:06 +02:00
stats
storage doc: fix flash_area_get_sectors doc 2019-10-25 16:40:12 -05:00
sys lib/os: Add sys_heap, a new/simpler/faster memory allocator 2020-04-14 10:05:55 -07:00
toolchain toolchain: Fix warning about too few arguments on BUILD_ASSERT() 2020-04-11 11:09:20 -04:00
tracing tracing: move headers under include/tracing 2020-02-07 15:58:05 -05:00
usb usb: make usb descriptor power options configurable 2019-12-20 19:46:16 -05:00
zephyr include: Remove compat include headers 2019-12-10 08:39:37 -05:00
cache.h
device.h device: Provide a dummy macro for device_pm_control_nop on disabled PM 2020-03-27 14:48:30 +02:00
devicetree.h doc: devicetree: change doxygen groups 2020-04-13 22:38:13 -04:00
exc_handle.h kernel: rename z_arch_ to arch_ 2019-11-07 15:21:46 -08:00
fatal.h doc: fix misspelling in API doxygen comments 2019-10-29 06:00:14 +01:00
generated_dts_board.h dts: Add include/generated_dts_board.h for backwards compatibility 2020-01-17 17:57:59 +01:00
init.h kernel: add sys init level for SMP 2020-03-25 19:07:28 -04:00
irq_nextlevel.h include: respect line limit in api pointer initialization 2019-12-16 21:14:08 -05:00
irq_offload.h kernel: sychronize irq_offload() access 2019-11-08 15:16:43 -08:00
irq.h arch: isr: Update z_isr_install for multi-level interrupts 2020-04-09 13:12:24 -07:00
kernel_includes.h headers: Refactor kernel and arch headers. 2019-11-06 16:07:32 -08:00
kernel_structs.h kernel/userspace: Move syscall_frame field to thread struct 2020-02-08 08:51:04 -05:00
kernel_version.h
kernel.h kernel: remove all old requirement tags 2020-04-13 14:11:01 +02:00
ptp_clock.h scripts: Replace hard-coded subsystem list with __subsystem annotations. 2020-03-11 17:13:39 +02:00
sched_priq.h
shared_irq.h include: respect line limit in api pointer initialization 2019-12-16 21:14:08 -05:00
spinlock.h global: Replace BUILD_ASSERT_MSG() with BUILD_ASSERT() 2020-03-31 07:18:06 +02:00
sw_isr_table.h
sys_clock.h kernel/timeout: Doc cleanup 2020-03-31 19:40:47 -04:00
syscall_handler.h kernel: rename struct _k_object 2020-03-17 20:11:27 +02:00
syscall.h global: Remove leading/trailing blank lines in files 2019-12-11 19:17:27 +01:00
timeout_q.h kernel/timeout: Add timeout remaining/expires APIs 2020-03-31 19:40:47 -04:00
toolchain.h toolchain: Fix for off-tree toolchains 2019-10-08 17:09:23 -04:00
wait_q.h headers: Refactor kernel and arch headers. 2019-11-06 16:07:32 -08:00
zephyr.h