ksm: add ksm involvement information for each process
Quoted 30 lines
Quoted 30 lines
In /proc/<pid>/ksm_stat, Add two extra ksm involvement items including
KSM_mergeableandKSM_merge_any. It helps administrators to better know the system's KSM behavior at process level.
KSM_mergeable: yes/no
whether any VMAs of the process'mm are currently applicable to KSM.
KSM_merge_any: yes/no
whether the process'mm is added byprctl()into the candidate list of KSM or not, and fully enabled at process level.Signed-off-by xu xin <[email protected]>---
Changelog
=========
v2 -> v3:
Update theKSM_mergeablegetting method: loop up if any vma is mergeable to KSM.
https://lore.kernel.org/all/[email protected]/v1 -> v2:
replace the internal flag names with straightforward strings.
*MMF_VM_MERGEABLE->KSM_mergeable
*MMF_VM_MERGE_ANY->KSM_merge_anyfs/proc/base.c | 4 ++++ include/linux/ksm.h | 1 + mm/ksm.c | 16 ++++++++++++++++ 3 files changed, 21 insertions(+)
Quoted 14 lines
fs/proc/base.c static int proc_pid_ksm_stat(struct seq_file *m, struct pid_namespace *ns, · line 3223
Quoted 12 lines
fs/proc/base.c +4
-0@@ -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" , +ksm_process_mergeable (mm) ?"yes" :"no" ); +seq_printf (m,"KSM_merge_any: %s\n" , +test_bit (MMF_VM_MERGE_ANY , &mm->flags) ?"yes" :"no" );Inconsistent "KSM" casing .
Excuse me, could you be more specific? I didn't get it
Quoted 23 lines
Quoted 23 lines
fs/proc/base.c +0
-0mmput (mm); }include/linux/ksm.h +1
-0@@ -84,6 +84,7 @@ void folio_migrate_ksm(struct folio *newfolio, struct folio *folio);void collect_procs_ksm (struct folio *folio,struct page *page,struct list_head *to_kill,int force_early);long ksm_process_profit (struct mm_struct *); +bool ksm_process_mergeable (struct mm_struct *mm);#else /* !CONFIG_KSM */ mm/ksm.c +0
-0@@ -3373,6 +3373,22 @@ static void wait_while_offlining(void)#endif /* CONFIG_MEMORY_HOTREMOVE */
Quoted 5 lines
mm/ksm.c static void wait_while_offlining(void) · line 3377
Quoted 3 lines
mm/ksm.c +2
-0#ifdef CONFIG_PROC_FS +/* +* The process is mergeable only if any VMA (and which) is currently confusing "(and which)"
Oh yes, I'll correct it
Quoted 16 lines
mm/ksm.c static void wait_while_offlining(void) · line 3388
Quoted 12 lines
mm/ksm.c +11
-0+* applicable to KSM. +*/ +bool ksm_process_mergeable (struct mm_struct *mm) +{ +struct vm_area_struct *vma; + +VMA_ITERATOR (vmi, mm,0 ); +for_each_vma (vmi, vma) +if (vma->vm_flags &VM_MERGEABLE ) +return true; +Are we holding the mmap lock here? I only see a
mmput()inproc_pid_ksm_stat()above, which might mean that we are not holding the mmap lock.
No, we'are missing the read lock of mmap. I'll fix it. Thanks a lot.
Quoted 45 lines · xu xin
Quoted 30 lines
Quoted 30 lines
In /proc/<pid>/ksm_stat, Add two extra ksm involvement items including
KSM_mergeableandKSM_merge_any. It helps administrators to better know the system's KSM behavior at process level.
KSM_mergeable: yes/no
whether any VMAs of the process'mm are currently applicable to KSM.
KSM_merge_any: yes/no
whether the process'mm is added byprctl()into the candidate list of KSM or not, and fully enabled at process level.Signed-off-by xu xin <[email protected]>---
Changelog
=========
v2 -> v3:
Update theKSM_mergeablegetting method: loop up if any vma is mergeable to KSM.
https://lore.kernel.org/all/[email protected]/v1 -> v2:
replace the internal flag names with straightforward strings.
*MMF_VM_MERGEABLE->KSM_mergeable
*MMF_VM_MERGE_ANY->KSM_merge_anyfs/proc/base.c | 4 ++++ include/linux/ksm.h | 1 + mm/ksm.c | 16 ++++++++++++++++ 3 files changed, 21 insertions(+)Quoted 14 lines
fs/proc/base.c static int proc_pid_ksm_stat(struct seq_file *m, struct pid_namespace *ns, · line 3223
Quoted 12 lines
fs/proc/base.c +4
-0@@ -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" , +ksm_process_mergeable (mm) ?"yes" :"no" ); +seq_printf (m,"KSM_merge_any: %s\n" , +test_bit (MMF_VM_MERGE_ANY , &mm->flags) ?"yes" :"no" );Inconsistent "KSM" casing .
Quoted 1 line
Excuse me, could you be more specific? I didn't get it
Everything is "ksm_" and you add "KSM_". Better keep that consistent.
Signature · 3 lines
Cheers, David / dhildenb