Skip to content

Commit b87920b

Browse files
pdunajcarlescufi
authored andcommitted
kernel: Make heap smallest object size configurable
Allow application to chose the size of the smallest object taken from the heap. Signed-off-by: Pawel Dunaj <pawel.dunaj@nordicsemi.no>
1 parent 0590fd5 commit b87920b

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

kernel/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,15 @@ config HEAP_MEM_POOL_SIZE
485485
dynamically allocating memory using k_malloc(). Supported values
486486
are: 256, 1024, 4096, and 16384. A size of zero means that no
487487
heap memory pool is defined.
488+
489+
config HEAP_MEM_POOL_MIN_SIZE
490+
int "The smallest blocks in the heap memory pool (in bytes)"
491+
depends on HEAP_MEM_POOL_SIZE != 0
492+
default 64
493+
help
494+
This option specifies the size of the smallest block in the pool.
495+
Option must be a power of 2 and lower than or equal to the size
496+
of the entire pool.
488497
endmenu
489498

490499
config ARCH_HAS_CUSTOM_SWAP_TO_MAIN

kernel/mempool.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ void k_free(void *ptr)
179179
* that has the address of the associated memory pool struct.
180180
*/
181181

182-
K_MEM_POOL_DEFINE(_heap_mem_pool, 64, CONFIG_HEAP_MEM_POOL_SIZE, 1, 4);
182+
K_MEM_POOL_DEFINE(_heap_mem_pool, CONFIG_HEAP_MEM_POOL_MIN_SIZE,
183+
CONFIG_HEAP_MEM_POOL_SIZE, 1, 4);
183184
#define _HEAP_MEM_POOL (&_heap_mem_pool)
184185

185186
void *k_malloc(size_t size)

0 commit comments

Comments
 (0)