Repository navigation
mm, sched, libc: save 576 bytes of code on DEFAULT_SMALL builds - #20628
Conversation
mm_addfreechunk() walks the free list and is inlined into every heap path (malloc, free, realloc, shrinkchunk, initialize), so each caller carries its own copy of the loop. Add MM_INLINE_ADDFREECHUNK, default !DEFAULT_SMALL. Small builds now emit one shared copy; default builds are unchanged. stm32f103-minimum:nsh (DEFAULT_SMALL=y): text -360 bytes. Signed-off-by: jingfei <[email protected]>
nxsched_add_prioritized() is inlined into all 18 call sites across the scheduler, semaphores, message queues and events. Add SCHED_INLINE_ADDPRIORITIZED, default !DEFAULT_SMALL. Small builds now use one shared copy; default builds are unchanged. stm32f103-minimum:nsh (DEFAULT_SMALL=y): text -200 bytes. Signed-off-by: jingfei <[email protected]>
Without CONFIG_HAVE_CXXINITIALIZE the body of lib_cxx_initialize() compiles away, but the empty function and its call from nxtask_startup() remain. Build the file only when C++ static initialization is supported and make the call a no-op otherwise. stm32f103-minimum:nsh: text -16 bytes. Signed-off-by: jingfei <[email protected]>
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
2 open findings
What changed in this PR
Reduces code size for DEFAULT_SMALL builds by making two hot-path helpers optionally out-of-line and by removing an always-built (but often empty) C++ init stub from non-C++ configurations.
Changes:
- Add
CONFIG_MM_INLINE_ADDFREECHUNK/CONFIG_SCHED_INLINE_ADDPRIORITIZEDto switch between header-inlined vs single out-of-line instantiation. - Add small
.c“instantiation” units and wire them into both Make and CMake builds when inlining is disabled. - Build
lib_cxx_initialize.conly whenCONFIG_HAVE_CXXINITIALIZE=y, and provide a no-op replacement otherwise.
| File | Description |
|---|---|
| sched/sched/sched_addprioritized.c | New instantiation unit to emit one out-of-line nxsched_add_prioritized() |
| sched/sched/sched.h | Conditional inline vs external definition for nxsched_add_prioritized() |
| sched/sched/Make.defs | Conditionally build sched_addprioritized.c when not inlining |
| sched/sched/CMakeLists.txt | Same conditional inclusion for CMake builds |
| sched/Kconfig | Add SCHED_INLINE_ADDPRIORITIZED option defaulting off for DEFAULT_SMALL |
| mm/mm_heap/mm_addfreechunk.c | New instantiation unit to emit one out-of-line mm_addfreechunk() |
| mm/mm_heap/mm.h | Conditional inline vs external definition/prototype for mm_addfreechunk() |
| mm/mm_heap/Make.defs | Conditionally build mm_addfreechunk.c when not inlining |
| mm/mm_heap/CMakeLists.txt | Same conditional inclusion for CMake builds |
| mm/Kconfig | Add MM_INLINE_ADDFREECHUNK option defaulting off for DEFAULT_SMALL |
| libs/libc/misc/lib_cxx_initialize.c | Remove internal #ifdef since file is now conditionally built |
| libs/libc/misc/Make.defs | Only build lib_cxx_initialize.c when C++ init is supported |
| libs/libc/misc/CMakeLists.txt | Same conditional inclusion for CMake builds |
| libs/libc/libc.h | No-op fallback for lib_cxx_initialize() when C++ init is unavailable |
🧠 Review effort: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Signed-off-by: jingfei <[email protected]>
Signed-off-by: jingfei <[email protected]>
Signed-off-by: jingfei <[email protected]>
|
|
"fixup!" commits should not be merged! That’s completely messed up CI! |
could you explain more? if it's a hard rule, let's add to the style check. |


Summary
Related to the footprint discussion in #20414. Three small, independent
changes that let size-constrained configurations drop code that currently
cannot be trimmed. Default (non-
DEFAULT_SMALL) builds keep today's behavior.mm/mm_heap: optional inline for
mm_addfreechunk()mm_addfreechunk()walks the free list and is inlined into every heap path(malloc, free, realloc, shrinkchunk, initialize), so each caller carries its
own copy of the loop. New
CONFIG_MM_INLINE_ADDFREECHUNK(
default !DEFAULT_SMALL). When disabled,mm_addfreechunk.cemits oneshared copy. The function body stays in one place (
mm.h); the.conlyinstantiates it, so no code is duplicated.
sched: optional inline for
nxsched_add_prioritized()Inlined into all 18 call sites across the scheduler, semaphores, message
queues and events. New
CONFIG_SCHED_INLINE_ADDPRIORITIZED(
default !DEFAULT_SMALL), same single-body pattern viasched_addprioritized.c.libc: build
lib_cxx_initialize()only for C++ initWithout
CONFIG_HAVE_CXXINITIALIZEthe function body compiles away, but theempty function and its call from
nxtask_startup()remain. The file is nowbuilt only when C++ static initialization is supported; otherwise the call
is a no-op macro.
Items 1 and 2 were made inline for performance in #14144 and #14059. That
stays the default; only
DEFAULT_SMALLbuilds switch to the shared copy.Impact
options default to
yunlessCONFIG_DEFAULT_SMALL=y.DEFAULT_SMALLbuilds: one extra call/return on heap free-list insertion andon priority-list insertion, in exchange for code size.
lib_cxx_initialize()is libc-internal(
libs/libc/libc.h).Testing
Host: Ubuntu x86_64, arm-none-eabi-gcc 10.3.1 20210621. Rebased on master
734b0c5757. All sizes below come from clean CMake builds.Size,
stm32f103-minimum:nsh(DEFAULT_SMALL=y):Per commit, applied in order:
mm_addfreechunk-360,nxsched_add_prioritized-200,
lib_cxx_initialize-16.Both states of each option build, and the out-of-line symbol is present
only when the option is off:
DEFAULT_SMALL=y, both inline options off)mm_addfreechunk,nxsched_add_prioritizedMM_INLINE_ADDFREECHUNK=y,SCHED_INLINE_ADDPRIORITIZED=yHAVE_CXXINITIALIZE=ylib_cxx_initializelinkedOther checks:
sim:smpwith both inline options off: builds; one shared copy of each function../tools/checkpatch.sh -g master..HEAD: all checks pass.cmake-format --check: clean.Runtime,
sim:ostest: run with both inline options off and, as a control,with both on (same tree). Both runs reached
waitpid_testinside a 540 stimeout with no
ERROR, assertion or panic, and went through the same tests.Neither configuration finished ostest in that window, so this shows no
difference between the two configurations rather than a full ostest pass.