Re: [PATCH 1/6] lsmem: display global memmap on memory parameter

Karel Zak <[email protected]> Thu, 16 Oct 2025 12:51:46 +0200
Newsgroups org.kernel.vger.util-linux
Message-ID <qdeva54xge5ksrhpwcfe4dd2wv6x5re2ue5fkcguffs2ebvwgk@hk5yjjhv7p2p>
On Thu, Oct 16, 2025 at 12:16:48PM +0200, Sumanth Korikkar wrote:
> 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 <[email protected]>
> ---
>  sys-utils/lsmem.1.adoc |  2 ++
>  sys-utils/lsmem.c      | 29 +++++++++++++++++++++++++++++
>  2 files changed, 31 insertions(+)
> 
> 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..ea818d6dc 100644
> --- a/sys-utils/lsmem.c
> +++ b/sys-utils/lsmem.c
> @@ -306,8 +306,25 @@ 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, "yes", len);
> +	else if (!strncmp(src, "N", 1))
> +		strncpy(res, "no", len);
> +	else if (!strncmp(src, "force", 5))
> +		strncpy(res, "force", len);
> +	else
> +		return -1;
> +	return 0;

In other places, we translate these strings, so it should be
N_("yes"), etc, and use _() in the final printf().

> +}
> +
>  static void print_summary(struct lsmem *lsmem)
>  {
> +	const char *path = "/sys/module/memory_hotplug/parameters/memmap_on_memory";

We rarely use hardcoded paths directly in code in util-linux. How
about adding #define _PATH_SYS_MEMMAP_PARM or something similar.

    Karel

-- 
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com