From c546c0b647bd7e995678d8292f2cff9a8f7e9052 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Fri, 20 May 2022 17:20:10 +0900 Subject: [PATCH] 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