You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by bt...@apache.org on 2021/05/25 08:01:47 UTC

[incubator-nuttx] branch master updated: cmd/free: add nused/nfree field in command free

This is an automated email from the ASF dual-hosted git repository.

btashton pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new fea1da2  cmd/free: add nused/nfree field in command free
fea1da2 is described below

commit fea1da2f53be1603a809ac00f9d257d212bf3796
Author: Jiuzhu Dong <do...@xiaomi.com>
AuthorDate: Wed Apr 28 11:05:20 2021 +0800

    cmd/free: add nused/nfree field in command free
    
    Change-Id: I74aa4b1e7394a17c3b117322a4cc24aa52aac3b8
    Signed-off-by: Jiuzhu Dong <do...@xiaomi.com>
---
 Documentation/applications/nsh/commands.rst |  7 +++++--
 fs/procfs/fs_procfsmeminfo.c                | 20 ++++++++++++++------
 include/malloc.h                            |  1 +
 mm/mm_heap/mm_mallinfo.c                    |  3 +++
 4 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/Documentation/applications/nsh/commands.rst b/Documentation/applications/nsh/commands.rst
index 3524128..cb91899 100644
--- a/Documentation/applications/nsh/commands.rst
+++ b/Documentation/applications/nsh/commands.rst
@@ -495,8 +495,9 @@ Show Memory Manager Status (free)
 example::
 
   nsh> free
-               total       used       free    largest
-  Mem:       4194288    1591552    2602736    2601584
+               total       used       free    largest  nused  nfree
+  Mem:       5583024    1614784    3968240    3967792    244      4
+
   nsh>
 
 **Where:**
@@ -506,6 +507,8 @@ total 	 This is the total size of memory allocated for use by malloc in bytes.
 used     This is the total size of memory occupied by chunks handed out by malloc.
 free     This is the total size of memory occupied by free (not in use) chunks.
 largest  Size of the largest free (not in use) chunk.
+nused    This is the number of allocated chunks
+nfree    This is the number of free chunks
 =======  ======================================
 
 .. _cmdget:
diff --git a/fs/procfs/fs_procfsmeminfo.c b/fs/procfs/fs_procfsmeminfo.c
index bc10f78..ebef16a 100644
--- a/fs/procfs/fs_procfsmeminfo.c
+++ b/fs/procfs/fs_procfsmeminfo.c
@@ -54,7 +54,7 @@
  * to handle the longest line generated by this logic.
  */
 
-#define MEMINFO_LINELEN 62
+#define MEMINFO_LINELEN 80
 
 /****************************************************************************
  * Private Types
@@ -74,6 +74,7 @@ struct progmem_info_s
 {
   int arena;                      /* Total size of available progmem. */
   int ordblks;                    /* This is the number of free chunks */
+  int aordblks;                   /* This is the number of allocated chunks */
   int mxordblk;                   /* Size of the largest free chunk */
   int uordblks;                   /* Total size of memory for allocated chunks */
   int fordblks;                   /* Total size of memory for free chunks. */
@@ -147,6 +148,8 @@ static void meminfo_progmem(FAR struct progmem_info_s *progmem)
   ssize_t status;
 
   progmem->arena    = 0;
+  progmem->ordblks  = 0;
+  progmem->aordblks = 0;
   progmem->fordblks = 0;
   progmem->uordblks = 0;
   progmem->mxordblk = 0;
