Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5505560rdb; Wed, 13 Dec 2023 10:28:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IGE8NezbYJYMQ/iw+K02CL7v7fy+k5cXpU0R9XtbIb4/BpqKadJXN5mrOKQFd5oQR1ksa6/ X-Received: by 2002:a92:cd8d:0:b0:35d:6281:517 with SMTP id r13-20020a92cd8d000000b0035d62810517mr11743200ilb.11.1702492101389; Wed, 13 Dec 2023 10:28:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702492101; cv=none; d=google.com; s=arc-20160816; b=WNd7TTvoGqVXCk45IH8yXTTTT+HMdaGgwTDcNEoUgeUw2TZkS820pmQzbvN/oAzCmu NJkZK2CFCmdGLe1pRPYw//gn/HHRPys4uPSuD8JBYkoGHvAq798m356TUW51PIgcUXP6 xIBm96jpmO1jcMkZ8AnEa4fuGAROK3haty3xZ6+vdKrY1wauGASxAUTj7pWyZmnDy0H9 XV2YYCzulOoC7F/UKf4cbmGPZXJx8lhPxoyg7I9hDUb4DgInGzBLqHxmnFaOxf9pzMdP LeWBYlu5f0zp3caNZWW8v7ms9RJsGK9MEivVrRMngwm4ateC+aK+sX/0/8JLicE+YnnK hZfw== 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=oFkMIsv/KO1omoMMrIxz+uBzORyGY8S6CnCh+B+0uQ0=; fh=sS+J4OyOC0EcVLWJpS3mBHGeO+0+dYZJ+ImCUfzsrH4=; b=oX5BxiKX/OZ8Tkilc4k+c0D77JwM2jaYSblTwbuOESYGZHUL30NlNEYPklb7WpV8Bx pYJU9XHfqqaS89AxLdxI9nMAedPSJm0sWJu1tPiespL4bjGBnqNMnWYi0V2iPrGwGYfG 8DmH3YtIAnQ0goRTVhzPKD3tQZONWnutZAWa0k46YUqrAEHaO4wd4BN91n8m1ZpmJjYV MOQ2KUJVJZ1Rx9QadEqqn9W739kur/EgJe4+83HioQjbI33Bkf99ZMORg+OhkBvIhZnT hitpllleyrulcpqXklfdPn/fn+zF7WyFMqbSxCQ55+CJ30PIvp9zL1e+T/bIWbkOWev6 jEcw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id c22-20020a63da16000000b005bdd6196f4asi9708565pgh.392.2023.12.13.10.28.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 10:28:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (Postfix) with ESMTP id F2E34826EB8D; Wed, 13 Dec 2023 10:28:18 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442613AbjLMS1y (ORCPT + 99 others); Wed, 13 Dec 2023 13:27:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235536AbjLMS1k (ORCPT ); Wed, 13 Dec 2023 13:27:40 -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 E6FDB11B for ; Wed, 13 Dec 2023 10:27:46 -0800 (PST) Received: by devbig1114.prn1.facebook.com (Postfix, from userid 425415) id C6E0610CFA72F; Wed, 13 Dec 2023 10:27:33 -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 v4 4/4] mm/ksm: document ksm advisor and its sysfs knobs Date: Wed, 13 Dec 2023 10:27:29 -0800 Message-Id: <20231213182729.587081-5-shr@devkernel.io> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20231213182729.587081-1-shr@devkernel.io> References: <20231213182729.587081-1-shr@devkernel.io> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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 morse.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 (morse.vger.email [0.0.0.0]); Wed, 13 Dec 2023 10:28:19 -0800 (PST) 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 | 55 ++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/Documentation/admin-guide/mm/ksm.rst b/Documentation/admin-g= uide/mm/ksm.rst index e59231ac6bb71..a639cac124777 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_to_scan + specifies the lower limit of the ``pages_to_scan`` parameter of = the + scan time advisor. The default is 500. + +adivsor_max_pages_to_scan + 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,35 @@ 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_min_pages_to_scan`` and ``advisor_max_pages_to_scan``. The def= ault +values are sufficient for most workloads and use cases. + +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