From patchwork Thu Oct 12 19:22:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 152125 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp1451244vqb; Thu, 12 Oct 2023 12:23:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFt6h9fOCG6dzXvYY1/qvGC9gbuOY+/igrQFDebtQq7j68eP+Y3OetUyKLO8J9mKOGGAW82 X-Received: by 2002:a05:6871:8a18:b0:1e9:bb3a:9a32 with SMTP id tl24-20020a0568718a1800b001e9bb3a9a32mr2145402oab.0.1697138607843; Thu, 12 Oct 2023 12:23:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697138607; cv=none; d=google.com; s=arc-20160816; b=C+YVuKJ9aVArGucpxlgCiVo/+3eVud1lOzbeKPa6sFYYd42KyMkXXwcuO9NBD8eRMN WDIOaltxoF0oqL6vdq8M3Ej1jqqqNlwN7al79oDFGYzPJF/NRjPEt5Vm7LmJrQML64Ly /y8cLTGo2NGLBfxWShIL5alCoDNvZfJ4Uxplpf9v79yhAe/l2f6Lmreg3Mi5wT/GzauZ fxtyIp948oMy7qgnWHtW270v1TWXURFd8Dy9oPE4u1stdH9ZcVrLeKKAU2lA9KwQ1hU1 nm92epOlp0Bd3z2He3VRxwuJXuuol8ORQpFdf1RUGBNeLVKKVIMF/qOWtlYtZYrqGz95 GyfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=r2W8hXhR3Y7BKTub/++HNG7xAOIt4x87SFDK4/RJD4M=; fh=BzdeVYqZhG5iuwuKJRNLP969rvCput73lx0iwx2zu7A=; b=logF5f4vBa2UneMXxst+D26zh66lMhQHIRlCpZn0nbE4KKPGxezIA6RgTkgR2B6adw d7rLfhwlCTQtAH/A+waypdsFObhU1xbR5+6Sq3FsNRvdHEOrpoTcSwprpCXNebVJF00r E3cv2lZdeWp0/fXSWIbLjcHStNMuS5rNPkEmfwGA0Rq9Hvx38VwYvnbWM5E0OlTLatLh hYLcy8d7jN9XwPADFyxeIoQWiHOrpQNKFT5OxnqCYSdLrykkiHKRjVvK1gmnkuhLC55B dTrbMxteWnFMwAICRlBL4vHT5uQLcCJwc8N2sjFgTzSsVoqF2ng81KE3ioolB73dyM23 0Dug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ckvz8J9Y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id g186-20020a636bc3000000b00563d9ff5158si2666596pgc.350.2023.10.12.12.23.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 12:23:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ckvz8J9Y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id 45F2C803D540; Thu, 12 Oct 2023 12:23:25 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442155AbjJLTXI (ORCPT + 19 others); Thu, 12 Oct 2023 15:23:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442125AbjJLTXG (ORCPT ); Thu, 12 Oct 2023 15:23:06 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 373C4CC for ; Thu, 12 Oct 2023 12:23:04 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CAE49C433CA; Thu, 12 Oct 2023 19:23:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697138583; bh=QB5qYv9xS/UghnI15B6QiEIOnHFLoTKSAq1DXsFnEUI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ckvz8J9Yk9yDxzg9KFdbIg8oiysIzmG3nZWvtANgPETgNFiEj+Jwe0cSfoYy9C8VT ije8QYhAeQxs+qiH8JukkJ4HkgYw8GSevQnoKXmoyyT8rIIM5lBLW2Q/7ZHrCYBpL0 aeJVN5e3l8nQVGdG3gUyJV1y4IKbmBLx6HALQyiAZ39wM1DS7kAGurtwjq4c9xaS5k 99u4rx/q559z5Bm3hDKCPpjCvfDL+CrDtS49zR/QyrQmDQl5I4q7q2U2vpHe4Nxfjw MdmdJQXRnyCBm+i3VODRnqjhkPP2Lr8Q1eTJuO1AnP/xb7VC0hvCN6wBkFgP1x3pdh b7eBiPIW3p9Lw== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] mm/damon/sysfs: avoid empty scheme tried regions for large apply interval Date: Thu, 12 Oct 2023 19:22:54 +0000 Message-Id: <20231012192256.33556-3-sj@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231012192256.33556-1-sj@kernel.org> References: <20231012192256.33556-1-sj@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Thu, 12 Oct 2023 12:23:25 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779578813023899756 X-GMAIL-MSGID: 1779578813023899756 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 f60e56150feb..f73dc88d2d19 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; }