From mboxrd@z Thu Jan 1 00:00:00 1970 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 EA5A0C41535 for ; Tue, 19 Dec 2023 23:53:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5C5B06B006E; Tue, 19 Dec 2023 18:53:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 575986B0072; Tue, 19 Dec 2023 18:53:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 416166B007B; Tue, 19 Dec 2023 18:53:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 2F47C6B006E for ; Tue, 19 Dec 2023 18:53:25 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id EAD5D1403B9 for ; Tue, 19 Dec 2023 23:53:24 +0000 (UTC) X-FDA: 81585221928.03.17C67CA Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf29.hostedemail.com (Postfix) with ESMTP id 6721F120014 for ; Tue, 19 Dec 2023 23:53:22 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=qG9JfuJL; spf=none (imf29.hostedemail.com: domain of rdunlap@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=rdunlap@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1703030003; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=lSzGS7cKGhu4UfvY+zEqdstOj92fkqZRDakmXWHiL4s=; b=kIU1CeIp5syZgHGg+LeSlQOExAJ33VRldu/SeRd51FD8DExuwli7zo4+9m1Zqp07s0+IHx k8UKEpFqSZaOEs2yF9jaxtiakXGp6IE5yItIHGcBysnpSxjt8s30bpTVcaMPvV6NBBZKyW K/Ywn2NG1M0Ymf0duKwUkCgNhCrlT+M= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=qG9JfuJL; spf=none (imf29.hostedemail.com: domain of rdunlap@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=rdunlap@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703030003; a=rsa-sha256; cv=none; b=8pyYUrktSt2nK6XcEeBcl1+0IdAzivN7T/Y0/pgNR/cVX8XRBvijg9muJRBIaYeiE3neEA k1x2kAys66Q386bXmYg7V5rjyf6Z+MHN8koh25ytG/KWkzoQ+kjqZb8dJBl1ZUOKp3JF+/ IXMUAztt7G9DNf5yx+UHBclGcZNxddA= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date: Message-ID:Sender:Reply-To:Content-ID:Content-Description; bh=lSzGS7cKGhu4UfvY+zEqdstOj92fkqZRDakmXWHiL4s=; b=qG9JfuJLXvO4mrC6ZGH8PvNo7Z 1IzTEgAQllZj4UDPtlY9iWTOoNpYG1Yed+Es6w1NRZCZxtHC/OkjoLhV39sLhaqTTSXDA58PioeEE 34yP+j94+SMk5BzyuHAtaW96NjG338GpD5Hw+aXnhqwv8I8vAYqbQvxqnqGyIY2GcY/WgOtirbM67 ofYQHaKCbpT72rhT6P29nF3BsvnR9kdinKGB37g+28IAejAFOcQuhDO5Ma0nTHs46rLB+0Vxoh+hN AWPQDRq7K6nQgZOxCCEmXgWtA0Z1GYrOJshCdZb7gFNe9y6eXTGfnCgpAnWufZOQvBzJ77fQMt13d jhKN5JFA==; Received: from [50.53.46.231] (helo=[192.168.254.15]) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rFjtf-00FiJ6-1H; Tue, 19 Dec 2023 23:53:11 +0000 Message-ID: Date: Tue, 19 Dec 2023 15:53:10 -0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v5 4/4] mm/ksm: document ksm advisor and its sysfs knobs Content-Language: en-US To: Stefan Roesch , kernel-team@fb.com Cc: akpm@linux-foundation.org, david@redhat.com, hannes@cmpxchg.org, riel@surriel.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org References: <20231218231054.1625219-1-shr@devkernel.io> <20231218231054.1625219-5-shr@devkernel.io> From: Randy Dunlap In-Reply-To: <20231218231054.1625219-5-shr@devkernel.io> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 6721F120014 X-Rspam-User: X-Stat-Signature: y8ynfkhkhfycgdfomzw8kazmcqjmc3eb X-Rspamd-Server: rspam01 X-HE-Tag: 1703030002-623539 X-HE-Meta: U2FsdGVkX19A/D0EcuLoWgWauGU6j+7NPyiFHr2QZIErjHnjQgL0PFphBhVrgZLHUadO8oUw5GM40oRL6unzwaBkTH1mmg9xKbvkt47iPCcrNG9vf8ya3Ck5nOO1ZoBNCve1FlPPCfjq7eGsfEIqnaCR1yGWWjU95k12bKhAbGY4sN0wXSbQpQq3bucfW+amAu64h1qkuntiHHqmJAhckKt6DJPNrj3vw/JAHQ7pRUecp56uNDvdjiJibNfn61WFKXYzYEAIcaNEDtOfWJNqXaSz0wPN/ZgqTHul6TEvp1niIjuSJcADGuC0m7zmX/RfKhn6fnZlIUDs9TRkbUYn8E9hl7rI+ja/tHJbWCTFLxcWxFvQL3GGckuFsTyZCi6sPOjWW7i064OwvsMF+w39ulebd2FcgyyVQRa04ywKpM/1k9zKjxeZaa60vNgOSzhixMnBfybmGZuYW7KptAoJ9f2ggsy1lE/sVsDqdcQkAYzQbvxeLFPhHRS3nbVFQgH47jN6w05azY2BnddLB5bhI2wgUmJz1dvMLUSa/zOEHMfXxHmCZJ1s0pOmSq6AzxP+0z6MXWiIy1pb1X0/Jei0pP/1AUV8UXSU3Cn8ycnAioxKasBqxAUaYEn7PRlEtjMHWkdMUezIj/00W52WT+AS846FdMtdu2Vb3DAnM5cMoA+37NCszJDd3kh9ixLQcYLsA+BZxT4geCnLmagJxevDq2FGCbRwOvB+px3B1+QPbj2LCqJl85tLVYVPLpszZSxYCpKP1UK9Xfqh3wTEgv8L5eZikBxGZPj7THYj4V5CdNQgPs9vvZNVJ3ziSjEfa4eWjVgYdmxSCv8LrTsOVCCjAeZAkF+n9h6dr9ams0I7ZXaIxMO/ele4krmzYFamLlL8M5VwOYEv8ZtPABfIBzYmdVWig8IssS76SRM094ovYFYmb91l9oYD6ePug/wgHfoBOAUcT07SEaHkKodJEan eF+TaKSU qc8v2WEKFoA2Kc2gFhSSonICjAatgOxg09yuiFcweRcwVdgOh+oeJoQINlek//UJjEC6HDdMY1RPkv9r1cz2IYc75HUE51WhvStqBi1XkTf886WCeoUm3vfzOx6tF24bss5BqpnsuCgTnyW4QrHyWa3IMe0Wq7RxlhIMo+1z7kzui0o9FjhFNO1Rbn2jPGOWPi/mHDztPzEPzsNUBDS/OudV5wp93X2mIsdi7WzMxE+ly1Yp3mgcmC4pG9t6Z116aGPzDnVB1VMHWiC4USGaeK6CPhiv4BoPXBubCPTsVAMlhzst5v87eDDIpQG6AYTDf+F40 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: Hi, On 12/18/23 15:10, Stefan Roesch wrote: > 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 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. scan-time > + > 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. change > + > +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 scan-time > +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 I would drop to. aggressively > +important parameter for the configuration of the scan time advisor. scan-time > + > +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. recalculated > + > + > -- > Izik Eidus, > Hugh Dickins, 17 Nov 2009 thanks. -- #Randy https://people.kernel.org/tglx/notes-about-netiquette https://subspace.kernel.org/etiquette.html