From af3978c1fafbd48090986ee3e71ce56b09cb6059 Mon Sep 17 00:00:00 2001 From: anjiahao Date: Sun, 20 Nov 2022 15:00:44 +0800 Subject: [PATCH] adjust the contents of memdump and meminfo memdump:just dump info meminfo:statistics mem information Signed-off-by: anjiahao --- include/malloc.h | 4 ---- include/nuttx/mm/mm.h | 2 -- mm/kmm_heap/kmm_mallinfo.c | 2 -- mm/mm_heap/mm_mallinfo.c | 15 ++++++++----- mm/mm_heap/mm_memdump.c | 30 ++++++++------------------ mm/tlsf/mm_tlsf.c | 43 ++++++++++++++++++++++---------------- mm/umm_heap/umm_mallinfo.c | 2 -- 7 files changed, 44 insertions(+), 54 deletions(-) diff --git a/include/malloc.h b/include/malloc.h index 49de2b80da..030738ed0e 100644 --- a/include/malloc.h +++ b/include/malloc.h @@ -52,14 +52,12 @@ struct mallinfo * by free (not in use) chunks. */ }; -#if CONFIG_MM_BACKTRACE >= 0 struct mallinfo_task { pid_t pid; /* The pid of task */ int aordblks; /* This is the number of allocated (in use) chunks for task */ int uordblks; /* This is the total size of memory occupied for task */ }; -#endif /**************************************************************************** * Public Function Prototypes @@ -72,9 +70,7 @@ extern "C" struct mallinfo mallinfo(void); size_t malloc_size(FAR void *ptr); -#if CONFIG_MM_BACKTRACE >= 0 struct mallinfo_task mallinfo_task(pid_t pid); -#endif #if defined(__cplusplus) } diff --git a/include/nuttx/mm/mm.h b/include/nuttx/mm/mm.h index 8446b71c8e..ed874627c9 100644 --- a/include/nuttx/mm/mm.h +++ b/include/nuttx/mm/mm.h @@ -310,11 +310,9 @@ void kmm_extend(FAR void *mem, size_t size, int region); struct mallinfo; /* Forward reference */ int mm_mallinfo(FAR struct mm_heap_s *heap, FAR struct mallinfo *info); -#if CONFIG_MM_BACKTRACE >= 0 struct mallinfo_task; /* Forward reference */ int mm_mallinfo_task(FAR struct mm_heap_s *heap, FAR struct mallinfo_task *info); -#endif /* Functions contained in kmm_mallinfo.c ************************************/ diff --git a/mm/kmm_heap/kmm_mallinfo.c b/mm/kmm_heap/kmm_mallinfo.c index 7139301802..89e4ea4476 100644 --- a/mm/kmm_heap/kmm_mallinfo.c +++ b/mm/kmm_heap/kmm_mallinfo.c @@ -59,7 +59,6 @@ struct mallinfo kmm_mallinfo(void) * ****************************************************************************/ -#if CONFIG_MM_BACKTRACE >= 0 struct mallinfo_task kmm_mallinfo_task(pid_t pid) { struct mallinfo_task info; @@ -68,5 +67,4 @@ struct mallinfo_task kmm_mallinfo_task(pid_t pid) mm_mallinfo_task(g_kmmheap, &info); return info; } -#endif #endif /* CONFIG_MM_KERNEL_HEAP */ diff --git a/mm/mm_heap/mm_mallinfo.c b/mm/mm_heap/mm_mallinfo.c index d9275771e0..3a7fc5f4c2 100644 --- a/mm/mm_heap/mm_mallinfo.c +++ b/mm/mm_heap/mm_mallinfo.c @@ -75,7 +75,6 @@ static void mallinfo_handler(FAR struct mm_allocnode_s *node, FAR void *arg) } } -#if CONFIG_MM_BACKTRACE >= 0 static void mallinfo_task_handler(FAR struct mm_allocnode_s *node, FAR void *arg) { @@ -86,14 +85,22 @@ static void mallinfo_task_handler(FAR struct mm_allocnode_s *node, if ((node->preceding & MM_ALLOC_BIT) != 0) { DEBUGASSERT(node->size >= SIZEOF_MM_ALLOCNODE); - if (node->pid == info->pid) +#if CONFIG_MM_BACKTRACE < 0 + if (info->pid == -1) +#else + if (info->pid == -1 || node->pid == info->pid) +#endif { info->aordblks++; info->uordblks += node->size; } } + else if (info->pid == -2) + { + info->aordblks++; + info->uordblks += node->size; + } } -#endif /**************************************************************************** * Public Functions @@ -137,7 +144,6 @@ int mm_mallinfo(FAR struct mm_heap_s *heap, FAR struct mallinfo *info) * ****************************************************************************/ -#if CONFIG_MM_BACKTRACE >= 0 int mm_mallinfo_task(FAR struct mm_heap_s *heap, FAR struct mallinfo_task *info) { @@ -148,4 +154,3 @@ int mm_mallinfo_task(FAR struct mm_heap_s *heap, mm_foreach(heap, mallinfo_task_handler, info); return OK; } -#endif diff --git a/mm/mm_heap/mm_memdump.c b/mm/mm_heap/mm_memdump.c index 382c03938c..93b8fdb53a 100644 --- a/mm/mm_heap/mm_memdump.c +++ b/mm/mm_heap/mm_memdump.c @@ -47,28 +47,21 @@ * Private Types ****************************************************************************/ -struct memdump_info_s -{ - pid_t pid; - int blks; - int size; -}; - /**************************************************************************** * Private Functions ****************************************************************************/ static void memdump_handler(FAR struct mm_allocnode_s *node, FAR void *arg) { - FAR struct memdump_info_s *info = arg; + pid_t pid = *(FAR pid_t *)arg; if ((node->preceding & MM_ALLOC_BIT) != 0) { DEBUGASSERT(node->size >= SIZEOF_MM_ALLOCNODE); #if CONFIG_MM_BACKTRACE < 0 - if (info->pid == -1) + if (pid == -1) #else - if (info->pid == -1 || node->pid == info->pid) + if (pid == -1 || node->pid == pid) #endif { #if CONFIG_MM_BACKTRACE < 0 @@ -95,8 +88,6 @@ static void memdump_handler(FAR struct mm_allocnode_s *node, FAR void *arg) (int)node->pid, (size_t)node->size, MM_PTR_FMT_WIDTH, ((FAR char *)node + SIZEOF_MM_ALLOCNODE), buf); #endif - info->blks++; - info->size += node->size; } } else @@ -112,10 +103,8 @@ static void memdump_handler(FAR struct mm_allocnode_s *node, FAR void *arg) fnode->flink->size == 0 || fnode->flink->size >= fnode->size); - if (info->pid <= -2) + if (pid <= -2) { - info->blks++; - info->size += node->size; syslog(LOG_INFO, "%12zu%*p\n", (size_t)node->size, MM_PTR_FMT_WIDTH, ((FAR char *)node + SIZEOF_MM_ALLOCNODE)); @@ -140,7 +129,7 @@ static void memdump_handler(FAR struct mm_allocnode_s *node, FAR void *arg) void mm_memdump(FAR struct mm_heap_s *heap, pid_t pid) { - struct memdump_info_s info; + struct mallinfo_task info; if (pid >= -1) { @@ -158,11 +147,10 @@ void mm_memdump(FAR struct mm_heap_s *heap, pid_t pid) syslog(LOG_INFO, "%12s%*s\n", "Size", MM_PTR_FMT_WIDTH, "Address"); } - info.blks = 0; - info.size = 0; - info.pid = pid; - mm_foreach(heap, memdump_handler, &info); + mm_foreach(heap, memdump_handler, &pid); + info.pid = pid; + mm_mallinfo_task(heap, &info); syslog(LOG_INFO, "%12s%12s\n", "Total Blks", "Total Size"); - syslog(LOG_INFO, "%12d%12d\n", info.blks, info.size); + syslog(LOG_INFO, "%12d%12d\n", info.aordblks, info.uordblks); } diff --git a/mm/tlsf/mm_tlsf.c b/mm/tlsf/mm_tlsf.c index c2cb433518..2bbe14f028 100644 --- a/mm/tlsf/mm_tlsf.c +++ b/mm/tlsf/mm_tlsf.c @@ -242,8 +242,6 @@ static void mallinfo_handler(FAR void *ptr, size_t size, int used, } } -#if CONFIG_MM_BACKTRACE >= 0 - /**************************************************************************** * Name: mallinfo_task_handler ****************************************************************************/ @@ -251,18 +249,34 @@ static void mallinfo_handler(FAR void *ptr, size_t size, int used, static void mallinfo_task_handler(FAR void *ptr, size_t size, int used, FAR void *user) { +#if CONFIG_MM_BACKTRACE >= 0 FAR struct memdump_backtrace_s *dump; +#endif FAR struct mallinfo_task *info = user; +#if CONFIG_MM_BACKTRACE >= 0 size -= sizeof(struct memdump_backtrace_s); dump = ptr + size; - if (used && dump->pid == info->pid) + + if (used) + { +#if CONFIG_MM_BACKTRACE < 0 + if (info->pid = -1) +#else + if (info->pid == -1 || info->pid == dump->pid) +#endif + { + info->aordblks++; + info->uordblks += size; + } + } + else if (info->pid == -2) { info->aordblks++; info->uordblks += size; } -} #endif +} /**************************************************************************** * Name: mm_lock @@ -350,7 +364,7 @@ static void mm_unlock(FAR struct mm_heap_s *heap) static void memdump_handler(FAR void *ptr, size_t size, int used, FAR void *user) { - FAR struct memdump_info_s *info = user; + pid_t pid = *(FAR pid_t *)user; #if CONFIG_MM_BACKTRACE >= 0 FAR struct memdump_backtrace_s *dump; @@ -361,9 +375,9 @@ static void memdump_handler(FAR void *ptr, size_t size, int used, if (used) { #if CONFIG_MM_BACKTRACE < 0 - if (info->pid == -1) + if (pid == -1) #else - if (info->pid == -1 || dump->pid == info->pid) + if (pid == -1 || dump->pid == pid) #endif { #if CONFIG_MM_BACKTRACE < 0 @@ -388,14 +402,10 @@ static void memdump_handler(FAR void *ptr, size_t size, int used, (int)dump->pid, size, MM_PTR_FMT_WIDTH, ptr, buf); #endif - info->blks++; - info->size += size; } } - else if (info->pid <= -2) + else if (pid <= -2) { - info->blks++; - info->size += size; syslog(LOG_INFO, "%12zu%*p\n", size, MM_PTR_FMT_WIDTH, ptr); } } @@ -839,7 +849,6 @@ int mm_mallinfo(FAR struct mm_heap_s *heap, FAR struct mallinfo *info) return OK; } -#if CONFIG_MM_BACKTRACE >= 0 int mm_mallinfo_task(FAR struct mm_heap_s *heap, FAR struct mallinfo_task *info) { @@ -867,7 +876,6 @@ int mm_mallinfo_task(FAR struct mm_heap_s *heap, return OK; } -#endif /**************************************************************************** * Name: mm_memdump @@ -905,20 +913,19 @@ void mm_memdump(FAR struct mm_heap_s *heap, pid_t pid) syslog(LOG_INFO, "%12s%*s\n", "Size", MM_PTR_FMT_WIDTH, "Address"); } - info.blks = 0; - info.size = 0; - info.pid = pid; #if CONFIG_MM_REGIONS > 1 for (region = 0; region < heap->mm_nregions; region++) #endif { DEBUGVERIFY(mm_lock(heap)); tlsf_walk_pool(heap->mm_heapstart[region], - memdump_handler, &info); + memdump_handler, &pid); mm_unlock(heap); } #undef region + info.pid = pid; + mm_mallinfo_task(heap, &info); syslog(LOG_INFO, "%12s%12s\n", "Total Blks", "Total Size"); syslog(LOG_INFO, "%12d%12d\n", info.blks, info.size); } diff --git a/mm/umm_heap/umm_mallinfo.c b/mm/umm_heap/umm_mallinfo.c index fd092e31f6..8418d1a853 100644 --- a/mm/umm_heap/umm_mallinfo.c +++ b/mm/umm_heap/umm_mallinfo.c @@ -59,7 +59,6 @@ struct mallinfo mallinfo(void) * ****************************************************************************/ -#if CONFIG_MM_BACKTRACE >= 0 struct mallinfo_task mallinfo_task(pid_t pid) { struct mallinfo_task info; @@ -68,4 +67,3 @@ struct mallinfo_task mallinfo_task(pid_t pid) mm_mallinfo_task(USR_HEAP, &info); return info; } -#endif