Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4646096rdb; Tue, 12 Dec 2023 05:46:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IEQDTvNbRJxuPi7zdbcRiqKE8EiAYERfD+N+J2I359aFLoRLg0rR9rL/S+wWBddIoKVsyDc X-Received: by 2002:a05:6a00:3a11:b0:6d0:8c48:fa07 with SMTP id fj17-20020a056a003a1100b006d08c48fa07mr3723980pfb.45.1702388800905; Tue, 12 Dec 2023 05:46:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702388800; cv=none; d=google.com; s=arc-20160816; b=L9bd2nlSXsf0ECzu5eUsghW3v+pSNf9KEX35XWdjEFm8dBnOSIM+8E2qyok7ZF4PvP Suc2BgYd2LCunX/hSrl4YEHtMkVaJkoImYiZdBDxTaoyOjumYbEFS8/wfV6E53yJnexz 2UzwpqjJOpz+3TmqLECkUvAvzTK6d7zmnqO+WcNf2kyCJW6EhieQyefMo1I8YD6TLzRF P0LalM51xVNxrxnP6YtuQzEfHj0elqJ5YYCMy2EOdYn2ynivy9TF0x85gNVJpPb6rgHI Ud9Mx4R5ZFGU37P8Rpu7DhalQGGIeCvOLDPePylr5GBaNR1DPzyhCF7RxOOm742LTgvW xp4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :organization:autocrypt:from:references:cc:to:content-language :subject:user-agent:mime-version:date:message-id:dkim-signature; bh=8DODWjUHEOXpo4jstEumop4gYxI3RMhCZ+EH7YA+W/g=; fh=rj364kmaeZMVM5HdKawlrVtJQHBt+LI407FoTGJZ9pc=; b=RAIHFyw0jHWMJNdguxLh8jr4Slb22Xsk3TeuAG6Vgy1qb3zzaR2hb3R+/6KRrcfVC4 ssr6JHsdfwoHJz6b3I9dQlEKdgITYXyepr7MqbdLGFdQu9rASp/Xat/TFZSwzx9yb50o h2wuRshKkEINpzCdIWczAM63GqNyc6tJvuF22bXHbE+VFY/1i/n7Svz03co/NIDcSosw CSK7Us1z9tu3SUjOMXeqts0lq881xqOOh6Ob4oUvLPOHmgsw32N+bYXd0Q8SD4dFPSF0 LxaK7qET97NNofF4nzt5fDG9b+lup5mxc0z0nTAGcR+wkHNBP5N3XL11SxWhuZOjq1rq SLxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Jtr6coEB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id q35-20020a635c23000000b0056336fb99aasi7652032pgb.850.2023.12.12.05.46.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 05:46:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Jtr6coEB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 6F4A4807D987; Tue, 12 Dec 2023 05:46:38 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346660AbjLLNqX (ORCPT + 99 others); Tue, 12 Dec 2023 08:46:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346622AbjLLNqW (ORCPT ); Tue, 12 Dec 2023 08:46:22 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59574A1 for ; Tue, 12 Dec 2023 05:46:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702388787; h=from:from: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:autocrypt:autocrypt; bh=8DODWjUHEOXpo4jstEumop4gYxI3RMhCZ+EH7YA+W/g=; b=Jtr6coEBs+yOngQQMec8H3UFE71tD73dv+pq225kdFSk+iDEaVpGrDitjEM1pkvj/GNSIo xb8Rcqx6BbJBJk7RT/VWcKpu2fUNoBr+qXMWazv5JoRo3W/mSk2xcgxYvB6NfVyAAgmZVd RaCrHaNW2U4vR/IjqOpZ/Mlfbi8cVpU= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-75-LV14k3W7Pkart837sqbWkg-1; Tue, 12 Dec 2023 08:46:26 -0500 X-MC-Unique: LV14k3W7Pkart837sqbWkg-1 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-333501e22caso4648758f8f.2 for ; Tue, 12 Dec 2023 05:46:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702388785; x=1702993585; h=content-transfer-encoding:in-reply-to:organization:autocrypt:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=8DODWjUHEOXpo4jstEumop4gYxI3RMhCZ+EH7YA+W/g=; b=hAONab4K/kMfwolBR2SQkmQTI+afC8aZCS7tQRcLwFKAN8Xjq4Ihc8piM4/kjJPcdi 325romUP/yndsgZa8aN3mmX12110DcE3gsb6IuHVdLmd3Eq+rs9RLKJfxBp97W7nLc70 JxQHiT82NL3AP/3JntdPLFhM3FDxGSdCWepRMFFjzAMXHDkoc0xxbI4+2GYzvnSQXcpe 1d0jtkxw0QZ64lxSAPC683lBhJdRsdwSsgTKL2Xfg/RB+ItN6F10PzQ4wVSjP4Vat8OU bw0nODiZQbTAxB7kNoX/ngRVNyHWyrRLoQHm905LKccylr3TbrQtlx3B4LGLhgaBxEKd wu9A== X-Gm-Message-State: AOJu0YyflA2dCMOP309cfnopnH68s1oxaHgtQ2UeqLM/1XQxypOcKkyI +1A7Vjw4lLOVWV12h4DG7JJDVY8vSTHXyxz1Whm6o+LbAtig6XNuYKcyDRZ4uXjmlQEncbKbN/0 sz4+lUixvhU05X1L4ClbHl/83 X-Received: by 2002:a5d:690b:0:b0:333:fd3:1a7f with SMTP id t11-20020a5d690b000000b003330fd31a7fmr3280231wru.52.1702388784970; Tue, 12 Dec 2023 05:46:24 -0800 (PST) X-Received: by 2002:a5d:690b:0:b0:333:fd3:1a7f with SMTP id t11-20020a5d690b000000b003330fd31a7fmr3280221wru.52.1702388784645; Tue, 12 Dec 2023 05:46:24 -0800 (PST) Received: from ?IPV6:2003:cb:c74b:ca00:4ca2:ff2c:9092:f070? (p200300cbc74bca004ca2ff2c9092f070.dip0.t-ipconnect.de. [2003:cb:c74b:ca00:4ca2:ff2c:9092:f070]) by smtp.gmail.com with ESMTPSA id e10-20020adffd0a000000b003334675634bsm10885476wrr.29.2023.12.12.05.46.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 12 Dec 2023 05:46:24 -0800 (PST) Message-ID: <525a4d9c-efaf-4663-a354-10f9e3ff2148@redhat.com> Date: Tue, 12 Dec 2023 14:46:23 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 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, hannes@cmpxchg.org, riel@surriel.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org References: <20231204234906.1237478-1-shr@devkernel.io> <20231204234906.1237478-5-shr@devkernel.io> From: David Hildenbrand Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1ImpaIv2Jw8NJgW0k/D1RyKCwaTsgRdwuK Kx/Y91XuSBdz0uOyU/S8kM1+ag0wvsGlpBVxRR/xw/E8M7TEwuCZQArqqTCmkG6HGcXFT0V9 PXFNNgV5jXMQRwU0O/ztJIQqsE5LsUomE//bLwzj9IVsaQpKDqW6TAPjcdBDPLHvriq7kGjt WhVhdl0qEYB8lkBEU7V2Yb+SYhmhpDrti9Fq1EsmhiHSkxJcGREoMK/63r9WLZYI3+4W2rAc UucZa4OT27U5ZISjNg3Ev0rxU5UH2/pT4wJCfxwocmqaRr6UYmrtZmND89X0KigoFD/XSeVv jwBRNjPAubK9/k5NoRrYqztM9W6sJqrH8+UWZ1Idd/DdmogJh0gNC0+N42Za9yBRURfIdKSb B3JfpUqcWwE7vUaYrHG1nw54pLUoPG6sAA7Mehl3nd4pZUALHwARAQABzSREYXZpZCBIaWxk ZW5icmFuZCA8ZGF2aWRAcmVkaGF0LmNvbT7CwZgEEwEIAEICGwMGCwkIBwMCBhUIAgkKCwQW AgMBAh4BAheAAhkBFiEEG9nKr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e90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: <20231204234906.1237478-5-shr@devkernel.io> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Tue, 12 Dec 2023 05:46:38 -0800 (PST) On 05.12.23 00:49, Stefan Roesch wrote: > 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 | 54 ++++++++++++++++++++++++++++ > 1 file changed, 54 insertions(+) > > diff --git a/Documentation/admin-guide/mm/ksm.rst b/Documentation/admin-guide/mm/ksm.rst > index e59231ac6bb71..297c4a0d04dee 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 > + 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 30000. > + > The effectiveness of KSM and MADV_MERGEABLE is shown in ``/sys/kernel/mm/ksm/``: > > general_profit > @@ -263,6 +289,34 @@ 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`` > +and ``advisor_max_pages``. The default values are sufficient for most workloads. > + > +The ``pages_to_scan`` parameter is re-calculated after a scan has been completed. Acked-by: David Hildenbrand -- Cheers, David / dhildenb