From b87920bf3c789ad4eeebb749d9a06ae72f15d589 Mon Sep 17 00:00:00 2001 From: Pawel Dunaj Date: Mon, 11 Mar 2019 17:28:23 +0100 Subject: [PATCH] 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 --- kernel/Kconfig | 9 +++++++++ kernel/mempool.c | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/kernel/Kconfig b/kernel/Kconfig index bcecfe735a06..513f394733da 100644 --- a/kernel/Kconfig +++ b/kernel/Kconfig @@ -485,6 +485,15 @@ config HEAP_MEM_POOL_SIZE dynamically allocating memory using k_malloc(). Supported values are: 256, 1024, 4096, and 16384. A size of zero means that no heap memory pool is defined. + +config HEAP_MEM_POOL_MIN_SIZE + int "The smallest blocks in the heap memory pool (in bytes)" + depends on HEAP_MEM_POOL_SIZE != 0 + default 64 + help + This option specifies the size of the smallest block in the pool. + Option must be a power of 2 and lower than or equal to the size + of the entire pool. endmenu config ARCH_HAS_CUSTOM_SWAP_TO_MAIN diff --git a/kernel/mempool.c b/kernel/mempool.c index 013947ea24f3..3c8c7c7659d1 100644 --- a/kernel/mempool.c +++ b/kernel/mempool.c @@ -179,7 +179,8 @@ void k_free(void *ptr) * that has the address of the associated memory pool struct. */ -K_MEM_POOL_DEFINE(_heap_mem_pool, 64, CONFIG_HEAP_MEM_POOL_SIZE, 1, 4); +K_MEM_POOL_DEFINE(_heap_mem_pool, CONFIG_HEAP_MEM_POOL_MIN_SIZE, + CONFIG_HEAP_MEM_POOL_SIZE, 1, 4); #define _HEAP_MEM_POOL (&_heap_mem_pool) void *k_malloc(size_t size)