From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 00721C46CA0 for ; Mon, 4 Dec 2023 23:49:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 941A46B0085; Mon, 4 Dec 2023 18:49:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6AE6D6B0089; Mon, 4 Dec 2023 18:49:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4B1F56B0087; Mon, 4 Dec 2023 18:49:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 32F816B0085 for ; Mon, 4 Dec 2023 18:49:25 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 10C22A0D2E for ; Mon, 4 Dec 2023 23:49:25 +0000 (UTC) X-FDA: 81530779890.29.E11F24D Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf28.hostedemail.com (Postfix) with ESMTP id 72389C001A for ; Mon, 4 Dec 2023 23:49:22 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=none; spf=neutral (imf28.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1701733762; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LZorcygG4jZkuFwNCG5i1dAxxLHjOAqJDWOY87GS9rg=; b=YA2GF9uE5GuMIC9g6KeIcxykEzsBPrjTa3q3WjZAfhZWvVXS5yZOpAQZmGXg5X8jjn0AoR rDylWchx8F1LQCnv4R0qv4T+6/NpmmtXZrBlrOWtD7DaBD445BioH/bUagli7EKeUWJX6q GuCpwqYrgIjy3mjj96QdeED4riFXuA8= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=none; spf=neutral (imf28.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701733762; a=rsa-sha256; cv=none; b=dc9ok/sbYhOpiBXZXYzaWujZo9E1BrTEOAryzBX++yHUr16esSGP/X/Oh12ldpPGZHRo+4 OyQmp3A+l6olqqHneb9jT8wLNjbXA0CNqoNSA2x/m9mmijPDxAMg2GZK+29bpvJQskI0ov MITVNR9BQXAzsz2JlanXifyXYXbS5qA= Received: by devbig1114.prn1.facebook.com (Postfix, from userid 425415) id 057BB105D3A8C; Mon, 4 Dec 2023 15:49:09 -0800 (PST) From: Stefan Roesch 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 v3 4/4] mm/ksm: document ksm advisor and its sysfs knobs Date: Mon, 4 Dec 2023 15:49:06 -0800 Message-Id: <20231204234906.1237478-5-shr@devkernel.io> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20231204234906.1237478-1-shr@devkernel.io> References: <20231204234906.1237478-1-shr@devkernel.io> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 72389C001A X-Rspam-User: X-Stat-Signature: 6mxi4y68z7hkith1yg5q79318oj1o1hn X-Rspamd-Server: rspam01 X-HE-Tag: 1701733762-534088 X-HE-Meta: U2FsdGVkX1/yOz3664ss681zxygD5msZYYN0qJk/Vrug0zLQL637fXLERQAGH13KIFp90RldwtZy007MzOjhsXhgXZ0t/Ha5fF2LukS2P/P0d1tuVV1V90vMnwT/ZbIQl0f98e1SeVn6iwyQw3J7wrkJUKmEPtrky5Yx6owlTgTNmE23UXfmCe7y9F1RrG2tIHFcU24DpZt1nUC4DW//JBzkzNeeXZXHKO6Wu++ZqKkAxnQlDTQwuq/GIdogWU2RZDfLVfTV4GoitI5gwBUcLrpbzE1+aeax0hsxxh9D2rLUeiJNBAOfs9y3r7GSpPNoxgQ8rvapKDjhDqrH1H+JkVweNw/ovz6rCMksd5kw6tak6/shkUFFn/FEL3fvwTwuNWAx5M+zj7IPrPPZsHPWs0OQu9FjjpNLd4oMthOJRKGHX9pWZ0SApXFHMyF7UxacFmCLLKP8kZD8hB0tV02iUsIXPRyPmtxde97QlepYrD5UvGrJRFQUVIlWj4MMJ19lgBv1njQk0XTWI3zWCEg9KwBuSAAric36ex6nNWd6lzNkvvEDm6RdCI0febsu9enPBKAg9JAJOKnb2nsshTkT82NeXvV9mg6hpUVL7bq57l0OVKkbuCXsT7uMBij66IG+kn61c4aaCrUgwSI+DRGjM+W36X0jAFEkHEAV88zL2najBpqVTSqP1YbQ2X3zhhHP21MZ68pZiR34u0j2DwjpzrUVyi37UX2hGdoRs+NeaRE40rblfEl4fwFX93ts/p6jvyYBjEZUHkOPQOZyBUoy/Q6LfFDq2OJXTRzjnFqq2m6AeDOXZr79GL1XmtWgl8sBS9e1m10tuzXaYxwrDsQEbFnB0UwoeB4tv6xeyQrlzmveZj/Czpou586QgXvfNa2HdlQ/RF7Cqzpd4vSKY1XH1FGg7Qyrar9FAflXzGdImofOmOll2lZDnXK8pa5VG/1cDeTfsYtJxQg1PfxmD5d D+j175mv WqNRN/HIII5z2xQlZ3JG5Dh8H3Fa0YTbFyafg X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: This documents the KSM advisor and its new knobs in /sys/fs/kernel/mm. Signed-off-by: Stefan Roesch --- Documentation/admin-guide/mm/ksm.rst | 54 ++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/Documentation/admin-guide/mm/ksm.rst b/Documentation/admin-g= uide/mm/ksm.rst index e59231ac6bb71..297c4a0d04dee 100644 --- a/Documentation/admin-guide/mm/ksm.rst +++ b/Documentation/admin-guide/mm/ksm.rst @@ -80,6 +80,9 @@ pages_to_scan how many pages to scan before ksmd goes to sleep e.g. ``echo 100 > /sys/kernel/mm/ksm/pages_to_scan``. =20 + The pages_to_scan value cannot be changed if ``advisor_mode`` ha= s + been set to scan-time. + Default: 100 (chosen for demonstration purposes) =20 sleep_millisecs @@ -164,6 +167,29 @@ smart_scan optimization is enabled. The ``pages_skipped`` metric shows how effective the setting is. =20 +advisor_mode + The ``advisor_mode`` selects the current advisor. Two modes are + supported: none and scan-time. The default is none. By setting + ``advisor_mode`` to scan-time, the scan time advisor is enabled. + The section about ``advisor`` explains in detail how the scan ti= me + advisor works. + +adivsor_max_cpu + specifies the upper limit of the cpu percent usage of the ksmd + background thread. The default is 70. + +advisor_target_scan_time + specifies the target scan time in seconds to scan all the candid= ate + pages. The default value is 200 seconds. + +advisor_min_pages + specifies the lower limit of the ``pages_to_scan`` parameter of = the + scan time advisor. The default is 500. + +adivsor_max_pages + specifies the upper limit of the ``pages_to_scan`` parameter of = the + scan time advisor. The default is 30000. + The effectiveness of KSM and MADV_MERGEABLE is shown in ``/sys/kernel/mm= /ksm/``: =20 general_profit @@ -263,6 +289,34 @@ ksm_swpin_copy note that KSM page might be copied when swapping in because do_swap_pag= e() cannot do all the locking needed to reconstitute a cross-anon_vma KSM p= age. =20 +Advisor +=3D=3D=3D=3D=3D=3D=3D + +The number of candidate pages for KSM is dynamic. It can be often observ= ed +that during the startup of an application more candidate pages need to b= e +processed. Without an advisor the ``pages_to_scan`` parameter needs to b= e +sized for the maximum number of candidate pages. The scan time advisor c= an +changes the ``pages_to_scan`` parameter based on demand. + +The advisor can be enabled, so KSM can automatically adapt to changes in= the +number of candidate pages to scan. Two advisors are implemented: none an= d +scan-time. With none, no advisor is enabled. The default is none. + +The scan time advisor changes the ``pages_to_scan`` parameter based on t= he +observed scan times. The possible values for the ``pages_to_scan`` param= eter is +limited by the ``advisor_max_cpu`` parameter. In addition there is also = the +``advisor_target_scan_time`` parameter. This parameter sets the target t= ime to +scan all the KSM candidate pages. The parameter ``advisor_target_scan_ti= me`` +decides how aggressive the scan time advisor scans candidate pages. Lowe= r +values make the scan time advisor to scan more aggresively. This is the = most +important parameter for the configuration of the scan time advisor. + +The initial value and the maximum value can be changed with ``advisor_mi= n_pages`` +and ``advisor_max_pages``. The default values are sufficient for most wo= rkloads. + +The ``pages_to_scan`` parameter is re-calculated after a scan has been c= ompleted. + + -- Izik Eidus, Hugh Dickins, 17 Nov 2009 --=20 2.39.3