You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/05/21 06:28:47 UTC

[incubator-nuttx] 01/03: mm: Do not abort on allocation failue with CONFIG_DEBUG_MM

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit c546c0b647bd7e995678d8292f2cff9a8f7e9052
Author: YAMAMOTO Takashi <ya...@midokura.com>
AuthorDate: Fri May 20 17:20:10 2022 +0900

    mm: Do not abort on allocation failue with CONFIG_DEBUG_MM
    
    When allocation failed, it isn't too uncommon for the caller
    to fall back to other allocation method.
    (eg. esp32 textheap code tries iram heap when an allocation from rtc heap
    failed.)
    DEBUGASSERT(false) is too much in that case.
    
    This commit removes the DEBUGASSERT, and also makes the heap dump
    a separate option.
---
 mm/Kconfig             | 5 +++++
 mm/mm_heap/mm_malloc.c | 5 ++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/mm/Kconfig b/mm/Kconfig
index c4f506aedd..269ea6609d 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -191,4 +191,9 @@ config MM_BACKTRACE_DEFAULT
 	default n
 	depends on DEBUG_MM
 
+config MM_DUMP_ON_FAILURE
+	bool "Dump heap info on allocation failure"
+	default n
+	depends on DEBUG_MM
+
 source "mm/iob/Kconfig"
diff --git a/mm/mm_heap/mm_malloc.c b/mm/mm_heap/mm_malloc.c
index 135e1f3f1c..a5fd14b528 100644
--- a/mm/mm_heap/mm_malloc.c
+++ b/mm/mm_heap/mm_malloc.c
@@ -244,15 +244,18 @@ FAR void *mm_malloc(FAR struct mm_heap_s *heap, size_t size)
 #ifdef CONFIG_DEBUG_MM
   else
     {
+#ifdef CONFIG_MM_DUMP_ON_FAILURE
       struct mallinfo minfo;
+#endif
 
       mwarn("WARNING: Allocation failed, size %zu\n", alignsize);
+#ifdef CONFIG_MM_DUMP_ON_FAILURE
       mm_mallinfo(heap, &minfo);
       mwarn("Total:%d, used:%d, free:%d, largest:%d, nused:%d, nfree:%d\n",
             minfo.arena, minfo.uordblks, minfo.fordblks,
             minfo.mxordblk, minfo.aordblks, minfo.ordblks);
       mm_memdump(heap, -1);
-      DEBUGASSERT(false);
+#endif
     }
 #endif