From patchwork Mon Dec 4 23:49:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 173602 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3110432vqy; Mon, 4 Dec 2023 15:50:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IHvNicjwrWNlelB4KXVX7AGMTGpLzS4cG0XxuKiMy0FbqYka1YkaTZEdzAVol0rMG9zRV9m X-Received: by 2002:a17:90b:17c7:b0:285:b6a6:c40b with SMTP id me7-20020a17090b17c700b00285b6a6c40bmr339832pjb.42.1701733848718; Mon, 04 Dec 2023 15:50:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701733848; cv=none; d=google.com; s=arc-20160816; b=o/3OJ7MJahrXcPjA4D5W+BQ1nFY9LuIeO3XwWHLh61FL8PuyPl0LZKGsRuZ3ydfUqK Cu0ouQ8/rb1HcUBOE2ZrBUPC41EYLSIQOW+KbtciV5Ip2OONAfsUgt/ORh1AIyxIMO79 kl7SgQjpZ9e1tOPs/BmtP4AfGGCxlMS/5BPPOLMFRhi6JI6HURGvC4CWokt905VtakpZ 42LGf61X88v+JCX3LBu1JFxGWvYd60EeyUvl7u+XEbXRXgqvITzbut3b9U7mRXcgtig2 vKZM9QziOO/LSOPnHB+TUFxTriH11BRFTDxzo7j2FkfzAoRCn1A6ZfT7sEC0u9uNPVwP 18gg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=LZorcygG4jZkuFwNCG5i1dAxxLHjOAqJDWOY87GS9rg=; fh=sS+J4OyOC0EcVLWJpS3mBHGeO+0+dYZJ+ImCUfzsrH4=; b=XMD7I6IM91LhIbhHxDP2j9bS2nhGv2vZp3V54PnlAqhOZt1rnMAUKeLL2z/5NmGXoZ +uohQStCAAM5rg9n6RETozBu7393q+mMOxbwi3CLDBwz0h3bQp6Q+5fmBRVfNKKH5Ryz iVb7OuO7fExP37z5vvC8JpZSJ7yXeNePUlWzBp468Aq+fVrWLqqaPZAcXbTdhkcbJtTU J5aGHFzyDMuPwfb61wq3Mv+Jt/aRnq4lYFj7Vqxiz67VAFp/bdyfn+blQaggyWukxjMp OcqCExCz6o5M550lBq8xFb8OO1pyRvXfK3QJx9cpGB1D6pajpxG0bkySQ3Z0SfDnuAz+ TxSw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id j5-20020a170902da8500b001cfc170c11asi1806815plx.475.2023.12.04.15.50.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 15:50:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id EDE5B8097A61; Mon, 4 Dec 2023 15:50:19 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343583AbjLDXtV (ORCPT + 99 others); Mon, 4 Dec 2023 18:49:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234764AbjLDXtP (ORCPT ); Mon, 4 Dec 2023 18:49:15 -0500 Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0C43102 for ; Mon, 4 Dec 2023 15:49:21 -0800 (PST) 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 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Mon, 04 Dec 2023 15:50:20 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784397272145393605 X-GMAIL-MSGID: 1784397272145393605 This documents the KSM advisor and its new knobs in /sys/fs/kernel/mm. Signed-off-by: Stefan Roesch Acked-by: David Hildenbrand --- Documentation/admin-guide/mm/ksm.rst | 54 ++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/Documentation/admin-guide/mm/ksm.rst b/Documentation/admin-guide/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``. + The pages_to_scan value cannot be changed if ``advisor_mode`` has + been set to scan-time. + Default: 100 (chosen for demonstration purposes) sleep_millisecs @@ -164,6 +167,29 @@ smart_scan optimization is enabled. The ``pages_skipped`` metric shows how effective the setting is. +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 time + 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 candidate + 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/``: general_profit @@ -263,6 +289,34 @@ ksm_swpin_copy 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. +Advisor +======= + +The number of candidate pages for KSM is dynamic. It can be often observed +that during the startup of an application more candidate pages need to be +processed. Without an advisor the ``pages_to_scan`` parameter needs to be +sized for the maximum number of candidate pages. The scan time advisor can +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 and +scan-time. With none, no advisor is enabled. The default is none. + +The scan time advisor changes the ``pages_to_scan`` parameter based on the +observed scan times. The possible values for the ``pages_to_scan`` parameter is +limited by the ``advisor_max_cpu`` parameter. In addition there is also the +``advisor_target_scan_time`` parameter. This parameter sets the target time to +scan all the KSM candidate pages. The parameter ``advisor_target_scan_time`` +decides how aggressive the scan time advisor scans candidate pages. Lower +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_min_pages`` +and ``advisor_max_pages``. The default values are sufficient for most workloads. + +The ``pages_to_scan`` parameter is re-calculated after a scan has been completed. + + -- Izik Eidus, Hugh Dickins, 17 Nov 2009