linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH linux-next v2] ksm: add ksm involvement information for each process
@ 2024-04-26  1:46 xu.xin16
  2024-04-26  8:13 ` David Hildenbrand
  0 siblings, 1 reply; 3+ messages in thread
From: xu.xin16 @ 2024-04-26  1:46 UTC (permalink / raw)
  To: akpm, david; +Cc: linux-kernel, linux-fsdevel, shr

From: xu xin <xu.xin16@zte.com.cn>

In /proc/<pid>/ksm_stat, Add two extra ksm involvement items including
MMF_VM_MERGEABLE and MMF_VM_MERGE_ANY. It helps administrators to
better know the system's KSM behavior at process level.

KSM_mergeable: yes/no
	whether the process'mm is added by madvise() into the candidate list
	of KSM or not.
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.

Changelog
=========
v1 -> v2:
	replace the internal flag names with straightforward strings.
	* MMF_VM_MERGEABLE -> KSM_mergeable
	* MMF_VM_MERGE_ANY -> KSM_merge_any

Signed-off-by: xu xin <xu.xin16@zte.com.cn>
---
 fs/proc/base.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/fs/proc/base.c b/fs/proc/base.c
index 18550c071d71..50e808ffcda4 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -3217,6 +3217,10 @@ static int proc_pid_ksm_stat(struct seq_file *m, struct pid_namespace *ns,
 		seq_printf(m, "ksm_zero_pages %lu\n", mm->ksm_zero_pages);
 		seq_printf(m, "ksm_merging_pages %lu\n", mm->ksm_merging_pages);
 		seq_printf(m, "ksm_process_profit %ld\n", ksm_process_profit(mm));
+		seq_printf(m, "KSM_mergeable: %s\n",
+				test_bit(MMF_VM_MERGEABLE, &mm->flags) ? "yes" : "no");
+		seq_printf(m, "KSM_merge_any: %s\n",
+				test_bit(MMF_VM_MERGE_ANY, &mm->flags) ? "yes" : "no");
 		mmput(mm);
 	}

-- 
2.15.2

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH linux-next v2] ksm: add ksm involvement information for each process
  2024-04-26  1:46 [PATCH linux-next v2] ksm: add ksm involvement information for each process xu.xin16
@ 2024-04-26  8:13 ` David Hildenbrand
  2024-05-11  8:12   ` xu xin
  0 siblings, 1 reply; 3+ messages in thread
From: David Hildenbrand @ 2024-04-26  8:13 UTC (permalink / raw)
  To: xu.xin16, akpm; +Cc: linux-kernel, linux-fsdevel, shr

On 26.04.24 03:46, 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
> MMF_VM_MERGEABLE and MMF_VM_MERGE_ANY. It helps administrators to
> better know the system's KSM behavior at process level.
> 
> KSM_mergeable: yes/no
> 	whether the process'mm is added by madvise() into the candidate list
> 	of KSM or not.
> 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.
> 

Thinking about it, we should avoid exposing internal toggles with 
unclear semantics to the user. See below.

> Changelog
> =========
> v1 -> v2:
> 	replace the internal flag names with straightforward strings.
> 	* MMF_VM_MERGEABLE -> KSM_mergeable
> 	* MMF_VM_MERGE_ANY -> KSM_merge_any
> 
> Signed-off-by: xu xin <xu.xin16@zte.com.cn>
> ---
>   fs/proc/base.c | 4 ++++
>   1 file changed, 4 insertions(+)
> 
> diff --git a/fs/proc/base.c b/fs/proc/base.c
> index 18550c071d71..50e808ffcda4 100644
> --- a/fs/proc/base.c
> +++ b/fs/proc/base.c
> @@ -3217,6 +3217,10 @@ static int proc_pid_ksm_stat(struct seq_file *m, struct pid_namespace *ns,
>   		seq_printf(m, "ksm_zero_pages %lu\n", mm->ksm_zero_pages);
>   		seq_printf(m, "ksm_merging_pages %lu\n", mm->ksm_merging_pages);
>   		seq_printf(m, "ksm_process_profit %ld\n", ksm_process_profit(mm));
> +		seq_printf(m, "KSM_mergeable: %s\n",
> +				test_bit(MMF_VM_MERGEABLE, &mm->flags) ? "yes" : "no");

All it *currently* means is "we called __ksm_enter()" once. It does not 
mean that KSM is still enabled for that process and that any VMA would 
be considered for merging.

I don't think we should expose this.

That information can be more reliably had by looking at

"/proc/pid/smaps" and looking for "mg".

Which tells you exactly if any VMA (and which) is currently applicable 
to KSM.


> +		seq_printf(m, "KSM_merge_any: %s\n",
> +				test_bit(MMF_VM_MERGE_ANY, &mm->flags) ? "yes" : "no");

This makes more sense to export. It's the same as reading 
prctl(PR_GET_MEMORY_MERGE).

The man page [1] calls it simply "KSM has been enabled for this 
process", so process-wide KSM compared to per-VMA KSM.

"KSM_enabled:"

*might* be more reasonable in the context of PR_SET_MEMORY_MERGE.

It wouldn't tell though if KSM is enabled on the system, though.


[1] 
https://lore.kernel.org/linux-mm/20230227220206.436662-1-shr@devkernel.io/T/

-- 
Cheers,

David / dhildenb


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH linux-next v2] ksm: add ksm involvement information for each process
  2024-04-26  8:13 ` David Hildenbrand
