From c25f4233aa5fc25b6e502466d5a02b95361704e4 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Fri, 12 Feb 2021 14:07:33 +0900 Subject: [PATCH] procfs: Use procfs_register_meminfo for "Umem" --- fs/procfs/fs_procfsmeminfo.c | 24 ++---------------------- mm/umm_heap/umm_initialize.c | 13 +++++++++++++ 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/fs/procfs/fs_procfsmeminfo.c b/fs/procfs/fs_procfsmeminfo.c index ec000b62d3..f89cc452ca 100644 --- a/fs/procfs/fs_procfsmeminfo.c +++ b/fs/procfs/fs_procfsmeminfo.c @@ -265,7 +265,6 @@ static ssize_t meminfo_read(FAR struct file *filep, FAR char *buffer, size_t buflen) { FAR struct meminfo_file_s *procfile; - struct mallinfo mem; size_t linesize; size_t copysize; size_t totalsize; @@ -323,6 +322,8 @@ static ssize_t meminfo_read(FAR struct file *filep, FAR char *buffer, #ifdef CONFIG_MM_KERNEL_HEAP if (totalsize < buflen) { + struct mallinfo mem; + buffer += copysize; buflen -= copysize; @@ -341,27 +342,6 @@ static ssize_t meminfo_read(FAR struct file *filep, FAR char *buffer, } #endif -#if !defined(CONFIG_BUILD_KERNEL) - if (totalsize < buflen) - { - buffer += copysize; - buflen -= copysize; - - /* Show user heap information */ - - mem = kumm_mallinfo(); - linesize = snprintf(procfile->line, MEMINFO_LINELEN, - "Umem: %11lu%11lu%11lu%11lu\n", - (unsigned long)mem.arena, - (unsigned long)mem.uordblks, - (unsigned long)mem.fordblks, - (unsigned long)mem.mxordblk); - copysize = procfs_memcpy(procfile->line, linesize, buffer, buflen, - &offset); - totalsize += copysize; - } -#endif - #ifdef CONFIG_MM_PGALLOC if (totalsize < buflen) { diff --git a/mm/umm_heap/umm_initialize.c b/mm/umm_heap/umm_initialize.c index dee0eec037..14ea650b2f 100644 --- a/mm/umm_heap/umm_initialize.c +++ b/mm/umm_heap/umm_initialize.c @@ -26,6 +26,7 @@ #include +#include #include #include "umm_heap/umm_heap.h" @@ -82,4 +83,16 @@ void umm_initialize(FAR void *heap_start, size_t heap_size) { mm_initialize(USR_HEAP, heap_start, heap_size); + +#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MEMINFO) +#if (defined(CONFIG_BUILD_PROTECTED) && defined(__KERNEL__)) || \ + defined(CONFIG_BUILD_FLAT) + static struct procfs_meminfo_entry_s g_umm_procfs; + + g_umm_procfs.name = "Umem"; + g_umm_procfs.mallinfo = (void *)mm_mallinfo; + g_umm_procfs.user_data = USR_HEAP; + procfs_register_meminfo(&g_umm_procfs); +#endif +#endif }