mm/vmstat: add event for ksm swapping in copy
authorYang Yang <yang.yang29@zte.com.cn>
Tue, 22 Mar 2022 21:46:33 +0000 (14:46 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 22 Mar 2022 22:57:09 +0000 (15:57 -0700)
When faults in from swap what used to be a KSM page and that page had been
swapped in before, system has to make a copy, and leaves remerging the
pages to a later pass of ksmd.

That is not good for performace, we'd better to reduce this kind of copy.
There are some ways to reduce it, for example lessen swappiness or
madvise(, , MADV_MERGEABLE) range.  So add this event to support doing
this tuning.  Just like this patch: "mm, THP, swap: add THP swapping out
fallback counting".

Link: https://lkml.kernel.org/r/20220113023839.758845-1-yang.yang29@zte.com.cn
Signed-off-by: Yang Yang <yang.yang29@zte.com.cn>
Reviewed-by: Ran Xiaokai <ran.xiaokai@zte.com.cn>
Cc: Hugh Dickins <hughd@google.com>
Cc: Yang Shi <yang.shi@linux.alibaba.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Saravanan D <saravanand@fb.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
include/linux/vm_event_item.h
mm/ksm.c
mm/vmstat.c

index 7b23633..16a0a4f 100644 (file)
@@ -129,6 +129,9 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,
 #ifdef CONFIG_SWAP
                SWAP_RA,
                SWAP_RA_HIT,
+#ifdef CONFIG_KSM
+               KSM_SWPIN_COPY,
+#endif
 #endif
 #ifdef CONFIG_X86
                DIRECT_MAP_LEVEL2_SPLIT,
index c20bd4d..4a7f861 100644 (file)
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -2595,6 +2595,9 @@ struct page *ksm_might_need_to_copy(struct page *page,
                SetPageDirty(new_page);
                __SetPageUptodate(new_page);
                __SetPageLocked(new_page);
+#ifdef CONFIG_SWAP
+               count_vm_event(KSM_SWPIN_COPY);
+#endif
        }
 
        return new_page;
index 846b670..d5cc8d7 100644 (file)
@@ -1388,6 +1388,9 @@ const char * const vmstat_text[] = {
 #ifdef CONFIG_SWAP
        "swap_ra",
        "swap_ra_hit",
+#ifdef CONFIG_KSM
+       "ksm_swpin_copy",
+#endif
 #endif
 #ifdef CONFIG_X86
        "direct_map_level2_splits",