@ 2024-05-11  8:12   ` xu xin
  0 siblings, 0 replies; 3+ messages in thread
From: xu xin @ 2024-05-11  8:12 UTC (permalink / raw)
  To: david; +Cc: akpm, linux-fsdevel, linux-kernel, shr, si.hao, xu.xin16

>> @@ -3217,6 +3217,10 @@ static int proc_pid_ksm_stat(struct seq_file *m, struct pid_namespace *ns,
>>   		seq_printf(m, "ksm_zero_pages %lu\n", mm->ksm_zero_pages);
>>   		seq_printf(m, "ksm_merging_pages %lu\n", mm->ksm_merging_pages);
>>   		seq_printf(m, "ksm_process_profit %ld\n", ksm_process_profit(mm));
>> +		seq_printf(m, "KSM_mergeable: %s\n",
>> +				test_bit(MMF_VM_MERGEABLE, &mm->flags) ? "yes" : "no");
>
>All it *currently* means is "we called __ksm_enter()" once. It does not 
>mean that KSM is still enabled for that process and that any VMA would 
>be considered for merging.
>
>I don't think we should expose this.
>
>That information can be more reliably had by looking at
>
>"/proc/pid/smaps" and looking for "mg".
>
>Which tells you exactly if any VMA (and which) is currently applicable 
>to KSM.
>
>
>> +		seq_printf(m, "KSM_merge_any: %s\n",
>> +				test_bit(MMF_VM_MERGE_ANY, &mm->flags) ? "yes" : "no");
>
>This makes more sense to export. It's the same as reading 
>prctl(PR_GET_MEMORY_MERGE).
>
>The man page [1] calls it simply "KSM has been enabled for this 
>process", so process-wide KSM compared to per-VMA KSM.
>
>"KSM_enabled:"
>
>*might* be more reasonable in the context of PR_SET_MEMORY_MERGE.
>
>It wouldn't tell though if KSM is enabled on the system, though.
>

I agree it. But I hope admistrators can tell if the process enabled KSM-scan
by madvise or prctl. At this point, only "/proc/pid/smaps"  is not enough.

So can we add a item "KSM_enabled" which has three value as follows?

1) "prctl": KSM has been fully enabled for this process.

2) "madvise": KSM has been enabled on parts of VMA for this process.

3) "never": KSM has been never enabled for this process.

Just refer to the semantics of '/sys/kernel/mm/transparent_hugepage/enabled' 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-05-11  8:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-26  1:46 [PATCH linux-next v2] ksm: add ksm involvement information for each process xu.xin16
2024-04-26  8:13 ` David Hildenbrand
2024-05-11  8:12   ` xu xin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).