]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
ksm: count zero pages for each process
authorxu xin <xu.xin16@zte.com.cn>
Fri, 30 Dec 2022 01:16:29 +0000 (09:16 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Fri, 10 Feb 2023 23:36:02 +0000 (15:36 -0800)
As the number of ksm zero pages is not included in ksm_merging_pages per
process when enabling use_zero_pages, it's unclear of how many actual
pages are merged by KSM.  To let users accurately estimate their memory
demands when unsharing KSM zero-pages, it's necessary to show KSM zero-
pages per process.

Since unsharing zero pages placed by KSM accurately is achieved, then
tracking empty pages merging and unmerging is not a difficult thing any
longer.

Since we already have /proc/<pid>/ksm_stat, just add the information of
zero_pages_sharing in it.

Link: https://lkml.kernel.org/r/202212300916292181912@zte.com.cn
Signed-off-by: xu xin <xu.xin16@zte.com.cn>
Cc: Claudio Imbrenda <imbrenda@linux.ibm.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Xuexin Jiang <jiang.xuexin@zte.com.cn>
Cc: Xiaokai Ran <ran.xiaokai@zte.com.cn>
Cc: Yang Yang <yang.yang29@zte.com.cn>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
fs/proc/base.c
include/linux/mm_types.h
mm/ksm.c

index 9e479d7d202b12c0ddf53e00975858162156db8a..ac9ebe972be0badb0560844ff1155d3b552c84fc 100644 (file)
@@ -3207,6 +3207,7 @@ static int proc_pid_ksm_stat(struct seq_file *m, struct pid_namespace *ns,
        mm = get_task_mm(task);
        if (mm) {
                seq_printf(m, "ksm_rmap_items %lu\n", mm->ksm_rmap_items);
+               seq_printf(m, "zero_pages_sharing %lu\n", mm->ksm_zero_pages_sharing);
                mmput(mm);
        }
 
index 56753d0f096d06591c5c2ff29b05b72fb212c7b3..3cd60243c625222f7077bd82c447b1136110e9ea 100644 (file)
@@ -729,7 +729,7 @@ struct mm_struct {
 #ifdef CONFIG_KSM
                /*
                 * Represent how many pages of this process are involved in KSM
-                * merging.
+                * merging (not including ksm_zero_pages_sharing).
                 */
                unsigned long ksm_merging_pages;
                /*
@@ -737,6 +737,11 @@ struct mm_struct {
                 * including merged and not merged.
                 */
                unsigned long ksm_rmap_items;
+               /*
+                * Represent how many empty pages are merged with kernel zero
+                * pages when enabling KSM use_zero_pages.
+                */
+               unsigned long ksm_zero_pages_sharing;
 #endif
 #ifdef CONFIG_LRU_GEN
                struct {
index 7ec1de787ebed27998343eedd11fc63f91b91277..31de9252f0452353310bca4912dbafeadca49e5c 100644 (file)
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -794,6 +794,7 @@ static inline void clean_rmap_item_zero_flag(struct ksm_rmap_item *rmap_item)
 {
        if (rmap_item->address & ZERO_PAGE_FLAG) {
                ksm_zero_pages_sharing--;
+               rmap_item->mm->ksm_zero_pages_sharing--;
                rmap_item->address &= PAGE_MASK;
        }
 }
@@ -2116,6 +2117,7 @@ static int try_to_merge_with_kernel_zero_page(struct ksm_rmap_item *rmap_item,
                        if (!err) {
                                rmap_item->address |= ZERO_PAGE_FLAG;
                                ksm_zero_pages_sharing++;
+                               rmap_item->mm->ksm_zero_pages_sharing++;
                        }
                } else {
                        /* If the vma is out of date, we do not need to continue. */