From patchwork Wed Oct 4 19:02:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13409343 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 12844E7C4ED for ; Wed, 4 Oct 2023 19:03:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 111A88D00B2; Wed, 4 Oct 2023 15:03:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EEF5F8D00AE; Wed, 4 Oct 2023 15:03:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CF2C68D00B0; Wed, 4 Oct 2023 15:03:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id BF5F38D00AE for ; Wed, 4 Oct 2023 15:03:20 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 7B458120404 for ; Wed, 4 Oct 2023 19:03:20 +0000 (UTC) X-FDA: 81308702160.10.3D9684E Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf27.hostedemail.com (Postfix) with ESMTP id C41364002D for ; Wed, 4 Oct 2023 19:03:18 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf27.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1696446198; 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=IrnoYKEsaMdrdPk/QW6pcNkJHjkVEFDhjGBdxi2+XMU=; b=7kYFGtYoihGPRGW0MqibQ0qQZVHdIqRrQjKo/ArrkiL/zcYlPQVj2s81sfxKJpO4offA+D hpu1Xdh+dfc8KZhXez2qJTzOsmjQ/vqve0kL0oWFUwBSbA8XDhgdk+f7OxVdKDq88xlNcK hSNPI8YmD86oeFLEvNmXam5f/MIY47E= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf27.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696446198; a=rsa-sha256; cv=none; b=zmNJiEy5baxlzVsV81Fk2l/Gwlqp6G4Mx9lm4QhWkja+YsTya+UasJe0hPSl9qbVnSbq2d tErFD/N7gvdlvdKf4+91ansRrNpl2k1eHUxrkoOFnm6+/vdaqfKXkIXkeal5wcx9jRM4WA wblMAzD2epnz8i12qYZO+cjn6gG+8qw= Received: by devbig1114.prn1.facebook.com (Postfix, from userid 425415) id 0F49CD08C004; Wed, 4 Oct 2023 12:03:03 -0700 (PDT) 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 v1 4/4] mm/ksm: document ksm advisor and its sysfs knobs Date: Wed, 4 Oct 2023 12:02:49 -0700 Message-Id: <20231004190249.829015-5-shr@devkernel.io> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20231004190249.829015-1-shr@devkernel.io> References: <20231004190249.829015-1-shr@devkernel.io> MIME-Version: 1.0 X-Rspamd-Queue-Id: C41364002D X-Rspam-User: X-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dpyHFbiIEpxtUvInIx+sA 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: 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 | 45 ++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/Documentation/admin-guide/mm/ksm.rst b/Documentation/admin-guide/mm/ksm.rst index e59231ac6bb7..8de93650d3b0 100644 --- a/Documentation/admin-guide/mm/ksm.rst +++ b/Documentation/admin-guide/mm/ksm.rst @@ -164,6 +164,25 @@ 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: 0 (None) and 1 (Scan time). The default is None. By + setting ``advisor_mode`` to 1, the scan time advisor is enabled. + The section about ``advisor`` explains in detail how the scan time + advisor works. + +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 5000. + +advisor_target_scan_time + specifies the target scan time in seconds to scan all the candidate + pages. The default value is 200 seconds. + The effectiveness of KSM and MADV_MERGEABLE is shown in ``/sys/kernel/mm/ksm/``: general_profit @@ -263,6 +282,32 @@ 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: 0 (None) and +1 (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_min_pages`` and ``advisor_max_pages`` parameters. 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 ``pages_to_scan`` parameter is re-calculated after a scan has been completed. + + -- Izik Eidus, Hugh Dickins, 17 Nov 2009