mm/vmstat: add events for ksm cow
Subsystems (2)
PATCH v3 1/1 mm/vmstat: add events for ksm cow
From: Yang Yang <[email protected]>
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.
---
v2:
- fix compile error when CONFIG_KSM is not set
v3:
- delete KSM_COW_FAIL event
--- include/linux/vm_event_item.h | 1 + mm/memory.c | 4 ++++ mm/vmstat.c | 1 + 3 files changed, 6 insertions(+)
include/linux/vm_event_item.h +1 -0
@@ -131,6 +131,7 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT, SWAP_RA_HIT,#ifdef CONFIG_KSM KSM_SWPIN_COPY, + COW_KSM,#endif #endif #ifdef CONFIG_X86
mm/memory.c +4 -0
@@ -3339,6 +3339,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); }
mm/vmstat.c +1 -0
@@ -1390,6 +1390,7 @@ const char * const vmstat_text[] = {"swap_ra_hit" , #ifdef CONFIG_KSM"ksm_swpin_copy" , +"cow_ksm" , #endif #endif #ifdef CONFIG_X86
Signature · 1 line
2.25.1
include/linux/vm_event_item.h enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT, · line 134
Quoted 6 lines · On Thu, Mar 24, 2022 at 10:43:33AM +0000, [email protected] wrote:
+++
b/include/linux/vm_event_item.hinclude/linux/vm_event_item.h +1
-0@@ -131,6 +131,7 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT, SWAP_RA_HIT,#ifdef CONFIG_KSM KSM_SWPIN_COPY , + COW_KSM,
Shouldn't we call this KSM_COW?
mm/vmstat.c const char * const vmstat_text[] = { · line 1393
Quoted 6 lines
mm/vmstat.c +2
-0+++ b/mm/vmstat.c@@ -1390,6 +1390,7 @@ const char * const vmstat_text[] = {"swap_ra_hit" , #ifdef CONFIG_KSM"ksm_swpin_copy" , + "cow_ksm",
... and this "ksm_cow"?
Quoted 9 lines · Matthew Wilcox
include/linux/vm_event_item.h enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT, · line 134
Quoted 6 lines · On Thu, Mar 24, 2022 at 10:43:33AM +0000, [email protected] wrote:
+++
b/include/linux/vm_event_item.hinclude/linux/vm_event_item.h +1
-0@@ -131,6 +131,7 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT, SWAP_RA_HIT,#ifdef CONFIG_KSM KSM_SWPIN_COPY , + COW_KSM,Shouldn't we call this
KSM_COW?
I guess I proposed COW_KSM because ideally we'll have COW_ANON, COW_ZERO, COW_OTHER, ... so it'd be under the "COW" namespace. No strong opinion, though.
Signature · 3 lines
Thanks, David / dhildenb
Andrew Morton
maintainerQuoted 9 lines · On Thu, 24 Mar 2022 10:43:33 +0000 [email protected] wrote:
From: Yang Yang <[email protected]>
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.
It's unclear (to me) how anyone will actually use this, how they will interpret the output.
Some tutorial words added to Documentation/vm/ksm.rst would be helpful. While in there, please check for any other /proc/vmstat fields which we forgot to document.
include/linux/vm_event_item.h enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT, · line 134
Quoted 7 lines
include/linux/vm_event_item.h +1
-0@@ -131,6 +131,7 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT, SWAP_RA_HIT,#ifdef CONFIG_KSM KSM_SWPIN_COPY , + COW_KSM,
I agree that this name looks unpleasingly backwards. Do we have an expectation that we actually will be adding more COW_* fields?
Quoted 19 lines · Andrew Morton
Quoted 9 lines · On Thu, 24 Mar 2022 10:43:33 +0000 [email protected] wrote:
From: Yang Yang <[email protected]>
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.
It's unclear (to me) how anyone will actually use this, how they will interpret the output.
Some tutorial words added to
Documentation/vm/ksm.rstwould be helpful. While in there, please check for any other/proc/vmstatfields which we forgot to document.
Quoted 10 lines
include/linux/vm_event_item.h enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT, · line 134
Quoted 7 lines
include/linux/vm_event_item.h +1
-0@@ -131,6 +131,7 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT, SWAP_RA_HIT,#ifdef CONFIG_KSM KSM_SWPIN_COPY , + COW_KSM,I agree that this name looks unpleasingly backwards. Do we have an expectation that we actually will be adding more COW_* fields?
As raised previously (also when proposing this), I'd like to have COW_ANON, COW_ZERO, COW_OTHER. Ideally, we'd have added all via a single patch for them. They would at least be of value to me.
Signature · 3 lines
Thanks, David / dhildenb