linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: xu.xin16@zte.com.cn, akpm@linux-foundation.org
Cc: linux-kernel@vger.kernel.org, wang.yaxin@zte.com.cn,
	linux-mm@kvack.org, linux-fsdevel@vger.kernel.org,
	yang.yang29@zte.com.cn
Subject: Re: [PATCH v5] ksm: add ksm involvement information for each process
Date: Mon, 13 Jan 2025 10:18:54 +0100	[thread overview]
Message-ID: <ba714a36-dc46-49dc-af6d-aeced26295e1@redhat.com> (raw)
In-Reply-To: <20250110174034304QOb8eDoqtFkp3_t8mqnqc@zte.com.cn>

On 10.01.25 10:40, xu.xin16@zte.com.cn wrote:
> From: xu xin <xu.xin16@zte.com.cn>
> 
> In /proc/<pid>/ksm_stat, Add two extra ksm involvement items including
> KSM_mergeable and KSM_merge_any. It helps administrators to
> better know the system's KSM behavior at process level.
> 
> ksm_merge_any: yes/no
> 	whether the process'mm is added by prctl() into the candidate list
> 	of KSM or not, and fully enabled at process level.
> 
> ksm_mergeable: yes/no
>      whether any VMAs of the process'mm are currently applicable to KSM.
> 
> Purpose
> =======
> These two items are just to improve the observability of KSM at process
> level, so that users can know if a certain process has enable KSM.

s/enable/enabled/

> 
> For example, if without these two items, when we look at
> /proc/<pid>/ksm_stat and there's no merging pages found, We are not sure
> whether it is because KSM was not enabled or because KSM did not
> successfully merge any pages.
> 
> Althrough "mg" in /proc/<pid>/smaps indicate VM_MERGEABLE, it's opaque

s/Althrough/Although/

> and not very obvious for non professionals.
> 
> Signed-off-by: xu xin <xu.xin16@zte.com.cn>
> Cc: Wang Yaxin <wang.yaxin@zte.com.cn>
> ---
> Changelog v4 -> v5:
> 1. Update the documentation.
> 2. Correct a comment sentence and add purpose statment in commit message.
> ---
>   Documentation/filesystems/proc.rst | 66 ++++++++++++++++++++++++++++++++++++++
>   fs/proc/base.c                     | 11 +++++++
>   include/linux/ksm.h                |  1 +
>   mm/ksm.c                           | 19 +++++++++++
>   4 files changed, 97 insertions(+)
> 
> diff --git a/Documentation/filesystems/proc.rst b/Documentation/filesystems/proc.rst
> index 6a882c57a7e7..916f83203de0 100644
> --- a/Documentation/filesystems/proc.rst
> +++ b/Documentation/filesystems/proc.rst
> @@ -48,6 +48,7 @@ fixes/update part 1.1  Stefani Seibold <stefani@seibold.net>    June 9 2009
>     3.11	/proc/<pid>/patch_state - Livepatch patch operation state
>     3.12	/proc/<pid>/arch_status - Task architecture specific information
>     3.13  /proc/<pid>/fd - List of symlinks to open files
> +  3.14  /proc/<pid/ksm_stat - Information about the process' ksm status.
> 
>     4	Configuring procfs
>     4.1	Mount options
> @@ -2232,6 +2233,71 @@ The number of open files for the process is stored in 'size' member
>   of stat() output for /proc/<pid>/fd for fast access.
>   -------------------------------------------------------
> 
> +3.14 /proc/<pid/ksm_stat - Information about the process' ksm status
> +--------------------------------------------------------------------
> +When CONFIG_KSM is enabled, each process has this file which displays
> +the information of ksm merging status.
> +
> +Example
> +~~~~~~~
> +
> +::
> +
> +    / # cat /proc/self/ksm_stat
> +    ksm_rmap_items 0
> +    ksm_zero_pages 0
> +    ksm_merging_pages 0
> +    ksm_process_profit 0
> +    ksm_merge_any: no
> +    ksm_mergeable: no
> +
> +Description
> +~~~~~~~~~~~
> +
> +ksm_rmap_items
> +^^^^^^^^^^^^^^
> +
> +The number of ksm_rmap_item structure in use. The structure of

structures

> +ksm_rmap_item is to store the reverse mapping information for virtual

is to store -> stores?

> +addresses. KSM will generate a ksm_rmap_item for each ksm-scanned page
> +of the process.

Is it really each

> +
> +ksm_zero_pages
> +^^^^^^^^^^^^^^
> +
> +When /sys/kernel/mm/ksm/use_zero_pages is enabled, it represent how many
> +empty pages are merged with kernel zero pages by KSM.
> +
> +ksm_merging_pages
> +^^^^^^^^^^^^^^^^^
> +
> +It represents how many pages of this process are involved in KSM merging
> +(not including ksm_zero_pages). It is the same with what
> +/proc/<pid>/ksm_merging_pages shows.
 > +> +ksm_process_profit
> +^^^^^^^^^^^^^^^^^^
> +
> +The profit that KSM brings (Saved bytes). KSM can save memory by merging
> +identical pages, but also can consume additional memory, because it needs
> +to generate a number of rmap_items to save each scanned page's brief rmap
> +information. Some of these pages may be merged, but some may not be abled
> +to be merged after being checked several times, which are unprofitable
> +memory consumed.
> +
> +ksm_merge_any
> +^^^^^^^^^^^^^
> +
> +It specifies whether the process'mm is added by prctl() into the candidate list

Shows whether ... ?

> +of KSM or not, and KSM scanning is fully enabled at process level.
> +
> +ksm_mergeable
> +^^^^^^^^^^^^^
> +
> +It specifies whether any VMAs of the process'mm are currently applicable to KSM.

Shows whether ... ?

"any VMA"



Apart from that LGTM

Acked-by: David Hildenbrand <david@redhat.com>

-- 
Cheers,

David / dhildenb



  parent reply	other threads:[~2025-01-13  9:19 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-10  9:40 xu.xin16
2025-01-11  0:45 ` Andrew Morton
2025-01-13  9:18 ` David Hildenbrand [this message]
2025-01-14 15:46 ` Mario Casquero

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ba714a36-dc46-49dc-af6d-aeced26295e1@redhat.com \
    --to=david@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=wang.yaxin@zte.com.cn \
    --cc=xu.xin16@zte.com.cn \
    --cc=yang.yang29@zte.com.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox