From patchwork Fri Jan 3 17:44:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13925768 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 E624DE77188 for ; Fri, 3 Jan 2025 17:44:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 012A46B009E; Fri, 3 Jan 2025 12:44:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F05766B009F; Fri, 3 Jan 2025 12:44:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D0A546B00A0; Fri, 3 Jan 2025 12:44:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id B00406B009E for ; Fri, 3 Jan 2025 12:44:24 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 75E1D1608A0 for ; Fri, 3 Jan 2025 17:44:24 +0000 (UTC) X-FDA: 82966862244.03.71CBDD1 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf16.hostedemail.com (Postfix) with ESMTP id 14F51180018 for ; Fri, 3 Jan 2025 17:43:29 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=gHVNUPVz; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf16.hostedemail.com: domain of sj@kernel.org designates 147.75.193.91 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=1735926239; 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=9JAlw7XvehbdsMTJw6PdqdFa818K21BGIHZWKFbMOIE=; b=kXUju7wgxpUEAoflNI/jsQvGml+yZLXbIkz23UalUhnN1OlPxrS/svrN/lBtmCcUwq2ixU XjkXqEcbXoH9qgQaz3Af9AanV/5K8/lnmtoPxf4OHV19PAnkaVAxjlUA1tEfrVu+HIpcDB uIdIQF0XQ7WJThgUcziRGmciydzvdMU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1735926239; a=rsa-sha256; cv=none; b=M6NQlc0KKYDsMd150QIqDPXZlntG6vWR5i6tQYnCsdnSJHhVKlzSRXnjuWvf2MZPXeD63u um6jyktqEQWMBN3xA6vjnb/u6xKqTkrCUMPJ9QdqsJaQsR1PnGZd0mFc+7XT/kKgd0NCxF 2iC/F0bJB+fBPq6l4O1C5CW+l01FcaU= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=gHVNUPVz; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf16.hostedemail.com: domain of sj@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=sj@kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id F0941A41046; Fri, 3 Jan 2025 17:42:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B3FD3C4CEDC; Fri, 3 Jan 2025 17:44:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735926262; bh=OfM4+ASQzquOI9PQ720oHjnGo91lYu+MMlnD/0TFf7o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gHVNUPVzUGN38B0q75yQWFjNnyOmqoa/GJd9qHGqQYcBF78X8Cf8fSVaxmKX6KBqk 8fX944GYefToDwQPcTmtgWR1bUG2J9ZUJ8LHX2w3qzit1SWrLyNlqN97plh/mChReB dyhT3jBPAvIPNIOjAQrAzv826X0+tDYkHTrQBSjMf89J6O5s6nBr6EXEEtDjeINQ6+ HawS40sZ66R2Loi/gcGbvMHmganax0t/3+o+agJ1LONDjYjRpee+vvQuWZhA/G/uYM au3+FH5OYBMhfq4mW1D3/b4h2N6dE3k/Fs1I2xP4KzH/0SH6OhZwlQFHsLqU0W8qNk 5UZhgsiU5nOSA== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 10/10] mm/damon/sysfs: remove unused code for schemes tried regions update Date: Fri, 3 Jan 2025 09:44:00 -0800 Message-Id: <20250103174400.54890-11-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250103174400.54890-1-sj@kernel.org> References: <20250103174400.54890-1-sj@kernel.org> MIME-Version: 1.0 X-Stat-Signature: pooiynn1oh1p3mxcm5oiz8xz1f1kdpxe X-Rspamd-Queue-Id: 14F51180018 X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1735926209-298818 X-HE-Meta: U2FsdGVkX1/NReWPyOjwaleldCdlJQ8VO6pB246TaRnJyN3hIOuZLWzop4fhBhQjBpqBQmPLAMRQC+0B6zcO6hqmmuOzXAh1YhNP2eh+REUx8K+T0jcihTRn2Oe/1ogMakjRsESUO07965IJRVKoq0aF4p8rFxFGw9Snni+HlnaBpShyvap1fGD2JC5srkHUnDNYT2C3dt+p466xN2n/EHqq8Fn1PwziXaAtYGdROCQBFDlICmRaDrKi7pVKKvxDz5tgD6yxn8S8UzQVLcawfrKkPhyV81+mC9FhF4ofVGab3SP+jvATBjSHJGo2itWBPQ2wwQC2hFaPEuv/rUFsO5FMUPKzGGLMGX6UrlykWNaLUjoLQPc9x6ijzUlh3AX32jToQNxJsR03p61X/aJBRwIGEKR/f7+qrD5AB6f82QmuOFVc5R2ewOPv57Rx4DETPuW0dkXdPkTVMiQjabG+VQcJvL4xKSjz1Yqim6a/TO6Q+Ha7cSCWSA17yrHy5X+AK8o/ShWa+tkYVvdbTXgNSA/a1Fh54nlz4WqG/HOOk7KqStf40PtbcO+5PSzR5ws8ekSt1fZztYsS1pdQY1w2mkZyuJAXdthaYslQH7+S7zdZRYbl6qmGMRFAgXv1cud4btgxXKzG4u9pKvp+C+/cjzJFVsxgmHNLYAvPTkjEU1mlxky8ZDJ71TI9IBP2TfWmvdT0HaMNvfdR5+4Dt+2Cfjvx5eeDYBiYR/w3pc5xiTlCAIysYs2AKejaykrwZM3ewIGX/Fz7o32sZozQM5tER7RhPJogyrmYJvR+zDTQDfvkgTkFnxnNYhv7fumcgzeuNKFxulknkyk6hw7HQUaejo4J89FYxPVaOIOoagyJbYzWn0yxOpDDJl5vOISss45Gmoa1Wi67vbB0wmLQGdkc5oq3+gkUGFZouCvDwAiVrcnzTLrDB9Hb+4hDVus8b8O0Jqn41F4sgKJTlK4YtSR 50GNXhht SpDQqPimWGa4yKLFPfhWbZxsMY43/5YkDXgED/95kTSAsbsqvevlcNUeLvI57vAJMpbs7teVqyPB6TYv296G3rYZuZqT2hDMD9q3Zf0hJQxHQhtijswFvqd4rcIakssOCm7n4LzH8ojKRfnGBN84/HPl/ntiX9i/5s6EnIi29s8Q6Y4ySYXqhCQQSr42807KeiqmhY8Azci6dBoVwagSXZ8vZezgLUnNNdRtvi74fvn/VXBE= 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 was using damon_callback with its own complicated synchronization logics to update DAMOS scheme applied regions directories and files. But it is replaced to use damos_walk(), and the additional synchronization logics are no more being used. Remove those. Signed-off-by: SeongJae Park --- mm/damon/sysfs-common.h | 10 -- mm/damon/sysfs-schemes.c | 204 --------------------------------------- mm/damon/sysfs.c | 70 +------------- 3 files changed, 2 insertions(+), 282 deletions(-) diff --git a/mm/damon/sysfs-common.h b/mm/damon/sysfs-common.h index 81f1c845118f..b3f63bc658b7 100644 --- a/mm/damon/sysfs-common.h +++ b/mm/damon/sysfs-common.h @@ -45,16 +45,6 @@ void damon_sysfs_schemes_update_stats( struct damon_sysfs_schemes *sysfs_schemes, struct damon_ctx *ctx); -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); - void damos_sysfs_populate_region_dir(struct damon_sysfs_schemes *sysfs_schemes, struct damon_ctx *ctx, struct damon_target *t, struct damon_region *r, struct damos *s, diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index 1d8ad637051a..5c4490b97258 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -114,55 +114,11 @@ 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() - * callback. - * - * Then, the first followup ->before_damos_apply() callback - * (damon_sysfs_before_damos_apply()) sets the status 'started'. The first - * ->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, - * ->before_damos_apply() will not be called back. Until the situation is - * changed, the update will not be finished. To avoid this, - * damon_sysfs_after_sampling() set the status as 'finished' if more than two - * apply intervals of the scheme is passed while the state is 'idle'. - * - * 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; - unsigned long upd_timeout_jiffies; }; static struct damon_sysfs_scheme_regions * @@ -178,7 +134,6 @@ 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; } @@ -2126,63 +2081,6 @@ void damon_sysfs_schemes_update_stats( } } -/* - * damon_sysfs_schemes that need to update its schemes regions dir. Protected - * by damon_sysfs_lock - */ -static struct damon_sysfs_schemes *damon_sysfs_schemes_for_damos_callback; -static int damon_sysfs_schemes_region_idx; -static bool damos_regions_upd_total_bytes_only; - -/* - * DAMON callback that called before damos apply. While this callback is - * registered, damon_sysfs_lock should be held to ensure the regions - * directories exist. - */ -static int damon_sysfs_before_damos_apply(struct damon_ctx *ctx, - struct damon_target *t, struct damon_region *r, - struct damos *s) -{ - struct damos *scheme; - struct damon_sysfs_scheme_regions *sysfs_regions; - struct damon_sysfs_scheme_region *region; - struct damon_sysfs_schemes *sysfs_schemes = - damon_sysfs_schemes_for_damos_callback; - int schemes_idx = 0; - - damon_for_each_scheme(scheme, ctx) { - if (scheme == s) - break; - schemes_idx++; - } - - /* user could have removed the scheme sysfs dir */ - if (schemes_idx >= sysfs_schemes->nr) - 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; - - region = damon_sysfs_scheme_region_alloc(r); - if (!region) - return 0; - list_add_tail(®ion->list, &sysfs_regions->regions_list); - sysfs_regions->nr_regions++; - if (kobject_init_and_add(®ion->kobj, - &damon_sysfs_scheme_region_ktype, - &sysfs_regions->kobj, "%d", - damon_sysfs_schemes_region_idx++)) { - kobject_put(®ion->kobj); - } - return 0; -} - /** * damos_sysfs_populate_region_dir() - Populate a schemes tried region dir. * @sysfs_schemes: Schemes directory to populate regions directory. @@ -2231,29 +2129,6 @@ void damos_sysfs_populate_region_dir(struct damon_sysfs_schemes *sysfs_schemes, } } -/* - * 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. - */ -void damos_sysfs_mark_finished_regions_updates(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 || - time_after(jiffies, - sysfs_regions->upd_timeout_jiffies)) - sysfs_regions->upd_status = - DAMOS_TRIED_REGIONS_UPD_FINISHED; - } -} - /* Called from damon_sysfs_cmd_request_callback under damon_sysfs_lock */ int damon_sysfs_schemes_clear_regions( struct damon_sysfs_schemes *sysfs_schemes) @@ -2270,82 +2145,3 @@ int damon_sysfs_schemes_clear_regions( } return 0; } - -static struct damos *damos_sysfs_nth_scheme(int n, struct damon_ctx *ctx) -{ - struct damos *scheme; - int i = 0; - - damon_for_each_scheme(scheme, ctx) { - if (i == n) - return scheme; - i++; - } - return NULL; -} - -static void damos_tried_regions_init_upd_status( - struct damon_sysfs_schemes *sysfs_schemes, - struct damon_ctx *ctx) -{ - int i; - struct damos *scheme; - struct damon_sysfs_scheme_regions *sysfs_regions; - - for (i = 0; i < sysfs_schemes->nr; i++) { - sysfs_regions = sysfs_schemes->schemes_arr[i]->tried_regions; - scheme = damos_sysfs_nth_scheme(i, ctx); - if (!scheme) { - sysfs_regions->upd_status = - DAMOS_TRIED_REGIONS_UPD_FINISHED; - continue; - } - sysfs_regions->upd_status = DAMOS_TRIED_REGIONS_UPD_IDLE; - sysfs_regions->upd_timeout_jiffies = jiffies + - 2 * usecs_to_jiffies(scheme->apply_interval_us ? - scheme->apply_interval_us : - ctx->attrs.aggr_interval); - } -} - -/* Called while damon_sysfs_lock is hold */ -int damon_sysfs_schemes_update_regions_start( - struct damon_sysfs_schemes *sysfs_schemes, - struct damon_ctx *ctx, bool total_bytes_only) -{ - damon_sysfs_schemes_clear_regions(sysfs_schemes); - damon_sysfs_schemes_for_damos_callback = sysfs_schemes; - 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; - 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 - * damon_sysfs_schemes_update_regions_start() - */ -int damon_sysfs_schemes_update_regions_stop(struct damon_ctx *ctx) -{ - damon_sysfs_schemes_for_damos_callback = NULL; - ctx->callback.before_damos_apply = NULL; - damon_sysfs_schemes_region_idx = 0; - return 0; -} diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 4ba44a314f2e..cf8fb5a963d6 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1181,25 +1181,9 @@ static int damon_sysfs_add_targets(struct damon_ctx *ctx, return 0; } -static bool damon_sysfs_schemes_regions_updating; - static void damon_sysfs_before_terminate(struct damon_ctx *ctx) { struct damon_target *t, *next; - struct damon_sysfs_kdamond *kdamond; - enum damon_sysfs_cmd cmd; - - /* damon_sysfs_schemes_update_regions_stop() might not yet called */ - kdamond = damon_sysfs_cmd_request.kdamond; - cmd = damon_sysfs_cmd_request.cmd; - if (kdamond && ctx == kdamond->damon_ctx && - (cmd == DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_REGIONS || - cmd == DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_BYTES) && - damon_sysfs_schemes_regions_updating) { - damon_sysfs_schemes_update_regions_stop(ctx); - damon_sysfs_schemes_regions_updating = false; - mutex_unlock(&damon_sysfs_lock); - } if (!damon_target_has_pid(ctx)) return; @@ -1232,28 +1216,6 @@ static int damon_sysfs_upd_schemes_stats(void *data) return 0; } -static int damon_sysfs_upd_schemes_regions_start( - struct damon_sysfs_kdamond *kdamond, bool total_bytes_only) -{ - struct damon_ctx *ctx = kdamond->damon_ctx; - - if (!ctx) - return -EINVAL; - return damon_sysfs_schemes_update_regions_start( - kdamond->contexts->contexts_arr[0]->schemes, ctx, - total_bytes_only); -} - -static int damon_sysfs_upd_schemes_regions_stop( - struct damon_sysfs_kdamond *kdamond) -{ - struct damon_ctx *ctx = kdamond->damon_ctx; - - if (!ctx) - return -EINVAL; - return damon_sysfs_schemes_update_regions_stop(ctx); -} - static inline bool damon_sysfs_kdamond_running( struct damon_sysfs_kdamond *kdamond) { @@ -1358,12 +1320,10 @@ 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; int err = 0; /* avoid deadlock due to concurrent state_store('off') */ - if (!damon_sysfs_schemes_regions_updating && - !mutex_trylock(&damon_sysfs_lock)) + if (!mutex_trylock(&damon_sysfs_lock)) return 0; kdamond = damon_sysfs_cmd_request.kdamond; if (!kdamond || kdamond->damon_ctx != c) @@ -1374,39 +1334,13 @@ static int damon_sysfs_cmd_request_callback(struct damon_ctx *c, bool active, goto out; err = damon_sysfs_commit_input(kdamond); break; - case DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_BYTES: - total_bytes_only = true; - fallthrough; - case DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_REGIONS: - if (!damon_sysfs_schemes_regions_updating) { - err = damon_sysfs_upd_schemes_regions_start(kdamond, - total_bytes_only); - if (!err) { - damon_sysfs_schemes_regions_updating = true; - 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 - * 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; - } - break; default: break; } /* Mark the request as invalid now. */ damon_sysfs_cmd_request.kdamond = NULL; out: - if (!damon_sysfs_schemes_regions_updating) - mutex_unlock(&damon_sysfs_lock); -keep_lock_out: + mutex_unlock(&damon_sysfs_lock); return err; }