From patchwork Tue Oct 10 01:25:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13414731 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 8D3C9CD68E4 for ; Tue, 10 Oct 2023 01:26:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 01AFA8D0089; Mon, 9 Oct 2023 21:26:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EBCCF8E0002; Mon, 9 Oct 2023 21:26:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C71198D00AA; Mon, 9 Oct 2023 21:26:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id B8D138D0089 for ; Mon, 9 Oct 2023 21:26:10 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 91E5B1CAAF6 for ; Tue, 10 Oct 2023 01:26:10 +0000 (UTC) X-FDA: 81327810900.23.C54BD6B Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf20.hostedemail.com (Postfix) with ESMTP id C2FE01C0005 for ; Tue, 10 Oct 2023 01:26:08 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="tAWQTp/K"; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf20.hostedemail.com: domain of sj@kernel.org designates 145.40.68.75 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=1696901169; 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=kVignUki5JZnCPqJilSs5i8raEK8eQaEo1c0T2dA0wQ=; b=nY1OfrFRv+JG/1veug1N7JBWXkhsk+H0XW/CH42eIHvm+VgkFlcGNuuYz/1/+A9oCLR9XY du0E8fLMIKemzCdpCw48VBThidMn0pi7T7kLh/U23c3U+/SZYXNa9+osuBiU+3kqoQ87ek Jquhgfq70TYoHT+MEauHOnwXMjNZP/s= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="tAWQTp/K"; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf20.hostedemail.com: domain of sj@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696901169; a=rsa-sha256; cv=none; b=SXq8+DLVN2It2xa59DCe1VqYeKKOEjAq2hZhZsomkA9XCXGYd1fd81u5Ye+1xQ9rnFdIGK I6Y8f0A+/sMEP59BLD+sVZ93Upd9sz6zE780fGxqSz/42A9bmNM48KcuQxqpt1ErdE8oAp f2B3d/yTDmF+wzqPFR7mn5skXd+/PKU= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by ams.source.kernel.org (Postfix) with ESMTP id 6138AB80B55; Tue, 10 Oct 2023 01:26:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 50667C433C8; 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=1696901166; bh=tkpBuPAHcXxVtnYMQEIhabnoxptCyM9g6IJhkHy1SMg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tAWQTp/K52moV1cPuIjdEwQJ611H9Xy78nBYCj90TW3I4Ov5uPdLOFPNqJYK3VXAw +Ll4igPCl10aeRmwGmu+DHjgv08wOmOQnBGquWSiyOwjVkyU5kwz6VG35hAUTxFH8K f8KTLiado7LKukenztqwf8o17fVXIAEb73doXRJgHbgOTxzJN4mVRFatJlxSjI7Bxk qR1+S0Y6NMcIOJdjIMZL7PrPU7rS0HH/3Wh/0Le67RiElATC2oJrBpt8heZ6JaVPDS TVZCQHhFbEQqHjYysEhkeyr2R2d810evFOuASv+otwr6W4Jx3TF3+7v9YBY7zHqMjB uV1ETgeQCVyxw== From: SeongJae Park To: Cc: SeongJae Park , Andrew Morton , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 1/3] mm/damon/sysfs-schemes: do not update tried regions more than one DAMON snapshot Date: Tue, 10 Oct 2023 01:25:58 +0000 Message-Id: <20231010012600.83140-2-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-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: C2FE01C0005 X-Stat-Signature: ep31orqfh5s6onwrcyyhyhqwdd948p3w X-HE-Tag: 1696901168-200364 X-HE-Meta: U2FsdGVkX1+QZJEQ8DK9OrgfFb4Aa4BZfNKWETJ0jKtn1LMa+xyQAyDPCnjtf2NEmE0JX+NBxf4KxcefNPxCwoedZBsDMB0b4FnYIE84B6ptkx5BvoKFM4dzt6PGxkIqm1JMmfgax5kCMMwTpPWfLehVMX2BocwX5c2QfA8PmqMLykuL4Cirkjx05H0zZjTm91ObXEmWCQ70Naeh115bIzRnH62MXTl+80NhwJMTNWxxZHGLP7m/XV3KlBVIINuH3b1+NOke+BjHG61PeQQ45+iggO/Lpbw5/wHmr8fcmMB2Wl1n/xdb0wUgFJJdA3Cpee541tDfMU3EDbsiMlL7G1M1MiW45Phz8pSN9OuEItLuTCtQaqPCogCnH6eNAa2F5YqBZ9NDjYjbkOHQ4hzoEvTWW9QFCs1NVG+SidaSKreJh0Y+9Ynajb4QCUAL/MEN+vE2IbguX+fjzpfCHjC5xBdUhEKpP79nRDrtf2MInFWdumM59cHKMPLMCl0EIn0cU8G++mhbzB8dP433iOeREPxH6DpmZkNTubFzY8sDHbN/lFGbdGLakpmvywQ+gyc4dIHOE5I8q4VKfDYfGr/iV82/z/eN7y8kvGl2xSMglG9e9iS5KJ8V/1A8qPEBtsGf090c+eq6y9/IkAsbmD9CzSEFCm52JPF5yHjIInSzN6Dn41ZjqXOPSLRkEEd/7DV06pdOupeNy4M4i8i19lTFllBOP53aM6G6+2AWTyVH8El5XFFgR/ezMHZ4sksCrGdTvOAYnP18/YbEGPsWKNEjQ9LUWTYtbnP6ONepYvRK8O+JaFbRkYMPgEUpalYuYO+YhD7Lfsac3oFbCLW0zdcEJAi+ArLRFaJU7MNYElamTz9HkRSmXdhNXbiK7qnCmdi/JK0xlnaV4cT6cIavnEju6Wz8hUQZL1vJGSAiOCYyXsGgCuTqCh91ezoFe3ih32jBjePUqjYDQ5rHrg3zidh GqRHP8Cd 8KOPS9jY7Q/0D5QNbkOHyC8/UWtGQrsz5JMBd3CivTPahGsYOskuiwZZZzYnWUgy5nLr2R/MH//fxJJfG7cJnOdAT0W1ib/CetYK4IJuqItZ7eDY6YhOtVrDoJ8trgXV9m72f7SQ8asZkUDFUtycVcdj4tkaotRZccAiENZCg0IBwdNoMWr3HQ47SHamd73X8vL/n8AjgazWs2W/qZNM0b0vCVQTdIotl3u8Wpm5+AOidQCoPU/NaY+0icw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000064, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: DAMON_SYSFS exposes every DAMON-found region that eligible for applying the scheme action for one aggregation interval. However, each DAMON-based operation scheme has its own apply interval. Hence, for a scheme that having its apply interval much smaller than the aggregation interval, DAMON_SYSFS will expose the scheme regions that applied to more than one DAMON monitoring results snapshots. Since the purpose of DAMON tried regions is exposing single snapshot, this makes no much sense. Track progress of each scheme's tried regions update and avoid the case. Signed-off-by: SeongJae Park --- mm/damon/sysfs-schemes.c | 77 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index a7d70b95c4dd..b07a5c544b34 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -113,11 +113,47 @@ static const struct kobj_type damon_sysfs_scheme_region_ktype = { * scheme regions directory */ +/* + * enum damos_sysfs_regions_upd_status - Represent DAMOS tried regions update + * status + * @DAMOS_TRIED_REGIONS_UPD_IDLE: Waiting for next request. + * @DAMOS_TRIED_REGIONS_UPD_STARTED: Update started. + * @DAMOS_TRIED_REGIONS_UPD_FINISHED: Update finished. + * + * Each DAMON-based operation scheme (&struct damos) has its own apply + * interval, and we need to expose the scheme tried regions based on only + * single snapshot. For this, we keep the tried regions update status for each + * scheme. The status becomes 'idle' at the beginning. + * + * 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. + * + * 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. + * + * Finally, the tried regions request handling finisher function + * (damon_sysfs_schemes_update_regions_stop()) unregisters the callbacks. + */ +enum damos_sysfs_regions_upd_status { + DAMOS_TRIED_REGIONS_UPD_IDLE, + DAMOS_TRIED_REGIONS_UPD_STARTED, + DAMOS_TRIED_REGIONS_UPD_FINISHED, +}; + struct damon_sysfs_scheme_regions { struct kobject kobj; struct list_head regions_list; int nr_regions; unsigned long total_bytes; + enum damos_sysfs_regions_upd_status upd_status; }; static struct damon_sysfs_scheme_regions * @@ -130,6 +166,7 @@ damon_sysfs_scheme_regions_alloc(void) INIT_LIST_HEAD(®ions->regions_list); regions->nr_regions = 0; regions->total_bytes = 0; + regions->upd_status = DAMOS_TRIED_REGIONS_UPD_IDLE; return regions; } @@ -1777,6 +1814,10 @@ static int damon_sysfs_before_damos_apply(struct damon_ctx *ctx, return 0; sysfs_regions = sysfs_schemes->schemes_arr[schemes_idx]->tried_regions; + if (sysfs_regions->upd_status == DAMOS_TRIED_REGIONS_UPD_FINISHED) + return 0; + if (sysfs_regions->upd_status == DAMOS_TRIED_REGIONS_UPD_IDLE) + sysfs_regions->upd_status = DAMOS_TRIED_REGIONS_UPD_STARTED; sysfs_regions->total_bytes += r->ar.end - r->ar.start; if (damos_regions_upd_total_bytes_only) return 0; @@ -1793,6 +1834,29 @@ static int damon_sysfs_before_damos_apply(struct damon_ctx *ctx, return 0; } +/* + * DAMON callback that called after each accesses sampling. While this + * 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) +{ + 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_STARTED) + sysfs_regions->upd_status = + DAMOS_TRIED_REGIONS_UPD_FINISHED; + } + + return 0; +} + /* Called from damon_sysfs_cmd_request_callback under damon_sysfs_lock */ int damon_sysfs_schemes_clear_regions( struct damon_sysfs_schemes *sysfs_schemes, @@ -1816,6 +1880,16 @@ int damon_sysfs_schemes_clear_regions( return 0; } +static void damos_tried_regions_init_upd_status( + struct damon_sysfs_schemes *sysfs_schemes) +{ + int i; + + for (i = 0; i < sysfs_schemes->nr; i++) + sysfs_schemes->schemes_arr[i]->tried_regions->upd_status = + DAMOS_TRIED_REGIONS_UPD_IDLE; +} + /* Called from damon_sysfs_cmd_request_callback under damon_sysfs_lock */ int damon_sysfs_schemes_update_regions_start( struct damon_sysfs_schemes *sysfs_schemes, @@ -1823,8 +1897,10 @@ int damon_sysfs_schemes_update_regions_start( { damon_sysfs_schemes_clear_regions(sysfs_schemes, ctx); damon_sysfs_schemes_for_damos_callback = sysfs_schemes; + damos_tried_regions_init_upd_status(sysfs_schemes); 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; } @@ -1837,6 +1913,7 @@ 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; }