From patchwork Mon Dec 18 23:10:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 180678 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp1591707dyi; Mon, 18 Dec 2023 15:14:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IGfTZbHpA5JAYj4d+kn8n7/dLC4xRhA3u5AcbLDvxqj0iE5bPL8PR9SJO8+jYFqF+i7AYtS X-Received: by 2002:a17:906:530b:b0:a23:5570:2f39 with SMTP id h11-20020a170906530b00b00a2355702f39mr1481692ejo.99.1702941261452; Mon, 18 Dec 2023 15:14:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702941261; cv=none; d=google.com; s=arc-20160816; b=iGzMDiYHpdEhdidLBIcstjfgtiT/Lx5gpv9gCS5YHh4LVU+0kvplngHqz+Qe+Fxzc5 QigWgPpQJ0YGu2njHBPSwB6+QRU3jbceUSF7/W4Kz3dnAYp6YNbezN5LxYWgPQQpzIuO TqKX/LXURHg6/GHNo2EjqboPlAw9MTUwJ1NrA2MowWYIZH3PyBTntdulvr+7kSs888lR /BIYzhxvagxCzwDYv/QXWSGpLHKGUvGOlVce264ZuYdn9TwjbZWN/HGzXExOAOcd1xSr ubMAFGgfklN+C5zBW4/HorPnlruadH7np82gAR6h4loVFMN/2Wc+WGLAT2+Vm3mfxWg1 hoRQ== 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4470-ouuuleilei=gmail.com@vger.kernel.org" Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id qq26-20020a17090720da00b00a233a61aaa9si1858058ejb.830.2023.12.18.15.14.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 15:14:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-4470-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-4470-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4470-ouuuleilei=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 am.mirrors.kernel.org (Postfix) with ESMTPS id 140F91F249A8 for ; Mon, 18 Dec 2023 23:14:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DDD8C79944; Mon, 18 Dec 2023 23:13:39 +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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785663336350495427 X-GMAIL-MSGID: 1785663336350495427 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-guide/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``. + The pages_to_scan value cannot be changed if ``advisor_mode`` has + been set to scan-time. + Default: 100 (chosen for demonstration purposes) sleep_millisecs @@ -164,6 +167,29 @@ 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: 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 time + 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 candidate + 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/``: general_profit @@ -263,6 +289,35 @@ 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: none and +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_max_cpu`` parameter. 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_to_scan`` and ``advisor_max_pages_to_scan``. The default +values are sufficient for most workloads and use cases. + +The ``pages_to_scan`` parameter is re-calculated after a scan has been completed. + + -- Izik Eidus, Hugh Dickins, 17 Nov 2009