Skip to content

Commit

Permalink
kernel: Make heap smallest object size configurable
Browse files Browse the repository at this point in the history
Allow application to chose the size of the smallest object taken from
the heap.

Signed-off-by: Pawel Dunaj <pawel.dunaj@nordicsemi.no>
  • Loading branch information
pdunaj authored and carlescufi committed Mar 12, 2019
1 parent 0590fd5 commit b87920b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
9 changes: 9 additions & 0 deletions kernel/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion kernel/mempool.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b87920b

Please sign in to comment.