From patchwork Sat Oct 28 00:09:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13439318 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 E8E18C27C47 for ; Sat, 28 Oct 2023 00:13:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 462296B03FF; Fri, 27 Oct 2023 20:13:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 412CC6B0400; Fri, 27 Oct 2023 20:13:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 301076B0401; Fri, 27 Oct 2023 20:13:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 217AD6B03FF for ; Fri, 27 Oct 2023 20:13:00 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id EEA93C0ED7 for ; Sat, 28 Oct 2023 00:12:58 +0000 (UTC) X-FDA: 81392944836.29.0BB8ED0 Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf13.hostedemail.com (Postfix) with ESMTP id 69B1020017 for ; Sat, 28 Oct 2023 00:12:57 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=none; spf=neutral (imf13.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=1698451977; 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=h32iBnhLVg6ZmUoj8PAweva7s48LAK0ljHaKrtYPXVM=; b=QWzro4nhHT67YAwlbFDj8s7/grfX9FXHe0n57rwe6WQmcBJMP166VD6qj8bP9W3hv7TjWD mer8DaP65MTmfM16hSMjZjdynz0kMt9KePl+XLPIEzqC9iPX0FaKTVEZHx7/ROHMlDpN24 2o4GyNraDQmKbNsKRN2jy050pkCB9hw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698451977; a=rsa-sha256; cv=none; b=YXAR9NREz8soM/24MtffdU/V6CZw0k6MZh/hw85gJ7psfwXz1YfIMRHd3FwmaGdZRBbYO3 uT2lBboTV9KFfiCII9hSuVJMjxJyctxkuKDVHKewaclNqGxnWWwlFbYssan47cKzNiXcOR PzeR29cBQbslYcTerZm00kvB7RYN7TU= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=none; spf=neutral (imf13.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io; dmarc=none Received: by devbig1114.prn1.facebook.com (Postfix, from userid 425415) id 762FBE5A2603; Fri, 27 Oct 2023 17:10:28 -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 v2 4/4] mm/ksm: document ksm advisor and its sysfs knobs Date: Fri, 27 Oct 2023 17:09:45 -0700 Message-Id: <20231028000945.2428830-5-shr@devkernel.io> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20231028000945.2428830-1-shr@devkernel.io> References: <20231028000945.2428830-1-shr@devkernel.io> MIME-Version: 1.0 X-Rspamd-Queue-Id: 69B1020017 X-Rspam-User: X-Stat-Signature: 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B/a2gd1kTpBKg== 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 | 66 ++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/Documentation/admin-guide/mm/ksm.rst b/Documentation/admin-guide/mm/ksm.rst index e59231ac6bb7..7e956692b656 100644 --- a/Documentation/admin-guide/mm/ksm.rst +++ b/Documentation/admin-guide/mm/ksm.rst @@ -164,6 +164,33 @@ 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_cpu + specifies the lower limit of the cpu percent usage of the ksmd + background thread. The default is 15. + +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 +290,45 @@ 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 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_cpu`` and ``advisor_max_cpu`` 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 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