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/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new b0ab41beee memdump: support dump the leak memory (malloced but task
exit)
b0ab41beee is described below
commit b0ab41beeeeae4a14d6e294e0409667ab7c2545d
Author: wangbowen6 <[email protected]>
AuthorDate: Fri May 26 17:17:19 2023 +0800
memdump: support dump the leak memory (malloced but task exit)
1. command "memdump leak" can dump the leacked memory node;
2. fix the leak memory stat bug in memory manager;
Signed-off-by: wangbowen6 <[email protected]>
---
fs/procfs/fs_procfsmeminfo.c | 54 ++++++++++++++++++++------------------------
mm/mempool/mempool.c | 4 ++--
mm/mm_heap/mm_mallinfo.c | 3 ++-
mm/mm_heap/mm_memdump.c | 6 ++---
mm/tlsf/mm_tlsf.c | 6 +++--
5 files changed, 35 insertions(+), 38 deletions(-)
diff --git a/fs/procfs/fs_procfsmeminfo.c b/fs/procfs/fs_procfsmeminfo.c
index c81df55947..824a6e5ae8 100644
--- a/fs/procfs/fs_procfsmeminfo.c
+++ b/fs/procfs/fs_procfsmeminfo.c
@@ -56,7 +56,7 @@
* to handle the longest line generated by this logic.
*/
-#define MEMINFO_LINELEN 80
+#define MEMINFO_LINELEN 256
/****************************************************************************
* Private Types
@@ -404,7 +404,6 @@ static ssize_t memdump_read(FAR struct file *filep, FAR
char *buffer,
FAR struct meminfo_file_s *procfile;
size_t linesize;
size_t copysize;
- size_t totalsize;
off_t offset;
finfo("buffer=%p buflen=%d\n", buffer, (int)buflen);
@@ -419,41 +418,26 @@ static ssize_t memdump_read(FAR struct file *filep, FAR
char *buffer,
#if CONFIG_MM_BACKTRACE >= 0
linesize = procfs_snprintf(procfile->line, MEMINFO_LINELEN,
- "usage: <pid/used/free/on/off>"
- "<seqmin> <seqmax> \n"
+ "usage: <on/off/pid/used/free/leak>"
+ "<seqmin> <seqmax>\n"
"on/off backtrace\n"
- "pid: dump pid allocated node\n");
+ "pid: dump pid allocated node\n"
+ "used: dump all allocated node\n"
+ "free: dump all free node\n"
+ "leak: dump all leaked node\n"
+ "The current sequence number %lu\n",
+ g_mm_seqno);
#else
linesize = procfs_snprintf(procfile->line, MEMINFO_LINELEN,
- "usage: <used/free>\n");
-#endif
-
- copysize = procfs_memcpy(procfile->line, linesize, buffer, buflen,
- &offset);
- totalsize = copysize;
- buffer += copysize;
- buflen -= copysize;
- linesize = procfs_snprintf(procfile->line, MEMINFO_LINELEN,
+ "usage: <used/free>\n"
"used: dump all allocated node\n"
"free: dump all free node\n");
-
- copysize = procfs_memcpy(procfile->line, linesize, buffer, buflen,
- &offset);
- totalsize += copysize;
-
-#if CONFIG_MM_BACKTRACE >= 0
- buffer += copysize;
- buflen -= copysize;
- linesize = procfs_snprintf(procfile->line, MEMINFO_LINELEN,
- "The current sequence number %lu\n",
- g_mm_seqno);
-
- totalsize += procfs_memcpy(procfile->line, linesize, buffer, buflen,
- &offset);
#endif
- filep->f_pos += totalsize;
- return totalsize;
+ copysize = procfs_memcpy(procfile->line, linesize, buffer, buflen,
+ &offset);
+ filep->f_pos += copysize;
+ return copysize;
}
#endif
@@ -556,6 +540,16 @@ static ssize_t memdump_write(FAR struct file *filep, FAR
const char *buffer,
goto dump;
#endif
break;
+
+ case 'l':
+ dump.pid = PID_MM_LEAK;
+
+#if CONFIG_MM_BACKTRACE >= 0
+ p = (FAR char *)buffer + 4;
+ goto dump;
+#endif
+ break;
+
#if CONFIG_MM_BACKTRACE >= 0
default:
if (!isdigit(buffer[0]))
diff --git a/mm/mempool/mempool.c b/mm/mempool/mempool.c
index 47d851349c..f97913e1a1 100644
--- a/mm/mempool/mempool.c
+++ b/mm/mempool/mempool.c
@@ -427,7 +427,7 @@ mempool_info_task(FAR struct mempool_s *pool,
node)
{
if ((task->pid == buf->pid || task->pid == PID_MM_ALLOC ||
- (task->pid == PID_MM_LEAK && !!nxsched_get_tcb(buf->pid))) &&
+ (task->pid == PID_MM_LEAK && !nxsched_get_tcb(buf->pid))) &&
buf->seqno >= task->seqmin && buf->seqno <= task->seqmax)
{
info.aordblks++;
@@ -490,7 +490,7 @@ void mempool_memdump(FAR struct mempool_s *pool,
struct mempool_backtrace_s, node)
{
if ((dump->pid == buf->pid || dump->pid == PID_MM_ALLOC ||
- (dump->pid == PID_MM_LEAK && !!nxsched_get_tcb(buf->pid))) &&
+ (dump->pid == PID_MM_LEAK && !nxsched_get_tcb(buf->pid))) &&
buf->seqno >= dump->seqmin && buf->seqno <= dump->seqmax)
{
char tmp[CONFIG_MM_BACKTRACE * MM_PTR_FMT_WIDTH + 1] = "";
diff --git a/mm/mm_heap/mm_mallinfo.c b/mm/mm_heap/mm_mallinfo.c
index a0f1453558..d844bd9293 100644
--- a/mm/mm_heap/mm_mallinfo.c
+++ b/mm/mm_heap/mm_mallinfo.c
@@ -106,7 +106,8 @@ static void mallinfo_task_handler(FAR struct mm_allocnode_s
*node,
#else
if ((task->pid == node->pid ||
(task->pid == PID_MM_ALLOC && node->pid != PID_MM_MEMPOOL) ||
- (task->pid == PID_MM_LEAK && !!nxsched_get_tcb(node->pid))) &&
+ (task->pid == PID_MM_LEAK && node->pid >= 0 &&
+ !nxsched_get_tcb(node->pid))) &&
node->seqno >= task->seqmin && node->seqno <= task->seqmax)
{
info->aordblks++;
diff --git a/mm/mm_heap/mm_memdump.c b/mm/mm_heap/mm_memdump.c
index 57b831982b..7f45c2f419 100644
--- a/mm/mm_heap/mm_memdump.c
+++ b/mm/mm_heap/mm_memdump.c
@@ -61,9 +61,9 @@ static void memdump_handler(FAR struct mm_allocnode_s *node,
FAR void *arg)
#if CONFIG_MM_BACKTRACE < 0
if (dump->pid == PID_MM_ALLOC)
#else
- if ((dump->pid == node->pid ||
- (dump->pid == PID_MM_ALLOC && node->pid != PID_MM_MEMPOOL) ||
- (dump->pid == PID_MM_LEAK && !!nxsched_get_tcb(node->pid))) &&
+ if ((dump->pid == node->pid || dump->pid == PID_MM_ALLOC ||
+ (dump->pid == PID_MM_LEAK && node->pid >= 0 &&
+ !nxsched_get_tcb(node->pid))) &&
node->seqno >= dump->seqmin && node->seqno <= dump->seqmax)
#endif
{
diff --git a/mm/tlsf/mm_tlsf.c b/mm/tlsf/mm_tlsf.c
index 30de861a39..70ae02af17 100644
--- a/mm/tlsf/mm_tlsf.c
+++ b/mm/tlsf/mm_tlsf.c
@@ -299,7 +299,8 @@ static void mallinfo_task_handler(FAR void *ptr, size_t
size, int used,
if ((task->pid == buf->pid ||
(task->pid == PID_MM_ALLOC && buf->pid != PID_MM_MEMPOOL) ||
- (task->pid == PID_MM_LEAK && !!nxsched_get_tcb(buf->pid))) &&
+ (task->pid == PID_MM_LEAK && buf->pid >= 0 &&
+ !nxsched_get_tcb(buf->pid))) &&
buf->seqno >= task->seqmin && buf->seqno <= task->seqmax)
{
info->aordblks++;
@@ -412,7 +413,8 @@ static void memdump_handler(FAR void *ptr, size_t size, int
used,
if ((dump->pid == buf->pid ||
(dump->pid == PID_MM_ALLOC && buf->pid != PID_MM_MEMPOOL) ||
- (dump->pid == PID_MM_LEAK && !!nxsched_get_tcb(buf->pid))) &&
+ (dump->pid == PID_MM_LEAK && buf->pid >= 0 &&
+ !nxsched_get_tcb(buf->pid))) &&
buf->seqno >= dump->seqmin && buf->seqno <= dump->seqmax)
#endif
{