From: Sumanth Korikkar Date: Thu, 16 Oct 2025 15:38:01 +0000 (+0200) Subject: lsmem: display global memmap on memory parameter X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=52491bde50e0afadc6e8d6f840ccd17bf4df62e0;p=thirdparty%2Futil-linux.git lsmem: display global memmap on memory parameter 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 --- diff --git a/sys-utils/lsmem.1.adoc b/sys-utils/lsmem.1.adoc index d588051a8..9c9397631 100644 --- a/sys-utils/lsmem.1.adoc +++ b/sys-utils/lsmem.1.adoc @@ -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*:: diff --git a/sys-utils/lsmem.c b/sys-utils/lsmem.c index 39967bfc9..6151e269f 100644 --- a/sys-utils/lsmem.c +++ b/sys-utils/lsmem.c @@ -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)