Skip to content

Commit

Permalink
mm/vmstat: add events for ksm cow
Browse files Browse the repository at this point in the history
Users may use ksm by calling madvise(, , MADV_MERGEABLE) when they want
to save memory, it's a tradeoff by suffering delay on ksm cow. Users can
get to know how much memory ksm saved by reading
/sys/kernel/mm/ksm/pages_sharing, but they don't know what's the costs
of ksm cow, and this is important of some delay sensitive tasks.

So add ksm cow events to help users evaluate whether or how to use ksm.
Also update /Documentation/admin-guide/mm/ksm.rst with new added events.

Signed-off-by: Yang Yang <yang.yang29@zte.com.cn>
Reviewed-by: David Hildenbrand <david@redhat.com>
Reviewed-by: xu xin <xu.xin16@zte.com.cn>
Reviewed-by: Ran Xiaokai <ran.xiaokai@zte.com.cn>
  • Loading branch information
yangyang20220519 authored and intel-lab-lkp committed Mar 30, 2022
1 parent 673977c commit 48bd13b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Documentation/admin-guide/mm/ksm.rst
Expand Up @@ -184,6 +184,24 @@ The maximum possible ``pages_sharing/pages_shared`` ratio is limited by the
``max_page_sharing`` tunable. To increase the ratio ``max_page_sharing`` must
be increased accordingly.

Monitoring KSM events
=====================

There are some counters in /proc/vmstat that may be used to monitor KSM events.
KSM might help save memory, it's a tradeoff by may suffering delay on KSM COW
or on swapping in copy. Those events could help users evaluate whether or how
to use KSM. For example, if cow_ksm increases too fast, user may decrease the
range of madvise(, , MADV_MERGEABLE).

cow_ksm
is incremented every time a KSM page triggers copy on write (COW)
when users try to write to a KSM page, we have to make a copy.

ksm_swpin_copy
is incremented every time a KSM page is copied when swapping in
note that KSM page might be copied when swapping in because do_swap_page()
cannot do all the locking needed to reconstitute a cross-anon_vma KSM page.

--
Izik Eidus,
Hugh Dickins, 17 Nov 2009
1 change: 1 addition & 0 deletions include/linux/vm_event_item.h
Expand Up @@ -130,6 +130,7 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,
SWAP_RA,
SWAP_RA_HIT,
#ifdef CONFIG_KSM
COW_KSM,
KSM_SWPIN_COPY,
#endif
#endif
Expand Down
4 changes: 4 additions & 0 deletions mm/memory.c
Expand Up @@ -3331,6 +3331,10 @@ static vm_fault_t do_wp_page(struct vm_fault *vmf)
get_page(vmf->page);

pte_unmap_unlock(vmf->pte, vmf->ptl);
#ifdef CONFIG_KSM
if (PageKsm(vmf->page))
count_vm_event(COW_KSM);
#endif
return wp_page_copy(vmf);
}

Expand Down
1 change: 1 addition & 0 deletions mm/vmstat.c
Expand Up @@ -1390,6 +1390,7 @@ const char * const vmstat_text[] = {
"swap_ra",
"swap_ra_hit",
#ifdef CONFIG_KSM
"cow_ksm",
"ksm_swpin_copy",
#endif
#endif
Expand Down

0 comments on commit 48bd13b

Please sign in to comment.