1# Copyright (c) 2021 Intel Corporation
2#
3# SPDX-License-Identifier: Apache-2.0
4
5menu "Heap and Memory Allocation"
6
7config SYS_HEAP_VALIDATE
8	bool "Internal heap validity checking"
9	help
10	  The sys_heap implementation is instrumented for extensive
11	  internal validation.  Leave this off by default, unless
12	  modifying the heap code or (maybe) when running in
13	  environments that require sensitive detection of memory
14	  corruption.
15
16config SYS_HEAP_ALLOC_LOOPS
17	int "Number of tries in the inner heap allocation loop"
18	default 3
19	help
20	  The sys_heap allocator bounds the number of tries from the
21	  smallest chunk level (the one that might not fit the
22	  requested allocation) to maintain constant time performance.
23	  Setting this to a high level will cause the heap to return
24	  more successful allocations in situations of high
25	  fragmentation, at the cost of potentially significant
26	  (linear time) searching of the free list.  The default is
27	  three, which results in an allocator with good statistical
28	  properties ("most" allocations that fit will succeed) but
29	  keeps the maximum runtime at a tight bound so that the heap
30	  is useful in locked or ISR contexts.
31
32config SYS_HEAP_RUNTIME_STATS
33	bool "System heap runtime statistics"
34	help
35	  Gather system heap runtime statistics.
36
37config SYS_HEAP_LISTENER
38	bool "sys_heap event notifications"
39	select HEAP_LISTENER
40	help
41	  This allows application to listen for sys_heap events,
42	  such as memory allocation and de-allocation.
43
44config HEAP_LISTENER
45	bool
46	help
47	  Hidden option to enable API for registering and notifying
48	  listeners of certain events related to a heap usage,
49	  such as the heap resize.
50
51choice
52	prompt "Supported heap sizes"
53	depends on !64BIT
54	default SYS_HEAP_SMALL_ONLY if (SRAM_SIZE <= 256)
55	default SYS_HEAP_AUTO
56	help
57	  Heaps using reduced-size chunk headers can accommodate so called
58	  "small" heaps with a total size of 262136 bytes or less.
59
60	  Heaps using full-size chunk headers can have a total size up to
61	  16383 megabytes. The overhead is of course bigger.
62
63	  On 32-bit system the tradeoff is selectable between:
64
65	  - "small" heaps with low memory and runtime overhead;
66
67	  - "big" heaps with bigger memory overhead even for small heaps;
68
69	  - "auto" providing optimal memory overhead in all cases but with
70	    a higher runtime overhead and somewhat bigger code footprint.
71
72	  On 64-bit systems the "big" chunk header size conveniently provides
73	  the needed alignment on returned memory allocations. Small chunk
74	  headers would require alignment padding up to the big header size
75	  anyway so "big" heap is the only option in that case.
76
77config SYS_HEAP_SMALL_ONLY
78	bool "Support for small heaps only"
79	help
80	  Select this to optimize the code and memory usage if all your
81	  heaps are 262136 bytes or less.
82
83config SYS_HEAP_BIG_ONLY
84	bool "Support for big heaps only"
85	help
86	  Select this to optimize the code for big heaps only. This can
87	  accommodate any heap size but memory usage won't be as
88	  efficient with small sized heaps.
89
90config SYS_HEAP_AUTO
91	bool "Support for both small and big heaps at run time"
92	help
93	  This option optimizes memory usage for each heap according to
94	  their size albeit with some overhead in code size and execution.
95
96endchoice
97
98config SHARED_MULTI_HEAP
99	bool "Shared multi-heap manager"
100	help
101	  Enable support for a shared multi-heap manager that uses the
102	  multi-heap allocator to manage a set of reserved memory regions with
103	  different capabilities / attributes (cacheable, non-cacheable,
104	  etc...) defined in the DT.
105
106config SYS_MEM_BLOCKS
107	bool "(Yet Another) Memory Blocks Allocator"
108	help
109	  This enables support for memory block allocator where:
110	  () All memory blocks have a single fixed size.
111	  () Multiple blocks can be allocated or freed at the same time.
112	  () A group of blocks allocated together may not be contiguous.
113	     This is useful for operations such as scatter-gather DMA
114	     transfers.
115	  () Bookkeeping of allocated blocks is done outside of
116	     the associated buffer (unlike memory slab). This allows
117	     the buffer to reside in memory regions where these can be
118	     powered down to conserve energy.
119
120config SYS_MEM_BLOCKS_LISTENER
121	bool "Memory Blocks Allocator event notifications"
122	depends on SYS_MEM_BLOCKS
123	select HEAP_LISTENER
124	help
125	  This allows application to listen for memory blocks allocator
126	  events, such as memory allocation and de-allocation.
127
128config SYS_MEM_BLOCKS_RUNTIME_STATS
129	bool "Memory blocks runtime statistics"
130	depends on SYS_MEM_BLOCKS
131	help
132	  This option enables the tracking and reporting of the memory
133	  blocks statistics related to the current and maximum number
134	  of allocations in a given memory block.
135
136endmenu
137