linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Roesch <shr@devkernel.io>
To: kernel-team@fb.com
Cc: shr@devkernel.io, akpm@linux-foundation.org, david@redhat.com,
	hannes@cmpxchg.org, riel@surriel.com,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: [PATCH v1 0/4] Smart scanning mode for KSM
Date: Tue, 12 Sep 2023 10:52:24 -0700	[thread overview]
Message-ID: <20230912175228.952039-1-shr@devkernel.io> (raw)

This patch series adds "smart scanning" for KSM.

What is smart scanning?
=======================
KSM evaluates all the candidate pages for each scan. It does not use historic
information from previous scans. This has the effect that candidate pages that
couldn't be used for KSM de-duplication continue to be evaluated for each scan.

The idea of "smart scanning" is to keep historic information. With the historic
information we can temporarily skip the candidate page for one or several scans.

Details:
========
"Smart scanning" is to keep two small counters to store if the page has been
used for KSM. One counter stores how often we already tried to use the page for
KSM and the other counter stores when a page will be used as a candidate page
again.

How often we skip the candidate page depends how often a page failed KSM
de-duplication. The code skips a maximum of 8 times. During testing this has
shown to be a good compromise for different workloads.

New sysfs knob:
===============
Smart scanning is not enabled by default. With /sys/kernel/mm/ksm/smart_scan
smart scanning can be enabled.

Monitoring:
===========
To monitor how effective smart scanning is a new sysfs knob has been introduced.
/sys/kernel/mm/pages_skipped report how many pages have been skipped by smart
scanning.

Results:
========
- Various workloads have shown a 20% - 25% reduction in page scans
  For the instagram workload for instance, the number of pages scanned has been
  reduced from over 20M pages per scan to less than 15M pages.
- Less pages scans also resulted in an overall higher de-duplication rate as
  some shorter lived pages could be de-duplicated additionally
- Less pages scanned allows to reduce the pages_to_scan parameter
  and this resulted in  a 25% reduction in terms of CPU.
- The improvements have been observed for workloads that enable KSM with
  madvise as well as prctl



Stefan Roesch (4):
  mm/ksm: add "smart" page scanning mode
  mm/ksm: add pages_skipped metric
  mm/ksm: document smart scan mode
  mm/ksm: document pages_skipped sysfs knob

 Documentation/admin-guide/mm/ksm.rst | 11 ++++
 mm/ksm.c                             | 87 ++++++++++++++++++++++++++++
 2 files changed, 98 insertions(+)


base-commit: 15bcc9730fcd7526a3b92eff105d6701767a53bb
-- 
2.39.3



             reply	other threads:[~2023-09-12 17:52 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-12 17:52 Stefan Roesch [this message]
2023-09-12 17:52 ` [PATCH v1 1/4] mm/ksm: add "smart" page scanning mode Stefan Roesch
2023-09-13 21:07   ` Andrew Morton
2023-09-18 18:47     ` Stefan Roesch
2023-09-18 11:10   ` David Hildenbrand
2023-09-18 16:18     ` Stefan Roesch
2023-09-18 16:54       ` David Hildenbrand
2023-09-18 17:22         ` Stefan Roesch
2023-09-12 17:52 ` [PATCH v1 2/4] mm/ksm: add pages_skipped metric Stefan Roesch
2023-09-18 11:28   ` David Hildenbrand
2023-09-12 17:52 ` [PATCH v1 3/4] mm/ksm: document smart scan mode Stefan Roesch
2023-09-18 11:28   ` David Hildenbrand
2023-09-12 17:52 ` [PATCH v1 4/4] mm/ksm: document pages_skipped sysfs knob Stefan Roesch
2023-09-18 11:28   ` David Hildenbrand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230912175228.952039-1-shr@devkernel.io \
    --to=shr@devkernel.io \
    --cc=akpm@linux-foundation.org \
    --cc=david@redhat.com \
    --cc=hannes@cmpxchg.org \
    --cc=kernel-team@fb.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=riel@surriel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox