From patchwork Tue Feb 6 02:51:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13546542 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 C0237C4828D for ; Tue, 6 Feb 2024 02:52:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 209216B006E; Mon, 5 Feb 2024 21:52:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1B93F6B0071; Mon, 5 Feb 2024 21:52:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 081886B0072; Mon, 5 Feb 2024 21:52:07 -0500 (EST) 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 E87C36B006E for ; Mon, 5 Feb 2024 21:52:06 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id B2903807ED for ; Tue, 6 Feb 2024 02:52:06 +0000 (UTC) X-FDA: 81759854652.11.0656A6F Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf21.hostedemail.com (Postfix) with ESMTP id 265911C0016 for ; Tue, 6 Feb 2024 02:52:04 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=vOmbmYCA; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf21.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=1707187925; 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:references:dkim-signature; bh=qOQMNto8an4ntemQ7WT/Dy+S6k6+FjGXvA12+m9GdSU=; b=BvmLieAF/Nu1bTub3Ua70S0VIWuUOsMAX0YlfheUZYyD0flvxuiuztaCrkvG5dSkp3o3gi fr/2NA9HdVn5JJ0lIjFjAbB3Z5D8iMMExsVa5s0xshY8rmiY21uDqx85T7sP4V97psRjXH 8geFxKNesh30vauaVN6OKnVz4kRG7Mc= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=vOmbmYCA; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf21.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=1707187925; a=rsa-sha256; cv=none; b=3yb+L/2mlG5dpv/yuhS08EVb93Altho0J21gszGhwmR8rqolMRNvK9RqvlgYlwlTnIGFiL te6/kcm5MdPrFtMLdJOypjI5ZfHCYcMO4CYp7D/DVdbUpoGOBqgz5wdzStfsWKT/OTpkO6 jYjfLUNQdPNSSi4x6xZZO2PbBT4EWI4= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 2074460AC1; Tue, 6 Feb 2024 02:52:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 540C8C433F1; Tue, 6 Feb 2024 02:52:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707187923; bh=bq2ABozIdInk9f3RiCusWCHq2XVIshtqRKWElNQQ11M=; h=From:To:Cc:Subject:Date:From; b=vOmbmYCAyMcjTPDBExa+YMMSUcJ7pNPhNxNGTj21aG7LYarjqx+ATjZ+0q49woSF5 5AS4nIuWaVKSmgYxorBaiqwnZAmY7G1KvVBc2Ni3QxGwfJhuLdEN10EUAKe2swnmEV W0aR1ALWESt+pqsFlpW8qsWAkSNFHImkFcrwoUenw4n7tSf7E6gT0aeaDcdrmpu2PR bovUf1kqitI4jJuPp74WsRqI3vR9hOh70GvlIIl8wuxOEJh5p0+DlQk7DNaL5n4/pE bD/DglJhieuKy6XneJ5io1WWUgGFEqB1AGk/QEin1xzdK7+oFLjEVR/SG6r3CxgtgL 1r813pvFf5kQQ== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , cuiyangpei@gmail.com, xiongping1@xiaomi.com, damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] mm/damon/sysfs: handle 'state' file inputs for every sampling interval if possible Date: Mon, 5 Feb 2024 18:51:58 -0800 Message-Id: <20240206025158.203097-1-sj@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 265911C0016 X-Stat-Signature: 7cgy7bknzy35pw8j7r9if7hqdzb3tmcd X-Rspam-User: X-HE-Tag: 1707187924-458346 X-HE-Meta: U2FsdGVkX19bziu2CciG4ZyMbqc1QQ/YYA4mud3mOtv7z/dHho2AN8oIWiBNMTlaeUQjACKizoNigSeU9UlhMHgOQnoY3v0KKIYAn1fUHsF/vcN7NXMIc2r0zWfy1DjfFQ0AtOxgtcR4kB68JIqEdwmiu9+e3qpY4v7CPwm9yK7q94VI5mg3wOV8OO/D6nVYNEQVxTRJWT3wrvCjrJkyy68jJfl/CTNj3qrEsVvc4R8Eat4J4lyDJ7fYBEfvd/SXP6WBlI2rhnwVbCZ7h4PQKpXRvJzPpIZymrrgVs7Q2P3wNT3LB86s4JIFsXldQBommnLNe06UtrugSm/rwh9lwQBbT6cGqkeZQ3p46Kz3PBTKKuQl27hDXn2u+VrwoKB06TLSbCXvVETbgF7atxppu8H8f1zZVNVUpZ6oPNEmzAZdZkTXpH6E13Y/lU5KzB7tI2vLgmdFi6lWyRvDTFxZkUjdNEtRU8DB6CpilVar8HSbFFdNaYkV5eQI9NjgZPz1+gwZGsNXFZppCO2w8ROrwJEhaQvq/gIT7/EBbHc2Rz4kQZwxETnXEluMqJzSxtebJVskd5ViWS+OgLqzvkhee/x3vy0/K907qpJrd3B9GX9nh8Z1Jy47XI28R9nSYcQeI6FqV72a1ULp/6uAFdCcLqjegf23Svt7ssDZ5SkIBTtPgmOjOSs/tGsJKw96/bnz7GC+H+ASa4iwPt86VanIuDoCdw0ph3I1DmvmetTlDi/MymwNsFFx0Sfn+Ka/2JLiSPr/yd0bRy62S//eaFB7Fz79nE1NypGvaJMq6lR8faSwNv0J3JNRl6T9zGCIx+MWE0B5PrSr+AgAWWe7Xh/cedXbNZlfFP2pnfvAJEbmaY6tcefFJiel+ak0GFyL2tebMWd6J17bzUGIrJ895505pTP1a5yDZoz5AzGU3FrD5jhNbPrS+uH5LsAZ3TAbHztmhIgFTSOPQ7Qi2GUgMMh CihcGfln 6ajSfvtpt/mTDtdkND2GNe/psMUMDHYJdFR/9zd8t/QJi57RzX3wh2Zm+je14yfz9K6zuAXdrqSl6uIYXvbJrBso7xfUxoEbU/U64Gf8WhfyUMS5PUnzWZEIqUQxTBfiq3bjE0JXP2R1Q1N8iNW3RQVZ64nbiAhsL+7zMXTE413zG7/w3TiI/0DuoVvsM06HDPjD058LGpFRshJWXNzEXBy3cMYm9DUatSn5ByH5GjtYSgok= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: DAMON sysfs interface need to access kdamond-touching data for some of kdamond user commands. It uses ->after_aggregation() kdamond callback to safely access the data in the case. It had to use the aggregation interval callback because that was the only callback that users can access complete monitoring results. Since patch series "mm/damon: provide pseudo-moving sum based access rate", which starts from commit 78fbfb155d20 ("mm/damon/core: define and use a dedicated function for region access rate update"), DAMON provides good-to-use quality moitoring results for every sampling interval. It aims to help users who need to quickly retrieve the monitoring results. When the aggregation interval is set too long and therefore waiting for the aggregation interval can degrade user experience, or when the access pattern is expected to be significantly changed[1] could be such cases. However, because DAMON sysfs interface is still handling the commands per aggregation interval, the end user cannot get the benefit. Update DAMON sysfs interface to handle kdamond commands for every sampling interval if applicable. Specifically, all kdamond data accessing commands except 'commit' command are applicable. [1] https://lore.kernel.org/r/20240129121316.GA9706@cuiyangpei Signed-off-by: SeongJae Park --- mm/damon/sysfs-common.h | 2 ++ mm/damon/sysfs-schemes.c | 22 +++++++++------------- mm/damon/sysfs.c | 21 ++++++++++++++++++--- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/mm/damon/sysfs-common.h b/mm/damon/sysfs-common.h index 4c37a166eb81..ec0703e1e90b 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); +void damos_sysfs_mark_finished_regions_updates(struct damon_ctx *ctx); + bool damos_sysfs_regions_upd_done(void); int damon_sysfs_schemes_update_regions_stop(struct damon_ctx *ctx); diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index dd2fb5127009..98c6e5376486 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -127,17 +127,17 @@ static const struct kobj_type damon_sysfs_scheme_region_ktype = { * * Once the tried regions update request is received, the request handling * start function (damon_sysfs_scheme_update_regions_start()) sets the status - * of all schemes as 'idle' again, and register ->before_damos_apply() and - * ->after_sampling() callbacks. + * of all schemes as 'idle' again, and register ->before_damos_apply() + * callback. * * Then, the first followup ->before_damos_apply() callback * (damon_sysfs_before_damos_apply()) sets the status 'started'. The first - * ->after_sampling() callback (damon_sysfs_after_sampling()) after the call - * is called only after the scheme is completely applied - * to the given snapshot. Hence the callback knows the situation by showing - * 'started' status, and sets the status as 'finished'. Then, - * damon_sysfs_before_damos_apply() understands the situation by showing the - * 'finished' status and do nothing. + * ->after_sampling() or ->after_aggregation() callback + * (damon_sysfs_cmd_request_callback()) after the call is called only after + * the scheme is completely applied to the given snapshot. Hence the callback + * knows the situation by showing 'started' status, and sets the status as + * 'finished'. Then, damon_sysfs_before_damos_apply() understands the + * situation by showing the 'finished' status and do nothing. * * If DAMOS is not applied to any region due to any reasons including the * access pattern, the watermarks, the quotas, and the filters, @@ -2118,7 +2118,7 @@ static int damon_sysfs_before_damos_apply(struct damon_ctx *ctx, * callback is registered, damon_sysfs_lock should be held to ensure the * regions directories exist. */ -static int damon_sysfs_after_sampling(struct damon_ctx *ctx) +void damos_sysfs_mark_finished_regions_updates(struct damon_ctx *ctx) { struct damon_sysfs_schemes *sysfs_schemes = damon_sysfs_schemes_for_damos_callback; @@ -2134,8 +2134,6 @@ static int damon_sysfs_after_sampling(struct damon_ctx *ctx) sysfs_regions->upd_status = DAMOS_TRIED_REGIONS_UPD_FINISHED; } - - return 0; } /* Called from damon_sysfs_cmd_request_callback under damon_sysfs_lock */ @@ -2208,7 +2206,6 @@ int damon_sysfs_schemes_update_regions_start( damos_tried_regions_init_upd_status(sysfs_schemes, ctx); damos_regions_upd_total_bytes_only = total_bytes_only; ctx->callback.before_damos_apply = damon_sysfs_before_damos_apply; - ctx->callback.after_sampling = damon_sysfs_after_sampling; return 0; } @@ -2237,7 +2234,6 @@ int damon_sysfs_schemes_update_regions_stop(struct damon_ctx *ctx) { damon_sysfs_schemes_for_damos_callback = NULL; ctx->callback.before_damos_apply = NULL; - ctx->callback.after_sampling = NULL; damon_sysfs_schemes_region_idx = 0; return 0; } diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 1f891e18b4ee..678de97fcc88 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1379,11 +1379,13 @@ static int damon_sysfs_commit_schemes_quota_goals( * damon_sysfs_cmd_request_callback() - DAMON callback for handling requests. * @c: The DAMON context of the callback. * @active: Whether @c is not deactivated due to watermarks. + * @after_aggr: Whether this is called from after_aggregation() callback. * * 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, bool active) +static int damon_sysfs_cmd_request_callback(struct damon_ctx *c, bool active, + bool after_aggregation) { struct damon_sysfs_kdamond *kdamond; bool total_bytes_only = false; @@ -1401,6 +1403,8 @@ static int damon_sysfs_cmd_request_callback(struct damon_ctx *c, bool active) err = damon_sysfs_upd_schemes_stats(kdamond); break; case DAMON_SYSFS_CMD_COMMIT: + if (!after_aggregation) + goto out; err = damon_sysfs_commit_input(kdamond); break; case DAMON_SYSFS_CMD_COMMIT_SCHEMES_QUOTA_GOALS: @@ -1418,6 +1422,7 @@ static int damon_sysfs_cmd_request_callback(struct damon_ctx *c, bool active) goto keep_lock_out; } } else { + damos_sysfs_mark_finished_regions_updates(c); /* * Continue regions updating if DAMON is till * active and the update for all schemes is not @@ -1450,7 +1455,16 @@ 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); + return damon_sysfs_cmd_request_callback(c, false, false); +} + +static int damon_sysfs_after_sampling(struct damon_ctx *c) +{ + /* + * after_sampling() is called back only while the context is not + * deactivated by watermarks. + */ + return damon_sysfs_cmd_request_callback(c, true, false); } static int damon_sysfs_after_aggregation(struct damon_ctx *c) @@ -1459,7 +1473,7 @@ 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); + return damon_sysfs_cmd_request_callback(c, true, true); } static struct damon_ctx *damon_sysfs_build_ctx( @@ -1478,6 +1492,7 @@ static struct damon_ctx *damon_sysfs_build_ctx( } ctx->callback.after_wmarks_check = damon_sysfs_after_wmarks_check; + ctx->callback.after_sampling = damon_sysfs_after_sampling; ctx->callback.after_aggregation = damon_sysfs_after_aggregation; ctx->callback.before_terminate = damon_sysfs_before_terminate; return ctx;