]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsmem: display global memmap on memory parameter
authorSumanth Korikkar <sumanthk@linux.ibm.com>
Thu, 16 Oct 2025 15:38:01 +0000 (17:38 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 7 Nov 2025 09:25:59 +0000 (10:25 +0100)
Display the output of global memmap-on-memory parameter for memory
hotplug. Retrieve the details via
/sys/module/memory_hotplug/parameters/memmap_on_memory.

lsmem
RANGE                                 SIZE  STATE REMOVABLE BLOCK
0x0000000000000000-0x00000001ffffffff   8G online       yes  0-63

Memory block size:                128M
Total online memory:                8G
Total offline memory:               0B
Memmap on memory parameter:        yes

Signed-off-by: Sumanth Korikkar <sumanthk@linux.ibm.com>
sys-utils/lsmem.1.adoc
sys-utils/lsmem.c

index d588051a816b1c5df070fd596460b97adbbe1b29..9c9397631a4bd0e4783de5632c7e9b950e616ab5 100644 (file)
@@ -28,6 +28,8 @@ Not all columns are supported on all systems. If an unsupported column is specif
 
 Use the *--help* option to see the columns description.
 
+Memmap on memory parameter output displays the globally enabled memmap-on-memory setting for memory_hotplug. This is typically set on the kernel command line via memory_hotplug.memmap_on_memory.
+
 == OPTIONS
 
 *-a*, *--all*::
index 39967bfc9628d5fa773812a6f2a06e8365993a90..6151e269ff726b314637ecc67a925ae246f0d25e 100644 (file)
@@ -32,6 +32,7 @@
 #include "optutils.h"
 
 #define _PATH_SYS_MEMORY               "/sys/devices/system/memory"
+#define _PATH_SYS_MEMMAP_PARM          "/sys/module/memory_hotplug/parameters/memmap_on_memory"
 
 #define MEMORY_STATE_ONLINE            0
 #define MEMORY_STATE_OFFLINE           1
@@ -306,8 +307,24 @@ static void fill_scols_table(struct lsmem *lsmem)
                add_scols_line(lsmem, &lsmem->blocks[i]);
 }
 
+static int get_memmap_mode(char *res, char *src, int len)
+{
+       if (!strncmp(src, "Y", 1))
+               strncpy(res, N_("yes"), len);
+       else if (!strncmp(src, "N", 1))
+               strncpy(res, N_("no"), len);
+       else if (!strncmp(src, "force", 5))
+               strncpy(res, N_("force"), len);
+       else
+               return -1;
+       return 0;
+}
+
 static void print_summary(struct lsmem *lsmem)
 {
+       char buf[8], res[8];
+       FILE *memmap;
+
        if (lsmem->bytes) {
                printf("%-32s %15"PRId64"\n",_("Memory block size:"), lsmem->block_size);
                printf("%-32s %15"PRId64"\n",_("Total online memory:"), lsmem->mem_online);
@@ -327,6 +344,18 @@ static void print_summary(struct lsmem *lsmem)
                        printf("%-32s %5s\n",_("Total offline memory:"), p);
                free(p);
        }
+       memmap = fopen(_PATH_SYS_MEMMAP_PARM, "r");
+       if (!memmap)
+               return;
+       if (fgets(buf, sizeof(buf), memmap)) {
+               if (!get_memmap_mode(res, buf, sizeof(res))) {
+                       if (lsmem->bytes)
+                               printf("%-32s %15s\n", _("Memmap on memory parameter:"), _(res));
+                       else
+                               printf("%-32s %5s\n", _("Memmap on memory parameter:"), _(res));
+               }
+       }
+       fclose(memmap);
 }
 
 static int memory_block_get_node(struct lsmem *lsmem, char *name)