Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp2813747rdb; Wed, 4 Oct 2023 12:11:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGIv+ehWMH4tYlA8Vloa7COF30UlKiuhfFfK4etp0Hd3B2oIx0nYQaGKcyu0UhIIvgOJ9Rt X-Received: by 2002:a17:90a:b90c:b0:273:e24e:36b9 with SMTP id p12-20020a17090ab90c00b00273e24e36b9mr3238768pjr.8.1696446715043; Wed, 04 Oct 2023 12:11:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696446715; cv=none; d=google.com; s=arc-20160816; b=hMORG+yZAL+DQr4SVJ4suzibGuEW0MrIjfglp6oCIazmyZL6ia+PYLMURUD0l+5DMa syYHkdVxAzkCq4SgAWroR9aUz8qk+lVVPA5tJTy4gHOO4LRu4eCmSKfnrALmfyw4k+Vg xtPQauSVUJax7RZno862FdjtZsouXCeASTydkjPghNCRZdymk2I4jKDsJqIDXqAMd91c alKrn9Bft1VzpYpXhz0ECl8ehN7yAFeaPaJphqgMR6B9FfSU9mFfaivgD8KKUkjNw7rb DbnFEDso71hqbVj5l0mdx7nVqyC1JtICCt4FdkU8mDgeiBMiQUPONrsci8dvaT7m9kWo wXcw== 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=IrnoYKEsaMdrdPk/QW6pcNkJHjkVEFDhjGBdxi2+XMU=; fh=sS+J4OyOC0EcVLWJpS3mBHGeO+0+dYZJ+ImCUfzsrH4=; b=CuAxXKomCkI1wLgiv1vMODhf8HuWAmZi0L1CEzoEqxatDANIou5m7UzozprBvSMvs1 ngwMU8VHUxVnb459cs7lj3J8w4yGaEqfzUCNkoHQ1JuGrQSTUNFf6JNkIOXn7a4SJkmu r1fn/0lPZ+EXz6kqE7a5fv1C+FDhZlqNWL8YGUls4x30jAsDS+EjprbXVNAf4WX4YVqD TUs7nd2Yw/UwQJM+qm0uuoO5K9sdPO9NT2wOGoEBENSj3P5joTLVLYou3HweR5+DLGRI dJX7biKwR1wPpeoz2sMJhy5mz7BsPq7fUfnmvsa2Ekhjz3nyCY3x7ZkXCgj0REzT5Wk9 0mMw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id me10-20020a17090b17ca00b0027920d6f859si2259207pjb.107.2023.10.04.12.11.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 12:11:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id CB4A580964CD; Wed, 4 Oct 2023 12:11:27 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245481AbjJDTHy (ORCPT + 99 others); Wed, 4 Oct 2023 15:07:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343901AbjJDTHZ (ORCPT ); Wed, 4 Oct 2023 15:07:25 -0400 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 7D7DF30F4 for ; Wed, 4 Oct 2023 12:03:19 -0700 (PDT) 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 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=2.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.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 (agentk.vger.email [0.0.0.0]); Wed, 04 Oct 2023 12:11:28 -0700 (PDT) X-Spam-Level: ** 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-g= uide/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. =20 +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 ti= me + 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 candid= ate + pages. The default value is 200 seconds. + The effectiveness of KSM and MADV_MERGEABLE is shown in ``/sys/kernel/mm= /ksm/``: =20 general_profit @@ -263,6 +282,32 @@ 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: 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 t= he +observed scan times. The possible values for the ``pages_to_scan`` param= eter is +limited by the ``advisor_min_pages`` and ``advisor_max_pages`` parameter= s. 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 t= ime +advisor scans candidate pages. Lower values make the scan time advisor t= o scan +more aggresively. This is the most important parameter for the configura= tion of +the scan time advisor. + +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