From 736af90370e2734ff3585952bca894b1c99a4393 Mon Sep 17 00:00:00 2001 From: anjiahao Date: Tue, 9 May 2023 16:03:24 +0800 Subject: [PATCH] Support when malloc failed dump mempool info Signed-off-by: anjiahao --- include/nuttx/mm/mempool.h | 8 ++++++++ mm/mempool/mempool_multiple.c | 22 ++++++++++++++++++++++ mm/mm_heap/mm_malloc.c | 4 ++++ 3 files changed, 34 insertions(+) diff --git a/include/nuttx/mm/mempool.h b/include/nuttx/mm/mempool.h index 4391633ecd..aa4bacbb36 100644 --- a/include/nuttx/mm/mempool.h +++ b/include/nuttx/mm/mempool.h @@ -474,6 +474,14 @@ void mempool_multiple_memdump(FAR struct mempool_multiple_s *mpool, void mempool_multiple_deinit(FAR struct mempool_multiple_s *mpool); +/**************************************************************************** + * Name: mempool_multiple_info + * Description: + * Dump multiple memory pool's info. + ****************************************************************************/ + +void mempool_multiple_info(FAR struct mempool_multiple_s *mpool); + /**************************************************************************** * Name: mempool_multiple_info_task * Description: diff --git a/mm/mempool/mempool_multiple.c b/mm/mempool/mempool_multiple.c index 581dc925c0..6ddab78668 100644 --- a/mm/mempool/mempool_multiple.c +++ b/mm/mempool/mempool_multiple.c @@ -23,6 +23,7 @@ ****************************************************************************/ #include +#include #include #include @@ -591,6 +592,27 @@ FAR void *mempool_multiple_memalign(FAR struct mempool_multiple_s *mpool, return NULL; } +/**************************************************************************** + * Name: mempool_multiple_info + ****************************************************************************/ + +void mempool_multiple_info(FAR struct mempool_multiple_s *mpool) +{ + struct mempoolinfo_s minfo; + size_t i; + + syslog(LOG_INFO, "%11s%9s%9s%9s%9s%9s%9s\n", "bsize", "total", "nused", + "nfree", "nifree", "nwaiter", "nexpend"); + for (i = 0; i < mpool->npools; i++) + { + mempool_info(mpool->pools + i, &minfo); + syslog(LOG_INFO, "%9lu%11lu%9lu%9lu%9lu%9lu%9zu\n", + minfo.sizeblks, minfo.arena, minfo.aordblks, + minfo.ordblks, minfo.iordblks, + minfo.nwaiter, mpool->pools->nexpend); + } +} + /**************************************************************************** * Name: mempool_multiple_info_task ****************************************************************************/ diff --git a/mm/mm_heap/mm_malloc.c b/mm/mm_heap/mm_malloc.c index efc34d06c2..63eb025c7d 100644 --- a/mm/mm_heap/mm_malloc.c +++ b/mm/mm_heap/mm_malloc.c @@ -268,6 +268,10 @@ FAR void *mm_malloc(FAR struct mm_heap_s *heap, size_t size) # if CONFIG_MM_BACKTRACE >= 0 nxsched_foreach(mm_dump_handler, heap); # endif +# if CONFIG_MM_HEAP_MEMPOOL_THRESHOLD != 0 + mempool_multiple_info(heap->mm_mpool); +# endif + #endif #ifdef CONFIG_MM_PANIC_ON_FAILURE PANIC();