Received: by 2002:a05:7412:8598:b0:f9:33c2:5753 with SMTP id n24csp162946rdh; Mon, 18 Dec 2023 15:14:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IGeuhrSxVC3FT3ZPsPrPtWN8SCrwaYV2eHruOMU8EzHEO1YTzal9d46knEtctQF8gq5C4Sf X-Received: by 2002:a05:6e02:1c0d:b0:35f:af72:1d9b with SMTP id l13-20020a056e021c0d00b0035faf721d9bmr4123572ilh.127.1702941250950; Mon, 18 Dec 2023 15:14:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702941250; cv=none; d=google.com; s=arc-20160816; b=h8/3SXa+JGq4tlrQJM8UVmW7Dqh6372XtFjE5qdtNIpG23iVxLV9rfjxjN4J+ZTubW dCt1ryWBtb3IaghxyG/H6bYcyZi4YYHgKYM4ExaDxFxhIXY1cHe8F8OgHkA4y/55qGjb pJSpErGqcQn0ThoGxGRxCNpQc9oVyFNJ+527hADGjRZM4MxRIshxARLugWGQQv9c7QNy Lv6S5I8uIlgOZMgrHXExsogbLlAxRfjDesfAtWn8tCf2kN1J9gSp70W25EGCokpP/AUr 4iIvd0kfmd4bVvkHtgCCdvCoE5r2hyDmuCmrIDR3mJ4N3+ElV5BrYzqaMEd5ETP7ruzB sCCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=oFkMIsv/KO1omoMMrIxz+uBzORyGY8S6CnCh+B+0uQ0=; fh=sS+J4OyOC0EcVLWJpS3mBHGeO+0+dYZJ+ImCUfzsrH4=; b=H+SG2AaNuNw0oOSMgevR40lt+DHthEcRzu4beufCUmUfTE74jmGiuGuWFKSbPOWUNg 17XOaoK7T/GW0awfukm54yt6iV8VikbPIYPbj/MFknTO9f58Y4SWqYRsBd3QyeQONO2t rsNkNirlFw2PABX5/kSJELDbYvjHyTUeHHwntSBVNHQEbIvCVu89ucC65U4Ognb2xhkC OR6uEXBc2SCYXqOoKZbH3CxmnyMsteWr5BWQRQcH0ovLcz76pDhOZiHEuCgn+f+zISf3 fsH6LVTkxUxMOWCe7Uyrw1KQ3xHWrg8Ipx58+AbjWSwmFNVzyTKTQsvf0f62SqzxRuzG MGtg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-4470-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4470-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id v28-20020a63151c000000b005c6617b52e3si18708872pgl.0.2023.12.18.15.14.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 15:14:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-4470-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-4470-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4470-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 67DFF2810E8 for ; Mon, 18 Dec 2023 23:14:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C87A2768F4; Mon, 18 Dec 2023 23:13:38 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from 66-220-144-179.mail-mxout.facebook.com (66-220-144-179.mail-mxout.facebook.com [66.220.144.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1A4211EA85 for ; Mon, 18 Dec 2023 23:13:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=devkernel.io Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=devkernel.io Received: by devbig1114.prn1.facebook.com (Postfix, from userid 425415) id E0DD6111427B7; Mon, 18 Dec 2023 15:10:57 -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 v5 4/4] mm/ksm: document ksm advisor and its sysfs knobs Date: Mon, 18 Dec 2023 15:10:54 -0800 Message-Id: <20231218231054.1625219-5-shr@devkernel.io> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20231218231054.1625219-1-shr@devkernel.io> References: <20231218231054.1625219-1-shr@devkernel.io> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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