Repository navigation
!mm/mempool: replace the initial chunk size of #22540 with mm_pool_config_s - #22718
Open
huojianchaoyy wants to merge 5 commits into
Open
huojianchaoyy wants to merge 5 commits into
huojianchaoyy wants to merge 5 commits into
Conversation
This reverts commit fe9ca94. That commit lets the filesystem heap choose the size of its first mempool chunk through the new mm_initialize_pool_initial() and mempool_multiple_init_initial(). The commits that follow add the same option in the form that the next memory manager changes build on: an init_chunksize member of the multiple mempool and of the heap pool configuration, set by CONFIG_MM_HEAP_MEMPOOL_INIT_CHUNK_SIZE and, for the filesystem heap, CONFIG_FS_HEAP_MEMPOOL_INIT_CHUNK_SIZE. Keeping both would leave two ways to set the same size. BREAKING CHANGE: mm_initialize_pool_initial() and mempool_multiple_init_initial() are removed; the following commits add the initial chunk size back in another form. Quick fix: set init_chunksize in the struct mm_pool_config_s given to mm_initialize_pool(), or pass it as the init_chunksize argument of mempool_multiple_init(). CONFIG_FS_HEAP_MEMPOOL_INIT_CHUNK_SIZE keeps its name. Assisted-by: Kiro:claude-opus-5-5 Signed-off-by: huojianchao <huojianchao@xiaomi.com>
mempool_multiple_init() gets an init_chunksize argument: in chunk mode the first chunk that the multiple mempool allocates has this size, and the chunks after it have chunksize. struct mempool_init_s gets the matching member, and the heap passes CONFIG_MM_HEAP_MEMPOOL_INIT_CHUNK_SIZE (default CONFIG_MM_HEAP_MEMPOOL_CHUNK_SIZE) when it sets up its default pools, so that one first allocation can replace several chunk allocations at start-up. BREAKING CHANGE: mempool_multiple_init() takes a new init_chunksize argument after chunksize, and struct mempool_init_s has a new init_chunksize member after chunksize. Quick fix: pass the chunksize value again as init_chunksize to keep the old behavior, and use designated initializers for struct mempool_init_s, or add a value for the new member to positional ones. Assisted-by: Kiro:claude-opus-5-5 Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
struct mempool_init_s becomes struct mm_pool_config_s, the pool configuration that mm_initialize_pool() takes. Members that the caller leaves zero now get the defaults of the heap: the default pool sizes, CONFIG_MM_HEAP_MEMPOOL_THRESHOLD, _CHUNK_SIZE, _INIT_CHUNK_SIZE, _EXPAND_SIZE and _DICTIONARY_EXPAND_SIZE. A caller can then set only the members it cares about, e.g. init_chunksize. All callers in the tree pass NULL. BREAKING CHANGE: struct mempool_init_s is renamed struct mm_pool_config_s, and the members that the caller of mm_initialize_pool() leaves zero now take the defaults of the heap (CONFIG_MM_HEAP_MEMPOOL_*). Quick fix: replace struct mempool_init_s with struct mm_pool_config_s. Assisted-by: Kiro:claude-opus-5-5 Signed-off-by: huojianchao <huojianchao@xiaomi.com>
Fill in the default pool sizes and parameters only when CONFIG_MM_HEAP_MEMPOOL_THRESHOLD is above 0, and set up the multiple mempool only when there is a pool size table. The previous change did both unconditionally, which does not build with a threshold of 0: the default pool size table and the chunk and expand size options exist only for a threshold above 0. With a threshold of 0 a heap gets a mempool only when its caller passes the pool sizes, as before. Assisted-by: Kiro:claude-opus-5-5 Signed-off-by: huojianchao <huojianchao@xiaomi.com>
CONFIG_FS_HEAP_MEMPOOL_INIT_CHUNK_SIZE sets the size of the first mempool chunk of the filesystem heap; the other pool parameters keep the defaults of the heap. The default 0 keeps CONFIG_MM_HEAP_MEMPOOL_INIT_CHUNK_SIZE. Assisted-by: Kiro:claude-opus-5-5 Signed-off-by: huojianchao <huojianchao@xiaomi.com>
huojianchaoyy
requested review from
jerpelea and
xiaoxiang781216
as code owners
December 2, 2026 08:42
|
xiaoxiang781216
approved these changes
Dec 2, 2026
GUIDINGLI
approved these changes
Dec 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note: Please adhere to Contributing Guidelines.
Summary
This PR replaces the initial chunk size of #22540 by the one of Xiaomi Vela, which the next memory manager changes from Vela build on (the multiple mempool and heap pool configuration, and a pool-only heap manager after them). #22540 was a rewrite of the last commit below with new
*_initial()entry points; with both in master there would be two ways to set the same size.mm_initialize_pool_initial(),mempool_multiple_init_initial()and theinitial_sizemember of the multiple mempool go away.CONFIG_FS_HEAP_MEMPOOL_INIT_CHUNK_SIZEcomes back with the last commit under the same name.mempool_multiple_init()takesinit_chunksizeafterchunksize; in chunk mode the first chunk has this size and the later oneschunksize.struct mempool_init_sgets the member, and the heaps useCONFIG_MM_HEAP_MEMPOOL_INIT_CHUNK_SIZE(defaultCONFIG_MM_HEAP_MEMPOOL_CHUNK_SIZE) for their default pools.struct mempool_init_sbecomesstruct mm_pool_config_s; the members that a caller ofmm_initialize_pool()leaves zero take the defaults of the heap.CONFIG_MM_HEAP_MEMPOOL_THRESHOLD=0; in Vela this commit comes after the next one, it is moved up so that every commit builds (the two change different files).CONFIG_FS_HEAP_MEMPOOL_INIT_CHUNK_SIZEfor the filesystem heap; the default 0 keeps the heap default.mempool_multiple_init()takes a newinit_chunksizeargument afterchunksize,struct mempool_init_sis renamedstruct mm_pool_config_sand has a newinit_chunksizemember afterchunksize, andmm_initialize_pool_initial()andmempool_multiple_init_initial()are removed. Quick fix: pass thechunksizevalue again asinit_chunksizeto keep the old behavior, rename the struct (use designated initializers, or add a value for the new member to positional ones), and instead of the*_initial()calls setinit_chunksizein the pool configuration given tomm_initialize_pool()or pass it tomempool_multiple_init(). The first three commits carry the marking.Impact
mempool_multiple_init()has the newinit_chunksizeargument. Quick fix: pass thechunksizevalue again.struct mempool_init_sis nowstruct mm_pool_config_s. Quick fix: rename.mm_initialize_pool_initial()andmempool_multiple_init_initial()(in master since 2026-12-01, in no release) are removed. Quick fix: setinit_chunksizein the pool configuration given tomm_initialize_pool(), or pass it tomempool_multiple_init().CONFIG_MM_HEAP_MEMPOOL_INIT_CHUNK_SIZE, defaultCONFIG_MM_HEAP_MEMPOOL_CHUNK_SIZE, so nothing changes unless it is set.CONFIG_FS_HEAP_MEMPOOL_INIT_CHUNK_SIZEkeeps its name and default 0 and depends only onCONFIG_FS_HEAPSIZE > 0; this also removes the-Wundefwarning that master gives in fs/fs_heap.c when the FS heap is enabled and the mempool threshold is not above 0.CONFIG_MM_HEAP_MEMPOOL_CHUNK_SIZE >= CONFIG_MM_HEAP_MEMPOOL_EXPAND_SIZE, off by default and in every in-tree configuration):chunksizeinstead;Testing
Host: Ubuntu 22.04 x86_64, GCC 13.4.0 (sim), Arm GNU Toolchain 13.2.rel1, CMake 3.23 + Ninja 1.10. Base: master 003fe76 (first built and tested on bb308b4; the only later master commit on these files, f035c67, changes other lines of include/nuttx/mm/mm.h, and the five commits are the same).
./tools/checkpatch.sh -c -u -m -g HEAD~5..HEADpasses, and-bpasses for each of the three marked commits.Every commit builds without warnings (CMake, incremental) for
sim:nshwith the heap mempool in chunk mode (MM_HEAP_MEMPOOL_THRESHOLD=256,MM_HEAP_MEMPOOL_CHUNK_SIZE=16384,MM_HEAP_MEMPOOL_INIT_CHUNK_SIZE=32768,FS_HEAPSIZE=65536,FS_HEAP_MEMPOOL_INIT_CHUNK_SIZE=8192), for the same withMM_TLSF_MANAGER, and forMM_HEAP_MEMPOOL_THRESHOLD=0with the FS heap, except the third commit with a threshold of 0, which the fourth fixes. The head also builds forsim:smp,sim:adb,qemu-armv7a:nshandsim:ostestwith the chunk mode options, and with Make forsim:nsh. On 003fe76 every commit was built again for the threesim:nshconfigurations with the same result, and the head forsim:smpandqemu-armv7a:nsh.freeonsim:nshin chunk mode (master withFS_HEAP_MEMPOOL_INIT_CHUNK_SIZE=8192, which has noMM_HEAP_MEMPOOL_INIT_CHUNK_SIZE):sim:ostestwithMM_HEAP_MEMPOOL_THRESHOLD=256,MM_HEAP_MEMPOOL_CHUNK_SIZE=16384and one loop (TESTING_OSTEST_LOOPS=1; this PR alsoMM_HEAP_MEMPOOL_INIT_CHUNK_SIZE=32768):ostest_main: Exiting with status 0on master and on this PR, 44 tests each; the final memory usage of user_main grows by the same 0x4d0 bytes on both (masteruordblks 48a10 -> 48ee0, this PR489e0 -> 48eb0).Not tested: real hardware.