Skip to content

Commit b5c2ff9

Browse files
dcpleungnashif
authored andcommitted
kernel: add kconfig CONFIG_KERNEL_MEM_POOL
Adds a kconfig CONFIG_KERNEL_MEM_POOL to decide whether kernel memory pool related code is compiled. This option can be disabled to shrink code size. If k_heap is not being used at all, kheap.c will also not be compiled, resulting in further smaller code size. Signed-off-by: Daniel Leung <[email protected]>
1 parent 4f106c3 commit b5c2ff9

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

kernel/CMakeLists.txt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ add_library(kernel
1111
kheap.c
1212
mailbox.c
1313
mem_slab.c
14-
mempool.c
1514
msg_q.c
1615
mutex.c
1716
pipes.c
@@ -42,9 +41,13 @@ target_sources_ifdef(CONFIG_ATOMIC_OPERATIONS_C kernel PRIVATE atomic_c.c)
4241
target_sources_ifdef(CONFIG_MMU kernel PRIVATE mmu.c)
4342
target_sources_ifdef(CONFIG_POLL kernel PRIVATE poll.c)
4443

45-
if(${CONFIG_MEM_POOL_HEAP_BACKEND})
46-
else()
47-
target_sources(kernel PRIVATE mempool_sys.c)
44+
if(${CONFIG_KERNEL_MEM_POOL})
45+
target_sources(kernel PRIVATE mempool.c)
46+
47+
if(${CONFIG_MEM_POOL_HEAP_BACKEND})
48+
else()
49+
target_sources(kernel PRIVATE mempool_sys.c)
50+
endif()
4851
endif()
4952

5053
# The last 2 files inside the target_sources_ifdef should be

kernel/Kconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,16 @@ config NUM_PIPE_ASYNC_MSGS
444444
Setting this option to 0 disables support for asynchronous
445445
pipe messages.
446446

447+
config KERNEL_MEM_POOL
448+
bool "Use Kernel Memory Pool"
449+
default y
450+
help
451+
Enable the use of kernel memory pool.
452+
453+
Say y if unsure.
454+
455+
if KERNEL_MEM_POOL
456+
447457
config MEM_POOL_HEAP_BACKEND
448458
bool "Use k_heap as the backend for k_mem_pool"
449459
default y
@@ -472,6 +482,9 @@ config HEAP_MEM_POOL_MIN_SIZE
472482
This option specifies the size of the smallest block in the pool.
473483
Option must be a power of 2 and lower than or equal to the size
474484
of the entire pool.
485+
486+
endif # KERNEL_MEM_POOL
487+
475488
endmenu
476489

477490
config ARCH_HAS_CUSTOM_SWAP_TO_MAIN

0 commit comments

Comments
 (0)