This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit aa76476a8f950b6851d9b256d588f1b8ccc81555 Author: jingfei <[email protected]> AuthorDate: Tue Oct 13 18:09:17 2026 +0800 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. 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]> --- mm/Kconfig | 8 ++++++++ mm/mm_heap/CMakeLists.txt | 4 ++++ mm/mm_heap/Make.defs | 4 ++++ mm/mm_heap/mm.h | 20 ++++++++++++++++++-- mm/mm_heap/mm_addfreechunk.c | 41 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 75 insertions(+), 2 deletions(-) diff --git a/mm/Kconfig b/mm/Kconfig index e0b8441a6ae..70a79bd1dad 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -25,6 +25,14 @@ config MM_CUSTOMIZE_MANAGER endchoice +config MM_INLINE_ADDFREECHUNK + bool "Inline mm_addfreechunk()" + default !DEFAULT_SMALL + depends on MM_DEFAULT_MANAGER + ---help--- + Inline mm_addfreechunk() into every heap caller for speed. Disable + to emit one shared copy instead and save code space. + config MM_UMM_CUSTOMIZE_MANAGER bool "Customized heap manager" default n diff --git a/mm/mm_heap/CMakeLists.txt b/mm/mm_heap/CMakeLists.txt index ab32bbeb0bb..e1b76179400 100644 --- a/mm/mm_heap/CMakeLists.txt +++ b/mm/mm_heap/CMakeLists.txt @@ -42,6 +42,10 @@ if(CONFIG_MM_DEFAULT_MANAGER) mm_heapmember.c mm_memdump.c) + if(NOT CONFIG_MM_INLINE_ADDFREECHUNK) + list(APPEND SRCS mm_addfreechunk.c) + endif() + if(CONFIG_DEBUG_MM) list(APPEND SRCS mm_checkcorruption.c) endif() diff --git a/mm/mm_heap/Make.defs b/mm/mm_heap/Make.defs index 099d89c9666..0003fd2a4f7 100644 --- a/mm/mm_heap/Make.defs +++ b/mm/mm_heap/Make.defs @@ -29,6 +29,10 @@ CSRCS += mm_malloc_size.c mm_shrinkchunk.c mm_brkaddr.c mm_calloc.c CSRCS += mm_extend.c mm_free.c mm_mallinfo.c mm_malloc.c mm_foreach.c CSRCS += mm_memalign.c mm_realloc.c mm_zalloc.c mm_heapmember.c mm_memdump.c +ifneq ($(CONFIG_MM_INLINE_ADDFREECHUNK),y) +CSRCS += mm_addfreechunk.c +endif + ifeq ($(CONFIG_DEBUG_MM),y) CSRCS += mm_checkcorruption.c endif diff --git a/mm/mm_heap/mm.h b/mm/mm_heap/mm.h index 2926c6e054b..b34c2055231 100644 --- a/mm/mm_heap/mm.h +++ b/mm/mm_heap/mm.h @@ -310,6 +310,13 @@ void mm_delayfree(FAR struct mm_heap_s *heap, FAR void *mem, bool delay); void mm_free_delaylist(FAR struct mm_heap_s *heap); +/* Functions contained in mm_addfreechunk.c *********************************/ + +#ifndef CONFIG_MM_INLINE_ADDFREECHUNK +void mm_addfreechunk(FAR struct mm_heap_s *heap, + FAR struct mm_freenode_s *node); +#endif + /**************************************************************************** * Inline Functions ****************************************************************************/ @@ -326,8 +333,16 @@ static inline_function int mm_size2ndx(size_t size) return flsl(size) - 1; } -static inline_function void mm_addfreechunk(FAR struct mm_heap_s *heap, - FAR struct mm_freenode_s *node) +/* Single body for both forms: inline in every caller, or emitted once by + * mm_addfreechunk.c (which defines MM_ADDFREECHUNK_IMPL). + */ + +#if defined(CONFIG_MM_INLINE_ADDFREECHUNK) || defined(MM_ADDFREECHUNK_IMPL) +# ifdef CONFIG_MM_INLINE_ADDFREECHUNK +static inline_function +# endif +void mm_addfreechunk(FAR struct mm_heap_s *heap, + FAR struct mm_freenode_s *node) { FAR struct mm_freenode_s *next; FAR struct mm_freenode_s *prev; @@ -361,5 +376,6 @@ static inline_function void mm_addfreechunk(FAR struct mm_heap_s *heap, next->blink = node; } } +#endif #endif /* __MM_MM_HEAP_MM_H */ diff --git a/mm/mm_heap/mm_addfreechunk.c b/mm/mm_heap/mm_addfreechunk.c new file mode 100644 index 00000000000..4c4764745ee --- /dev/null +++ b/mm/mm_heap/mm_addfreechunk.c @@ -0,0 +1,41 @@ +/**************************************************************************** + * mm/mm_heap/mm_addfreechunk.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <assert.h> + +#include <nuttx/mm/mm.h> + +/* Emit the out-of-line definition of mm_addfreechunk() from mm.h. */ +#define MM_ADDFREECHUNK_IMPL +#include "mm_heap/mm.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/* mm_addfreechunk() is defined in mm_heap/mm.h. */