@@ -171,6 +174,7 @@ static void meminfo_progmem(FAR struct progmem_info_s *progmem)
         }
       else if (status != 0)
         {
+          progmem->aordblks++;
           progmem->uordblks += pagesize;
 
           if (stpage != 0xffff && up_progmem_isuniform())
@@ -285,7 +289,7 @@ static ssize_t meminfo_read(FAR struct file *filep, FAR char *buffer,
   linesize  =
     snprintf(procfile->line, MEMINFO_LINELEN,
              "                     "
-             "total       used       free    largest\n");
+             "total       used       free    largest  nused  nfree\n");
 
   copysize  = procfs_memcpy(procfile->line, linesize, buffer, buflen,
                             &offset);
@@ -308,12 +312,14 @@ static ssize_t meminfo_read(FAR struct file *filep, FAR char *buffer,
 
           entry->mallinfo(entry->user_data, &minfo);
           linesize   = snprintf(procfile->line, MEMINFO_LINELEN,
-                                "%12s:  %11lu%11lu%11lu%11lu\n",
+                                "%12s:  %11lu%11lu%11lu%11lu%7lu%7lu\n",
                                 entry->name,
                                 (unsigned long)minfo.arena,
                                 (unsigned long)minfo.uordblks,
                                 (unsigned long)minfo.fordblks,
-                                (unsigned long)minfo.mxordblk);
+                                (unsigned long)minfo.mxordblk,
+                                (unsigned long)minfo.aordblks,
+                                (unsigned long)minfo.ordblks);
           copysize   = procfs_memcpy(procfile->line, linesize, buffer,
                                      buflen, &offset);
           totalsize += copysize;
@@ -364,11 +370,13 @@ static ssize_t meminfo_read(FAR struct file *filep, FAR char *buffer,
       meminfo_progmem(&progmem);
 
       linesize   = snprintf(procfile->line, MEMINFO_LINELEN,
-                            "Prog:  %11lu%11lu%11lu%11lu\n",
+                            "Prog:  %11lu%11lu%11lu%11lu%7lu%7lu\n",
                             (unsigned long)progmem.arena,
                             (unsigned long)progmem.uordblks,
                             (unsigned long)progmem.fordblks,
-                            (unsigned long)progmem.mxordblk);
+                            (unsigned long)progmem.mxordblk,
+                            (unsigned long)progmem.aordblks,
+                            (unsigned long)progmem.ordblks);
       copysize   = procfs_memcpy(procfile->line, linesize, buffer, buflen,
                                  &offset);
       totalsize += copysize;
diff --git a/include/malloc.h b/include/malloc.h
index 0d993b9..a4bc6c4 100644
--- a/include/malloc.h
+++ b/include/malloc.h
@@ -40,6 +40,7 @@ struct mallinfo
   int arena;    /* This is the total size of memory allocated
                  * for use by malloc in bytes. */
   int ordblks;  /* This is the number of free (not in use) chunks */
+  int aordblks; /* This is the number of allocated (in use) chunks */
   int mxordblk; /* Size of the largest free (not in use) chunk */
   int uordblks; /* This is the total size of memory occupied by
                  * chunks handed out by malloc. */
diff --git a/mm/mm_heap/mm_mallinfo.c b/mm/mm_heap/mm_mallinfo.c
index e58d494..2b211bb 100644
--- a/mm/mm_heap/mm_mallinfo.c
+++ b/mm/mm_heap/mm_mallinfo.c
@@ -51,6 +51,7 @@ int mm_mallinfo(FAR struct mm_heap_s *heap, FAR struct mallinfo *info)
   FAR struct mm_allocnode_s *prev;
   size_t mxordblk = 0;
   int    ordblks  = 0;  /* Number of non-inuse chunks */
+  int    aordblks = 0;  /* Number of inuse chunks */
   size_t uordblks = 0;  /* Total allocated space */
   size_t fordblks = 0;  /* Total non-inuse space */
 #if CONFIG_MM_REGIONS > 1
@@ -92,6 +93,7 @@ int mm_mallinfo(FAR struct mm_heap_s *heap, FAR struct mallinfo *info)
           if ((node->preceding & MM_ALLOC_BIT) != 0)
             {
               DEBUGASSERT(node->size >= SIZEOF_MM_ALLOCNODE);
+              aordblks++;
               uordblks += node->size;
             }
           else
@@ -133,6 +135,7 @@ int mm_mallinfo(FAR struct mm_heap_s *heap, FAR struct mallinfo *info)
 
   info->arena    = heap_impl->mm_heapsize;
   info->ordblks  = ordblks;
+  info->aordblks = aordblks;
   info->mxordblk = mxordblk;
   info->uordblks = uordblks;
   info->fordblks = fordblks;