Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4837535rdb; Tue, 12 Dec 2023 10:33:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IEKgb5YvpgDVi619pBqNgTY41rvcFpTNHMd80w3bG9hNOC4RD3s3r7Zc7s5GOw1QL0+wM8u X-Received: by 2002:a17:902:ce8f:b0:1d0:6ffe:1e73 with SMTP id f15-20020a170902ce8f00b001d06ffe1e73mr3481610plg.86.1702405992404; Tue, 12 Dec 2023 10:33:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702405992; cv=none; d=google.com; s=arc-20160816; b=jg4aWBFrn3XGcfEM/WGi6tNPOXC5Jt+++9PbCfwBUWtSWaX/jxlfUkACS1GZUAMMkP IIQFHbQj1cg++BsfySysWTdKm1lK/ESGxRVXVZbegRXNyiAX8ISHs8ODdlbhXZS6KYFT SqSiuNkd0LBxOx3HBZEYSVq7IiWdzhwAnQD7u2ObcfSBEAVI2s9J18hW2oH3kIrSjNA+ JnpqMKuvuYpR2j14Vkdx10LELv4paQeSsaL3jbPERK+SHp1fmrzaAkfM6LVDTYdXSozT ZixFbNzGC3IubiypQ+eNk7wPZmr7t/OPWOHNpFIINI1SD5m8RAsgeF20Yi4V26pIt7rV LDeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:cc:to:from:date:references:in-reply-to :message-id:mime-version:user-agent:feedback-id:dkim-signature :dkim-signature; bh=tuYDtz0rZ+euf9UCS0pvvRidqHgRQ+VyODOTAYv7ja8=; fh=zqMjvwQ/d7wXU/3cJ5r5KatpF8Fs6MFrI3zf2HIewrU=; b=OVWBK667DPHRr3IbG6pbHkEN9Y6N1ZUiDZrxCiXyWUK6MjHFO9UIFVyPRqjUmpULPw jaoj1XQCBFP+Eck+ESjaVjBm8A04WOAew5/4BROrJVpXlru8UUD5KFEY373rPhOBbtzA fGr5DZ+9gO9/biRU8QOFDxFVi5fREWeqgnF23ZP3vn79TQlPsoNSdKwE26sSQC4StocB T3ISuxarPpME1V1431finHOv/98/HmNT3WwEeVhhVx12NQ3hhTCTwo+fCtnrz+Q9+DKO Xr7X8B343nR1Do53Ix9QvvCdArXzOQQ8JakTNSLU/mKAEmPAGEOYQpkMi9lF/SLVWSK9 P/sQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@devkernel.io header.s=fm2 header.b=OjznXwIl; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=3h22ptbb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id x15-20020a170902ec8f00b001d332818f37si1891350plg.188.2023.12.12.10.33.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 10:33:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@devkernel.io header.s=fm2 header.b=OjznXwIl; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=3h22ptbb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (Postfix) with ESMTP id 627DC80239F4; Tue, 12 Dec 2023 10:33:09 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232745AbjLLScz (ORCPT + 99 others); Tue, 12 Dec 2023 13:32:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232541AbjLLScy (ORCPT ); Tue, 12 Dec 2023 13:32:54 -0500 Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93622BD for ; Tue, 12 Dec 2023 10:33:00 -0800 (PST) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 0A1DF5C01A5; Tue, 12 Dec 2023 13:33:00 -0500 (EST) Received: from imap51 ([10.202.2.101]) by compute6.internal (MEProxy); Tue, 12 Dec 2023 13:33:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=devkernel.io; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1702405980; x=1702492380; bh=tuYDtz0rZ+ euf9UCS0pvvRidqHgRQ+VyODOTAYv7ja8=; b=OjznXwIljkD5vbMezWdOwRssOg x9/W71pB9uK1jpoBQnl3JKbr73M2t+4eMFrYPnFYBXvivVED7aMTJ55uf6Qw1lRY XVF/7fomrwZKGvLgN7RQ0RMeil8znUBwYCUhpuOtux7W3fRs0xIM9Jh9515g1zFV 9P4lgW3uFeJ+fIEqaj08BRnJtfUsD8iZcTl6YdYEsY/KGMGGQXGDiyaSzJS+gZ/V KmsSmWdoIQCMsBHSFCtn3fMMCjdxrcwQ3JAiKBe6X/+Rhd4vCj0oyYPIHivLYD+/ hWxMc6nVjQ46Subx65Q29fGa6QYiFstY6HC756WJll/WbysD+08jEyEjFgsA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1702405980; x=1702492380; bh=tuYDtz0rZ+euf9UCS0pvvRidqHgR Q+VyODOTAYv7ja8=; b=3h22ptbbEq75fuK0Z6nfn+NXsIIF0aDChRlorH8dYI2H Dx1K9MN7JBD/PRVQRHofVyf3Q+DFDL0exrddaCiv8nrM0tdSPJaZiHOEMhpQhl6y J1SM3yMoxI67AduB2a1h0oLld8OAsCGuujMDoSQhsXVPR70AwdEoEkcf4dGdWjjM 2nqH/ZfGLLGRQfBXUrdfPTXFF1NVu8BT3Q9j0JT/x0/cayb4Oun0LKAq8OOk7ozT aaaqQC8h7yLdwyNBPoybeque5/qvjxZPKSKwjq6J3ASJvY5YasgCa8HDr1cc2bTM 9RZvAlYXdCbsMD8eoijTmjbfewsMuN+PNq/RxIvOBA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrudelgedgudduudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvvefutgesthdtredtreertdenucfhrhhomhepfdfu thgvfhgrnhcutfhovghstghhfdcuoehshhhrseguvghvkhgvrhhnvghlrdhioheqnecugg ftrfgrthhtvghrnheplefgteffgfejtdelfeekgfetjefftdejgfdvudffiedtueevvdej gfevvdfgleetnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrh homhepshhhrhesuggvvhhkvghrnhgvlhdrihho X-ME-Proxy: Feedback-ID: i84614614:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id BD680B6008D; Tue, 12 Dec 2023 13:32:59 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.9.0-alpha0-1283-g327e3ec917-fm-20231207.002-g327e3ec9 MIME-Version: 1.0 Message-Id: In-Reply-To: <9f81f89f-c3ad-4cef-a619-ad36348c8ef5@redhat.com> References: <20231204234906.1237478-1-shr@devkernel.io> <20231204234906.1237478-2-shr@devkernel.io> <9f81f89f-c3ad-4cef-a619-ad36348c8ef5@redhat.com> Date: Tue, 12 Dec 2023 10:32:39 -0800 From: "Stefan Roesch" To: "David Hildenbrand" , kernel-team@fb.com Cc: "Andrew Morton" , hannes@cmpxchg.org, riel@surriel.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v3 1/4] mm/ksm: add ksm advisor Content-Type: text/plain X-Spam-Status: No, score=-0.9 required=5.0 tests=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 pete.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 (pete.vger.email [0.0.0.0]); Tue, 12 Dec 2023 10:33:09 -0800 (PST) On Tue, Dec 12, 2023, at 5:44 AM, David Hildenbrand wrote: > [...] > >> + >> +/** >> + * struct advisor_ctx - metadata for KSM advisor >> + * @start_scan: start time of the current scan >> + * @scan_time: scan time of previous scan >> + * @change: change in percent to pages_to_scan parameter >> + * @cpu_time: cpu time consumed by the ksmd thread in the previous scan >> + */ >> +struct advisor_ctx { >> + ktime_t start_scan; >> + unsigned long scan_time; >> + unsigned long change; >> + unsigned long long cpu_time; >> +}; >> +static struct advisor_ctx advisor_ctx; >> + >> +/* Define different advisor's */ >> +enum ksm_advisor_type { >> + KSM_ADVISOR_NONE, >> + KSM_ADVISOR_SCAN_TIME, >> +}; >> +static enum ksm_advisor_type ksm_advisor; >> + >> +static void init_advisor(void) >> +{ >> + advisor_ctx = (const struct advisor_ctx){ 0 }; >> +} > > Again, you can drop this completely. The static values are already > initialized to 0. > It is needed for patch 2, I folded it into set_advisor_defaults > Or is there any reason to initialize to 0 explicitly? > >> + >> +static void set_advisor_defaults(void) >> +{ >> + if (ksm_advisor == KSM_ADVISOR_NONE) >> + ksm_thread_pages_to_scan = DEFAULT_PAGES_TO_SCAN; >> + else if (ksm_advisor == KSM_ADVISOR_SCAN_TIME) >> + ksm_thread_pages_to_scan = ksm_advisor_min_pages; >> +} > > That function is unused? > I think you already saw it, it is used in patch 2, moving the function to patch 2. >> + >> +static inline void advisor_start_scan(void) >> +{ >> + if (ksm_advisor == KSM_ADVISOR_SCAN_TIME) >> + advisor_ctx.start_scan = ktime_get(); >> +} >> + >> +static inline s64 advisor_stop_scan(void) >> +{ >> + return ktime_ms_delta(ktime_get(), advisor_ctx.start_scan); >> +} > > Just inline that into the caller. Then rename run_advisor() into > advisor_stop_scan(). So in scan_get_next_rmap_item)( you have paired > start+stop hooks. > The next version has this change. >> + >> +/* >> + * Use previous scan time if available, otherwise use current scan time as an >> + * approximation for the previous scan time. >> + */ >> +static inline unsigned long prev_scan_time(struct advisor_ctx *ctx, >> + unsigned long scan_time) >> +{ >> + return ctx->scan_time ? ctx->scan_time : scan_time; >> +} >> + >> +/* Calculate exponential weighted moving average */ >> +static unsigned long ewma(unsigned long prev, unsigned long curr) >> +{ >> + return ((100 - EWMA_WEIGHT) * prev + EWMA_WEIGHT * curr) / 100; >> +} >> + >> +/* >> + * The scan time advisor is based on the current scan rate and the target >> + * scan rate. >> + * >> + * new_pages_to_scan = pages_to_scan * (scan_time / target_scan_time) >> + * >> + * To avoid pertubations it calculates a change factor of previous changes. > > s/pertubations/perturbations/ Fixed. > > Do you also want to describe how min/max CPU comes into play? > I added additional documentation for it in the next version of the patch. >> + * A new change factor is calculated for each iteration and it uses an >> + * exponentially weighted moving average. The new pages_to_scan value is >> + * multiplied with that change factor: >> + * >> + * new_pages_to_scan *= change facor >> + * >> + * In addition the new pages_to_scan value is capped by the max and min >> + * limits. >> + */ > > > > With that, LGTM > > Acked-by: David Hildenbrand > > -- > Cheers, > > David / dhildenb