From patchwork Tue Oct 10 01:25:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 150436 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp2216613vqo; Mon, 9 Oct 2023 18:26:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFQ6xlq7AByQX03pKDR2hsD3n+TT5183EmqT3woRMWYhdEtFlG/IMvKPUo7ryeOzK+k3cLI X-Received: by 2002:a17:90a:db8a:b0:274:945b:6979 with SMTP id h10-20020a17090adb8a00b00274945b6979mr14976122pjv.16.1696901208429; Mon, 09 Oct 2023 18:26:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696901208; cv=none; d=google.com; s=arc-20160816; b=hRF6p3P20Ri7oJIyq0xjutKNKkxzs7UuurCPSgEWNvod07Cl0PGduauE3eq9SA3JO7 9kBsA1Oa1gMnr02AUdBO22cClWYloFtNkFy1UgwSpPGK3TORxSONqVLwb3O77Vq3KVZ2 6ciOG5Gk+5ARBmxY22PDhkM3G6FO8ybvWyxZolLJqLOZIqrG+15rkfx8pHsZHSOF87k7 SOcYaR5VqPa2pXBDCsrcJBLCRvs1unztNbpd5osjgAVKjN57RmtzC8mGLgKnj1xaKji+ 0EWjzHBL1KP3ZTFTHcnjuegU2JdRp12yXh9H4SnNqS0jTW0cAephxSsO2YS46sWtddAj DAfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from :dkim-signature; bh=ZEt4SZ6nWhXI9Pu5fkBbNmR1B5GQg29zXBzEboxveTQ=; fh=vqNpWvtrgKyqgLywmXrl7l1d0QUXOIwW93A3X4awQbI=; b=QNIK8xkwVJ/yhAGTazaGLld8aw2I1IQPHC9tKVrYYZEugT9Ys10LBoQPceEEKG2Y+E ICJpi0TXAKS7pqoajMR0AayvkEsBrY0tNfV1OcWOImAaljaW6+nd+HAFmsaX/DcAF+if maQuvJnDUaW8horXAvbpkrQXa3s1JiJ0fXxzJy8tRx3wweQo0qG7QDwivQQuaMwIuFx7 CGAi8VoXO02xSqHkzTWHfDWa7KMsv4g80Y5RW36cfasOCpxmF8hYJmmKARVZgjO4F+JS qUo1PBI0Dz5/Cs+HNAQU6v2mPJ6tl2FNgRbXtcXzVyEjeJAf1XarcF/8Y3NTdaGAlYvd 0/kA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@kernel.org header.s=k20201202 header.b=IV6y0JX+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id z14-20020a17090ad78e00b0027782fd462esi12701438pju.5.2023.10.09.18.26.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 18:26:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=fail header.i=@kernel.org header.s=k20201202 header.b=IV6y0JX+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id EBBBF8101EC3; Mon, 9 Oct 2023 18:26:28 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379308AbjJJB0O (ORCPT + 18 others); Mon, 9 Oct 2023 21:26:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379264AbjJJB0I (ORCPT ); Mon, 9 Oct 2023 21:26:08 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B680E9D for ; Mon, 9 Oct 2023 18:26:07 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F0390C433CA; Tue, 10 Oct 2023 01:26:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696901167; bh=yWXWsEsp+bNgfqib0es1oavC1e2n/ntLxLviyD7crcg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IV6y0JX+4rigSdZUd1hRuiKh2HaDEEjIDljRDMOeW3AB7wxj72XOAJc5kYFlY5w2S 6PJMuETlqeosgA3sjPLApwudm850uFTqJPJ0j4OWEx1F+Pu/1On7KhLpiVnGqjsVJA U919sGnrb5xWyy5fBHtR73Lxdef0AhDjAWfeT2+QjS0hrJAQEBnAVdtA6AphxFOok5 BYhVIM1RMW9qvCFCEvcBK2Pp44sWxKZU62mLlJjSI0foETCl6z0Rxl4fFvX6sbEWw8 5fFJYuZwgmxG5HJcTrU1FXI3VbuRvFTXe9ksDIQHOM/TkM8tFfDcWK54+oYPBBdc1n vUksMtObrMpBg== From: SeongJae Park Cc: SeongJae Park , Andrew Morton , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 2/3] mm/damon/sysfs: avoid empty scheme tried regions for large apply interval Date: Tue, 10 Oct 2023 01:25:59 +0000 Message-Id: <20231010012600.83140-3-sj@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231010012600.83140-1-sj@kernel.org> References: <20231010012600.83140-1-sj@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net To: unlisted-recipients:; (no To-header on input) 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 (snail.vger.email [0.0.0.0]); Mon, 09 Oct 2023 18:26:29 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779329881191618001 X-GMAIL-MSGID: 1779329881191618001 DAMON_SYSFS assumes all schemes will be applied for at least one DAMON monitoring results snapshot within one aggregation interval, or makes no sense to wait for it while DAMON is deactivated by the watermarks. That for deactivated status still makes sense, but the aggregation interval based assumption is invalid now because each scheme can has its own apply interval. For schemes having larger than the aggregation or watermarks check interval, DAMOS tried regions update request can be finished without the update. Avoid the case by explicitly checking the status of the schemes tried regions update and watermarks based DAMON deactivation. Signed-off-by: SeongJae Park --- mm/damon/sysfs-common.h | 2 ++ mm/damon/sysfs-schemes.c | 16 ++++++++++++++++ mm/damon/sysfs.c | 34 ++++++++++++++++++++++++++++++---- 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/mm/damon/sysfs-common.h b/mm/damon/sysfs-common.h index fd482a0639b4..5ff081226e28 100644 --- a/mm/damon/sysfs-common.h +++ b/mm/damon/sysfs-common.h @@ -49,6 +49,8 @@ int damon_sysfs_schemes_update_regions_start( struct damon_sysfs_schemes *sysfs_schemes, struct damon_ctx *ctx, bool total_bytes_only); +bool damos_sysfs_regions_upd_done(void); + int damon_sysfs_schemes_update_regions_stop(struct damon_ctx *ctx); int damon_sysfs_schemes_clear_regions( diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index b07a5c544b34..45bd0fd4a8b1 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -1904,6 +1904,22 @@ int damon_sysfs_schemes_update_regions_start( return 0; } +bool damos_sysfs_regions_upd_done(void) +{ + struct damon_sysfs_schemes *sysfs_schemes = + damon_sysfs_schemes_for_damos_callback; + struct damon_sysfs_scheme_regions *sysfs_regions; + int i; + + for (i = 0; i < sysfs_schemes->nr; i++) { + sysfs_regions = sysfs_schemes->schemes_arr[i]->tried_regions; + if (sysfs_regions->upd_status != + DAMOS_TRIED_REGIONS_UPD_FINISHED) + return false; + } + return true; +} + /* * Called from damon_sysfs_cmd_request_callback under damon_sysfs_lock. Caller * should unlock damon_sysfs_lock which held before diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index e6b8e90bd450..71bdc51bea6e 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1336,12 +1336,13 @@ static int damon_sysfs_commit_input(struct damon_sysfs_kdamond *kdamond) /* * damon_sysfs_cmd_request_callback() - DAMON callback for handling requests. - * @c: The DAMON context of the callback. + * @c: The DAMON context of the callback. + * @active: Whether @c is not deactivated due to watermarks. * * This function is periodically called back from the kdamond thread for @c. * Then, it checks if there is a waiting DAMON sysfs request and handles it. */ -static int damon_sysfs_cmd_request_callback(struct damon_ctx *c) +static int damon_sysfs_cmd_request_callback(struct damon_ctx *c, bool active) { struct damon_sysfs_kdamond *kdamond; bool total_bytes_only = false; @@ -1373,6 +1374,13 @@ static int damon_sysfs_cmd_request_callback(struct damon_ctx *c) goto keep_lock_out; } } else { + /* + * Continue regions updating if DAMON is till + * active and the update for all schemes is not + * finished. + */ + if (active && !damos_sysfs_regions_upd_done()) + goto keep_lock_out; err = damon_sysfs_upd_schemes_regions_stop(kdamond); damon_sysfs_schemes_regions_updating = false; } @@ -1392,6 +1400,24 @@ static int damon_sysfs_cmd_request_callback(struct damon_ctx *c) return err; } +static int damon_sysfs_after_wmarks_check(struct damon_ctx *c) +{ + /* + * after_wmarks_check() is called back while the context is deactivated + * by watermarks. + */ + return damon_sysfs_cmd_request_callback(c, false); +} + +static int damon_sysfs_after_aggregation(struct damon_ctx *c) +{ + /* + * after_aggregation() is called back only while the context is not + * deactivated by watermarks. + */ + return damon_sysfs_cmd_request_callback(c, true); +} + static struct damon_ctx *damon_sysfs_build_ctx( struct damon_sysfs_context *sys_ctx) { @@ -1407,8 +1433,8 @@ static struct damon_ctx *damon_sysfs_build_ctx( return ERR_PTR(err); } - ctx->callback.after_wmarks_check = damon_sysfs_cmd_request_callback; - ctx->callback.after_aggregation = damon_sysfs_cmd_request_callback; + ctx->callback.after_wmarks_check = damon_sysfs_after_wmarks_check; + ctx->callback.after_aggregation = damon_sysfs_after_aggregation; ctx->callback.before_terminate = damon_sysfs_before_terminate; return ctx; }