Skip to content

!mm/mempool: replace the initial chunk size of #22540 with mm_pool_config_s - #22718

Open
huojianchaoyy wants to merge 5 commits into
apache:masterfrom
huojianchaoyy:nx-mm-mempool-init-chunk-v1
Open

huojianchaoyy wants to merge 5 commits into
apache:masterfrom
huojianchaoyy:nx-mm-mempool-init-chunk-v1

Conversation

@huojianchaoyy

Copy link
Copy Markdown

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.

  • Revert "fs_heap: fix fs_heap mempool init_chunksize": reverts fe9ca94 (fs_heap: fix fs_heap mempool init_chunksize #22540): mm_initialize_pool_initial(), mempool_multiple_init_initial() and the initial_size member of the multiple mempool go away. CONFIG_FS_HEAP_MEMPOOL_INIT_CHUNK_SIZE comes back with the last commit under the same name.
  • mm: mempool supports specifying the initialization chunk size: mempool_multiple_init() takes init_chunksize after chunksize; in chunk mode the first chunk has this size and the later ones chunksize. struct mempool_init_s gets the member, and the heaps use CONFIG_MM_HEAP_MEMPOOL_INIT_CHUNK_SIZE (default CONFIG_MM_HEAP_MEMPOOL_CHUNK_SIZE) for their default pools.
  • mempool: init_chunksize init by user: struct mempool_init_s becomes struct mm_pool_config_s; the members that a caller of mm_initialize_pool() leaves zero take the defaults of the heap.
  • mempool: init in heap or not by CONFIG_MM_HEAP_MEMPOOL_THRESHOLD: the defaults are filled in only for a threshold above 0, and a mempool is set up only with a pool size table. This makes the previous commit build again with 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).
  • fs_heap: fix fs_heap mempool init_chunksize: CONFIG_FS_HEAP_MEMPOOL_INIT_CHUNK_SIZE for the filesystem heap; the default 0 keeps the heap default.
  • BREAKING CHANGE: mempool_multiple_init() takes a new init_chunksize argument after chunksize, struct mempool_init_s is renamed struct mm_pool_config_s and has a new init_chunksize member after chunksize, and mm_initialize_pool_initial() and mempool_multiple_init_initial() are removed. Quick fix: pass the chunksize value again as init_chunksize to 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 set init_chunksize in the pool configuration given to mm_initialize_pool() or pass it to mempool_multiple_init(). The first three commits carry the marking.

Impact

  • API (include/nuttx/mm), all in-tree users are in mm/ and fs/fs_heap.c and are updated, nuttx-apps has none:
    • mempool_multiple_init() has the new init_chunksize argument. Quick fix: pass the chunksize value again.
    • struct mempool_init_s is now struct mm_pool_config_s. Quick fix: rename.
    • mm_initialize_pool_initial() and mempool_multiple_init_initial() (in master since 2026-12-01, in no release) are removed. Quick fix: set init_chunksize in the pool configuration given to mm_initialize_pool(), or pass it to mempool_multiple_init().
  • Kconfig: new CONFIG_MM_HEAP_MEMPOOL_INIT_CHUNK_SIZE, default CONFIG_MM_HEAP_MEMPOOL_CHUNK_SIZE, so nothing changes unless it is set. CONFIG_FS_HEAP_MEMPOOL_INIT_CHUNK_SIZE keeps its name and default 0 and depends only on CONFIG_FS_HEAPSIZE > 0; this also removes the -Wundef warning that master gives in fs/fs_heap.c when the FS heap is enabled and the mempool threshold is not above 0.
  • Behavior compared with fs_heap: fix fs_heap mempool init_chunksize #22540, both only in chunk mode (CONFIG_MM_HEAP_MEMPOOL_CHUNK_SIZE >= CONFIG_MM_HEAP_MEMPOOL_EXPAND_SIZE, off by default and in every in-tree configuration):
  • The section that fs_heap: fix fs_heap mempool init_chunksize #22540 added to Documentation/os/memory/index.rst goes away with the revert.

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..HEAD passes, and -b passes for each of the three marked commits.
Every commit builds without warnings (CMake, incremental) for sim:nsh with 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 with MM_TLSF_MANAGER, and for MM_HEAP_MEMPOOL_THRESHOLD=0 with the FS heap, except the third commit with a threshold of 0, which the fourth fixes. The head also builds for sim:smp, sim:adb, qemu-armv7a:nsh and sim:ostest with the chunk mode options, and with Make for sim:nsh. On 003fe76 every commit was built again for the three sim:nsh configurations with the same result, and the head for sim:smp and qemu-armv7a:nsh.
free on sim:nsh in chunk mode (master with FS_HEAP_MEMPOOL_INIT_CHUNK_SIZE=8192, which has no MM_HEAP_MEMPOOL_INIT_CHUNK_SIZE):

master:
      total       used       free    maxused    maxfree  nused  nfree name
      65528      20416      45112      52688      12288      9      3 heapfs
   67108856    1934480   65174376    1968176   65091424     21      5 Umem
this PR:
      total       used       free    maxused    maxfree  nused  nfree name
      65528      20416      45112      52688      12288      9      3 heapfs
   67108856    1934432   65174424    1968128   65093840     20      4 Umem

sim:ostest with MM_HEAP_MEMPOOL_THRESHOLD=256, MM_HEAP_MEMPOOL_CHUNK_SIZE=16384 and one loop (TESTING_OSTEST_LOOPS=1; this PR also MM_HEAP_MEMPOOL_INIT_CHUNK_SIZE=32768): ostest_main: Exiting with status 0 on master and on this PR, 44 tests each; the final memory usage of user_main grows by the same 0x4d0 bytes on both (master uordblks 48a10 -> 48ee0, this PR 489e0 -> 48eb0).
Not tested: real hardware.

huojianchao and others added 5 commits December 2, 2026 16:17
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>
@github-actions github-actions Bot added Area: Documentation Improvements or additions to documentation Size: M The size of the change in this PR is medium labels Dec 2, 2026
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown

@xiaoxiang781216 xiaoxiang781216 changed the title !mm/mempool: replace the initial chunk size of #22540 with the Vela one !mm/mempool: replace the initial chunk size of #22540 with mm_pool_config_s Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Documentation Improvements or additions to documentation Size: M The size of the change in this PR is medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants