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: 13419677 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 75B2CCDB47E for ; Thu, 12 Oct 2023 19:23:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9FC4B8000C; Thu, 12 Oct 2023 15:23:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9AF558D0002; Thu, 12 Oct 2023 15:23:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 827808000C; Thu, 12 Oct 2023 15:23:06 -0400 (EDT) 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 6E4E18D0002 for ; Thu, 12 Oct 2023 15:23:06 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 17397408A4 for ; Thu, 12 Oct 2023 19:23:06 +0000 (UTC) X-FDA: 81337782372.03.1AE4EA5 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf13.hostedemail.com (Postfix) with ESMTP id 70E4F20014 for ; Thu, 12 Oct 2023 19:23:04 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ckvz8J9Y; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf13.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697138584; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=r2W8hXhR3Y7BKTub/++HNG7xAOIt4x87SFDK4/RJD4M=; b=TByEU254v7+d2MDYqfO7s6VJTbgh7wZzLIEJreNweptbO4Kqjljzg0sBonp89NZaIS/Jd6 hpjGLrkqUlIXijMl1sg4Nr6AI4CtTC3Mzm2VZ6kdzfiVnZ1kA5hyHbHOgAU4use8n9W47Y Y6/dYyNXm1jytFNu/8VIyDOHPWUp0/g= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ckvz8J9Y; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf13.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697138584; a=rsa-sha256; cv=none; b=8hoeKgERKyp2N9pbmgoy/lJCQOZcu3Bty7tRhbHLNyfG0jIDFs0AgX2efkVNweUeL8GIdb XLLQyoFS9Swm1n1+tdRmsR30jFBdP1oFgrA+4d7QYffh+BXl11C7bgbcNUH8r6Xql7JUvl AUdPOz/dG/R95UxHCQuUl+NnFjZbqdg= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 9126F61F21; Thu, 12 Oct 2023 19:23:03 +0000 (UTC) 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-Rspamd-Queue-Id: 70E4F20014 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: bcftgm9z9i61kew5f5hfjthmrkqiih6u X-HE-Tag: 1697138584-770842 X-HE-Meta: U2FsdGVkX1/n1JQYisKOMzmRlhPTLktit8Qt0smBeSLq5AWl3co7Xryg2J7CXMUNX0zvVIxoBAjbtnjy+rg4c61Uz9VHmAXDq9IaHx1BnCl3TXLXWwGom7H/WvwH/vjfVIOPfZRzTEgyrCSbSg/Os1xF6vVaR4AEGFVqWSj1dzNZly7eMPO/xj/SnjycDDjZAtqECbyT2oNJUec5hMQzEEryZiG+WlrPXUIdbuPx1bLeS/fi0rZ117fjNtxdPdfxwSx3zv57CgGPOsxa9WWItdbZbgUi0E8CrSjo68Xk00qobgSik5ohFotBwOw2kr8rIVWSxI/JpWvGLnydlon6il/KPR9rEdqx3vxmzp17dgYNXYfnNBApSEP+cUNPPyxgLbMvY51rHRM3inEt5mkecgitIiIbBL3cryrJlS6neSX5E7CV9kG7kImn6jyUVma8WGbwHmzocHfh9KetzjdDsu77ii2SuURNbnCwHmKZ44YtJQqm5QKBtBQcGID+JTk7UmNjx5gOQbb1gL+oqdO/9sCyxFWrw45VhxnTTKLIzQGDL3mq3Qe8wiQTPIJKzMFPQ31F4eDFS+//sxXile9MfdLVSEno/BAa0wbM/YWVU70csAyeYetkJWGBoUONAp6UmJQpm79f7bB8GvEAUs90p5m59elFSRO3Gx9FjvstEbQWKCaZ/JxcemkPpPDBjrfjiCn0RXks5kzwFvVrPIz64uOYKCLwPwQ3nlQ4pCjAMra3Y4B36ntpZkk/m3Bj/rqImJFBWGWk3TZ1a4EHugqt+lD/toPoxvFwaVQ7sA/Yq/pgdIZX7EshO2D7GEH+zH2cPQZQdlQDbcLX7BCbxe0iYoDjTeoAXOt3IhOF/3ypcJ8srpWgHZlZuUpIJAQHDa8zt2HQ3oci1hsNej7Cn182mcADeXd04cuCGiRn3I1ChMXnv6UE2FW3tJIm+jiQVzJXlvH/Ug4UGtpAaxwwlmG e/2ouyow LYHkvTd3KsdUcT+K9jpl/04xTsfFoUgj3l/Zi74DGa/7SpQS8KKL1QB3y90ombEyipLW6iNDlf84j+Gtcox/bfhQkesX5DZuz9yuObuUc9TyHtZKUuzCkeqfpNBEtJky6OJQhdDUar13/dpBrpTWpu1kJOrQL5hQ3YIYBvVlXnTkgOEw6CgrxdL2no0OIiRGb+odRYGwGDdu2jdNJdSk6NugiL2A4l3NACknET396XwXhulwOTD8xdoqS8Q== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000004, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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; }