From nobody Wed Dec 17 16:09:41 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9A3011FBEAE; Fri, 3 Jan 2025 17:44:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735926252; cv=none; b=eLQOY1IMUXmtY5T6HH2yQ64kpLAMc5ZSGI2qqlN6+GB/Uw/8abmY3GU5e9mFksXfIi930qozJdOJZ61XMYy2slNV3V15f5voctj9f1XEbDUPigaEX833rBypSRHcr4NfhsfYHEkW0YqALOHjsjZkSS+8IfaG7WbRzyQ89Jf7/R0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735926252; c=relaxed/simple; bh=KNH5L0vNE8h71jgUkE2/vzFAwU/o8fScb4koo5cYPcs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=SHGKdB8mvdWKgzT2ppDdU/5KaiYGQgb97ydonHBs+kiS/xSLSZMY9p96zlWfmgNpk43IBaE/6P6prankGPkjY2+Y90xU/+32QQfUA7gsDNqh7Z2bEcI6Kuq+iD5HPcuxfax/6q1HZ9PnIlmO2l1/i4fgfbOv19xvyxfWalj+X0g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sACGoN3o; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="sACGoN3o" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E0C5FC4CECE; Fri, 3 Jan 2025 17:44:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735926252; bh=KNH5L0vNE8h71jgUkE2/vzFAwU/o8fScb4koo5cYPcs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sACGoN3oL+qwmja5AyRlGWax/gmJ7baYZ8musT1+Y6A1MPgca3vfNzf8XXzRkSMjH hCw1QsDoq6drVuV/DXW1R4bcC2ob9088NIgVmHq/uVIWuTXByszHUxOOorTko7oxwq THKL+O/rRfBi7xwcWLj9Ma3GxkX1WF/5keErrkRGRDj/WXF9yCSK4aw6O4ue0vhdfb 61w1MUczMR4N4G8Lbj2vJfik7dAXNW/6/QC+aAEGO46FCdGGxyxmQZbbEsWZZKMVkN DRk+oi3J5OiklmLjWBta2DEYurJHYKkOVn5YdoH4hE4BC9Y0Kn10jgfvcasKDQYoIE ah8Aa2FfMtn+A== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 01/10] mm/damon/sysfs-schemes: remove unnecessary schemes existence check in damon_sysfs_schemes_clear_regions() Date: Fri, 3 Jan 2025 09:43:51 -0800 Message-Id: <20250103174400.54890-2-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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" damon_sysfs_schemes_clear_regions() skips removing the scheme tried region directories only if the matching scheme is still ongoing. It is unnecessary check, since what users want is just removing the entire region directories. Remove the unnecessary check. Signed-off-by: SeongJae Park --- mm/damon/sysfs-common.h | 3 +-- mm/damon/sysfs-schemes.c | 16 +++++----------- mm/damon/sysfs.c | 2 +- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/mm/damon/sysfs-common.h b/mm/damon/sysfs-common.h index 9a18f3c535d3..e79b4a65ff2d 100644 --- a/mm/damon/sysfs-common.h +++ b/mm/damon/sysfs-common.h @@ -56,8 +56,7 @@ bool damos_sysfs_regions_upd_done(void); int damon_sysfs_schemes_update_regions_stop(struct damon_ctx *ctx); =20 int damon_sysfs_schemes_clear_regions( - struct damon_sysfs_schemes *sysfs_schemes, - struct damon_ctx *ctx); + struct damon_sysfs_schemes *sysfs_schemes); =20 int damos_sysfs_set_quota_scores(struct damon_sysfs_schemes *sysfs_schemes, struct damon_ctx *ctx); diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index b095457380b5..2aa34778a472 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -2208,20 +2208,14 @@ void damos_sysfs_mark_finished_regions_updates(stru= ct damon_ctx *ctx) =20 /* Called from damon_sysfs_cmd_request_callback under damon_sysfs_lock */ int damon_sysfs_schemes_clear_regions( - struct damon_sysfs_schemes *sysfs_schemes, - struct damon_ctx *ctx) + struct damon_sysfs_schemes *sysfs_schemes) { - struct damos *scheme; - int schemes_idx =3D 0; + int i; =20 - damon_for_each_scheme(scheme, ctx) { + for (i =3D 0; i < sysfs_schemes->nr; i++) { struct damon_sysfs_scheme *sysfs_scheme; =20 - /* user could have removed the scheme sysfs dir */ - if (schemes_idx >=3D sysfs_schemes->nr) - break; - - sysfs_scheme =3D sysfs_schemes->schemes_arr[schemes_idx++]; + sysfs_scheme =3D sysfs_schemes->schemes_arr[i]; damon_sysfs_scheme_regions_rm_dirs( sysfs_scheme->tried_regions); sysfs_scheme->tried_regions->total_bytes =3D 0; @@ -2271,7 +2265,7 @@ 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, ctx); + damon_sysfs_schemes_clear_regions(sysfs_schemes); damon_sysfs_schemes_for_damos_callback =3D sysfs_schemes; damos_tried_regions_init_upd_status(sysfs_schemes, ctx); damos_regions_upd_total_bytes_only =3D total_bytes_only; diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 58145d59881d..789804986ab0 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1262,7 +1262,7 @@ static int damon_sysfs_clear_schemes_regions( if (!ctx) return -EINVAL; return damon_sysfs_schemes_clear_regions( - kdamond->contexts->contexts_arr[0]->schemes, ctx); + kdamond->contexts->contexts_arr[0]->schemes); } =20 static inline bool damon_sysfs_kdamond_running( --=20 2.39.5 From nobody Wed Dec 17 16:09:41 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 922181FC111; Fri, 3 Jan 2025 17:44:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735926253; cv=none; b=nOdUT4u80vI0JsP9YjNrATwxyUvm6qAWlMHm1WC7ErVZYX/cy0Uowy7YHP0SXyQwEuC16ilx8OZkRuorMl+ja/TcbdyAdAfvbT4rqFmJwPiglPe1/O26sS8vL7Z/Eey0Cv3A6gs6mOR+n6yCpFHryBEne4Sjqsyp6rOwASekwxw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735926253; c=relaxed/simple; bh=HDW7FthU1uRvJZ3MkhWqZ07vrMNtcqEXeZfp37Ljvk0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HV452AlKxl24yMXbGYuywiM+psnl1oz/jc9r/1zFL0lMQ5XJnDdBtlx1frH1bbU1JCBttmBmEO69YzQNp//lxO/zE0x84vP1ju2/vUrA40FHbG+hJh0u1yBkmO0KhStKg2qdlEECWohf8m71orrUNRtoLkQjSfIo0dHtlntt+1g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=O4ZPHopH; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="O4ZPHopH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 02C2CC4CED6; Fri, 3 Jan 2025 17:44:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735926253; bh=HDW7FthU1uRvJZ3MkhWqZ07vrMNtcqEXeZfp37Ljvk0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O4ZPHopHQ4zwcT/ioK5B4zxE+LQ9Jblr6ZzjHB8UoIGpZkpSGE40nGqMLk/0MtGNv QSwWX1u63oc08L37F/G7LjqtBKn/UOv0mxeVv+5G4apc+W5noR+RcRNrwCE4GaLfCk TsmYIJlW5tnIZ2ugEFATGMPQffvTm/7jhZMVJXJ6iwnk/0PLFOP//qcXQlzt1dlwvI 6NC2FP1Dx7CYJNq+IQ4Sv+TD6AohzmbZtczclEbxyDJAPRVzzcqts6Il/yQ30ifkyx KJo3F0lyuXFp/lQ8TtuvDhBPby8BNLqvL1Ginb1s6ZdS82tUuNpRn8HHHBF6/zuh46 AO7OUX81CjKGQ== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 02/10] mm/damon/sysfs: handle clear_schemes_tried_regions from DAMON sysfs context Date: Fri, 3 Jan 2025 09:43:52 -0800 Message-Id: <20250103174400.54890-3-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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" DAMON sysfs interface handles clear_schemes_tried_regions request from the DAMON callback context (damon_sysfs_cmd_request_callback()), which is designed to be used for safe access to the related DAMON context internal data. But no DAMON context internal data is accessed for the work. Directly handle it from DAMON sysfs interface context, namely damon_sysfs_handle_cmd(). Signed-off-by: SeongJae Park --- mm/damon/sysfs-schemes.c | 2 +- mm/damon/sysfs.c | 17 +++-------------- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index 2aa34778a472..c57ab47686ff 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -2260,7 +2260,7 @@ static void damos_tried_regions_init_upd_status( } } =20 -/* Called from damon_sysfs_cmd_request_callback under damon_sysfs_lock */ +/* 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) diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 789804986ab0..4f6e4720b7ce 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1254,17 +1254,6 @@ static int damon_sysfs_upd_schemes_regions_stop( return damon_sysfs_schemes_update_regions_stop(ctx); } =20 -static int damon_sysfs_clear_schemes_regions( - struct damon_sysfs_kdamond *kdamond) -{ - struct damon_ctx *ctx =3D kdamond->damon_ctx; - - if (!ctx) - return -EINVAL; - return damon_sysfs_schemes_clear_regions( - kdamond->contexts->contexts_arr[0]->schemes); -} - static inline bool damon_sysfs_kdamond_running( struct damon_sysfs_kdamond *kdamond) { @@ -1417,9 +1406,6 @@ static int damon_sysfs_cmd_request_callback(struct da= mon_ctx *c, bool active, damon_sysfs_schemes_regions_updating =3D false; } break; - case DAMON_SYSFS_CMD_CLEAR_SCHEMES_TRIED_REGIONS: - err =3D damon_sysfs_clear_schemes_regions(kdamond); - break; case DAMON_SYSFS_CMD_UPDATE_SCHEMES_EFFECTIVE_QUOTAS: err =3D damon_sysfs_upd_schemes_effective_quotas(kdamond); break; @@ -1549,6 +1535,9 @@ static int damon_sysfs_handle_cmd(enum damon_sysfs_cm= d cmd, return damon_sysfs_turn_damon_on(kdamond); case DAMON_SYSFS_CMD_OFF: return damon_sysfs_turn_damon_off(kdamond); + case DAMON_SYSFS_CMD_CLEAR_SCHEMES_TRIED_REGIONS: + return damon_sysfs_schemes_clear_regions( + kdamond->contexts->contexts_arr[0]->schemes); default: break; } --=20 2.39.5 From nobody Wed Dec 17 16:09:41 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AFFDF1FC7E8; Fri, 3 Jan 2025 17:44:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735926254; cv=none; b=MzDxr18nzwbFcHrVlnH1ZSsCYhlek2ONQp/hR/DO8rqt1WA6JAaUEukJbNd1YgkmOvASv37Oq16hYm/refnVP4L9OSh0jgcpy/mjiPdj3A7LWmsuwoj5yRdoDS9SYLqv6ly67ub3HTIUVs8d953YVE2XbyQs3VkXh0c+IouQM+0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735926254; c=relaxed/simple; bh=JNkpoBSJiwe93XL962RE5R1ynJv2g3n6CCV3Kyol5/0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=t6dLzkDwAYsufpRnUERQlX3eQDsmYbLAD4sWkjbR8wig6Cqvy5PoFPfDOEwK3M2CmPVTJIGu00AhKpAR98VfgAoMT3pWd7Bj1XqfYj4DTgvO/8dwstfPH09OqBuzHW0oxxN6G4Moy4TREDZeLh14uQBcegSz+5atj8hh8kjC4Fs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qpu/k9+9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="qpu/k9+9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1274DC4CECE; Fri, 3 Jan 2025 17:44:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735926254; bh=JNkpoBSJiwe93XL962RE5R1ynJv2g3n6CCV3Kyol5/0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qpu/k9+9YSU7eTA3ClaCp7f1fEbo8Y70eSTguSBhya0DXCc0VjaqGUxE1sa356iNY 4btMs7/D2rf/yQsum03Nzf1vbAp7ZG2QdAApH6XDkNcK7gttcahF2zLBq+tRTfCxgi aLM8AWc/Rde2IKCQAkeCWL1KoedEMklGBEE4EZtzWh4lXHqPt94AtjoqsemaQXcriZ UgMfZgATz0uIPr+Knfg1C43PytEkgyYZkYdsf59EMqs+nN4MVFV5WK+v5h/c2GybEN 8EgB9v4qbBlrVEKKPhBIVJhZAW0XHaQ1uVAJzFs9btRwRl1SU/MeMm4dkUbTTlOVZ2 5eogb+SVumsOw== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 03/10] mm/damon/core: introduce damon_call() Date: Fri, 3 Jan 2025 09:43:53 -0800 Message-Id: <20250103174400.54890-4-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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Introduce a new DAMON core API function, damon_call(). It aims to replace some damon_callback usages that access damon_ctx of ongoing kdamond with additional synchronizations. It receives a function pointer, let the parallel kdamond invokes the function, and returns after the invocation is finished, or canceled due to some races. kdamond invokes the function inside the main loop after sampling is done. If it is deactivated by DAMOS watermarks or already out of the main loop, mark the request as canceled so that damon_call() can wakeup and return. Signed-off-by: SeongJae Park --- include/linux/damon.h | 26 +++++++++++++ mm/damon/core.c | 86 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+) diff --git a/include/linux/damon.h b/include/linux/damon.h index a67f2c4940e9..ac2d42a50751 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -552,6 +552,27 @@ struct damon_callback { void (*before_terminate)(struct damon_ctx *context); }; =20 +/* + * struct damon_call_control - Control damon_call(). + * + * @fn: Function to be called back. + * @data: Data that will be passed to @fn. + * @return_code: Return code from @fn invocation. + * + * Control damon_call(), which requests specific kdamond to invoke a given + * function. Refer to damon_call() for more details. + */ +struct damon_call_control { + int (*fn)(void *data); + void *data; + int return_code; +/* private: internal use only */ + /* informs if the kdamond finished handling of the request */ + struct completion completion; + /* informs if the kdamond canceled @fn infocation */ + bool canceled; +}; + /** * struct damon_attrs - Monitoring attributes for accuracy/overhead contro= l. * @@ -632,6 +653,9 @@ struct damon_ctx { /* for scheme quotas prioritization */ unsigned long *regions_score_histogram; =20 + struct damon_call_control *call_control; + struct mutex call_control_lock; + /* public: */ struct task_struct *kdamond; struct mutex kdamond_lock; @@ -779,6 +803,8 @@ static inline unsigned int damon_max_nr_accesses(const = struct damon_attrs *attrs int damon_start(struct damon_ctx **ctxs, int nr_ctxs, bool exclusive); int damon_stop(struct damon_ctx **ctxs, int nr_ctxs); =20 +int damon_call(struct damon_ctx *ctx, struct damon_call_control *control); + int damon_set_region_biggest_system_ram_default(struct damon_target *t, unsigned long *start, unsigned long *end); =20 diff --git a/mm/damon/core.c b/mm/damon/core.c index 5192ee29f6cf..97f19ec4179c 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -504,6 +504,7 @@ struct damon_ctx *damon_new_ctx(void) ctx->next_ops_update_sis =3D 0; =20 mutex_init(&ctx->kdamond_lock); + mutex_init(&ctx->call_control_lock); =20 ctx->attrs.min_nr_regions =3D 10; ctx->attrs.max_nr_regions =3D 1000; @@ -1162,6 +1163,54 @@ int damon_stop(struct damon_ctx **ctxs, int nr_ctxs) return err; } =20 +static bool damon_is_running(struct damon_ctx *ctx) +{ + bool running; + + mutex_lock(&ctx->kdamond_lock); + running =3D ctx->kdamond !=3D NULL; + mutex_unlock(&ctx->kdamond_lock); + return running; +} + +/** + * damon_call() - Invoke a given function on DAMON worker thread (kdamond). + * @ctx: DAMON context to call the function for. + * @control: Control variable of the call request. + * + * Ask DAMON worker thread (kdamond) of @ctx to call a function with an + * argument data that respectively passed via &damon_call_control->fn and + * &damon_call_control->data of @control, and wait until the kdamond finis= hes + * handling of the request. + * + * The kdamond executes the function with the argument in the main loop, j= ust + * after a sampling of the iteration is finished. The function can hence + * safely access the internal data of the &struct damon_ctx without additi= onal + * synchronization. The return value of the function will be saved in + * &damon_call_control->return_code. + * + * Return: 0 on success, negative error code otherwise. + */ +int damon_call(struct damon_ctx *ctx, struct damon_call_control *control) +{ + init_completion(&control->completion); + control->canceled =3D false; + + mutex_lock(&ctx->call_control_lock); + if (ctx->call_control) { + mutex_unlock(&ctx->call_control_lock); + return -EBUSY; + } + ctx->call_control =3D control; + mutex_unlock(&ctx->call_control_lock); + if (!damon_is_running(ctx)) + return -EINVAL; + wait_for_completion(&control->completion); + if (control->canceled) + return -ECANCELED; + return 0; +} + /* * Reset the aggregated monitoring results ('nr_accesses' of each region). */ @@ -1917,6 +1966,39 @@ static void kdamond_usleep(unsigned long usecs) usleep_range_idle(usecs, usecs + 1); } =20 +/* + * kdamond_call() - handle damon_call_control. + * @ctx: The &struct damon_ctx of the kdamond. + * @cancel: Whether to cancel the invocation of the function. + * + * If there is a &struct damon_call_control request that registered via + * &damon_call() on @ctx, do or cancel the invocation of the function depe= nding + * on @cancel. @cancel is set when the kdamond is deactivated by DAMOS + * watermarks, or the kdamond is already out of the main loop and therefore + * will be terminated. + */ +static void kdamond_call(struct damon_ctx *ctx, bool cancel) +{ + struct damon_call_control *control; + int ret =3D 0; + + mutex_lock(&ctx->call_control_lock); + control =3D ctx->call_control; + mutex_unlock(&ctx->call_control_lock); + if (!control) + return; + if (cancel) { + control->canceled =3D true; + } else { + ret =3D control->fn(control->data); + control->return_code =3D ret; + } + complete(&control->completion); + mutex_lock(&ctx->call_control_lock); + ctx->call_control =3D NULL; + mutex_unlock(&ctx->call_control_lock); +} + /* Returns negative error code if it's not activated but should return */ static int kdamond_wait_activation(struct damon_ctx *ctx) { @@ -1941,6 +2023,7 @@ static int kdamond_wait_activation(struct damon_ctx *= ctx) if (ctx->callback.after_wmarks_check && ctx->callback.after_wmarks_check(ctx)) break; + kdamond_call(ctx, true); } return -EBUSY; } @@ -2011,6 +2094,7 @@ static int kdamond_fn(void *data) if (ctx->callback.after_sampling && ctx->callback.after_sampling(ctx)) break; + kdamond_call(ctx, false); =20 kdamond_usleep(sample_interval); ctx->passed_sample_intervals++; @@ -2072,6 +2156,8 @@ static int kdamond_fn(void *data) ctx->kdamond =3D NULL; mutex_unlock(&ctx->kdamond_lock); =20 + kdamond_call(ctx, true); + mutex_lock(&damon_lock); nr_running_ctxs--; if (!nr_running_ctxs && running_exclusive_ctxs) --=20 2.39.5 From nobody Wed Dec 17 16:09:41 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D1A3A1FBEAE; Fri, 3 Jan 2025 17:44:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735926255; cv=none; b=pFRmrLUYBXhEbqxHd74V3KaD9r8agNVPD0XMQaUidmOWI5gjstK8ptN++6R/ZsN1ddjnXocDZ4FW/CxMqQ2mYBm968RAlGUzoibDdfkiIanqxVmgQJ4PR3N6heled9vnRTb+tRDbpJQ/hV5TWdcaeJ2dSSip9nS85nrffctVBBs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735926255; c=relaxed/simple; bh=qk6ZdrhnjRXiXYePVN+xCb4IJkjveXFxA9K3vfVDUfI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=R4+91d2NX5mKG1Y2us2twzcg/VL4GAERhZHdcFUP9NWQOdxY17matrS+wkpLJSioRB5OFIE6jv+HyI5m+8AvpGQZUZ3vgYkTt9hN1nPvrzSXfm+hUexn96ymEvBeYNs3xZuwVRL8cMITy7r2gUGJ4OmXIsoXJWcJoWhdR/9vc2k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=meBCKp87; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="meBCKp87" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 398B4C4CECE; Fri, 3 Jan 2025 17:44:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735926255; bh=qk6ZdrhnjRXiXYePVN+xCb4IJkjveXFxA9K3vfVDUfI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=meBCKp87S8/jHRYo5pQv+UDGhWfNwcohyxDM33g3BrH0kRpqtKeAQB6pwOZGWNi96 PCGQJtL+kLXigtPuZPe/SmkC0tegfZAUxAZwsTPcqxLlgDB1EI45ZywZ6UH4y1PNLA brIbs5cNZHaTqccz77K++7sgaG6V8tSVZVuvo/7PFSiqjMRuTK1/QLeTzG0Qkkakch erXOL67rWcHV+OxAt5MIhi0Pvd1KUl153p6oA6SMwqrgffeD06+TglZXpSrV6iQD0T PZLyGcQUPBUJA8UWKfdb1WibxX3jO6mNCtHrXQ+mvUQf6+FnP66xfX8nsRO0UZfbNZ nVk9GaWjLWkFg== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 04/10] mm/damon/sysfs: use damon_call() for update_schemes_stats Date: Fri, 3 Jan 2025 09:43:54 -0800 Message-Id: <20250103174400.54890-5-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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" DAMON sysfs interface uses damon_callback with its own synchronization facility to handle update_schemes_stats kdamond command. But damon_call() can support the use case without the additional synchronizations. Convert the code to use damon_call() instead. Signed-off-by: SeongJae Park --- mm/damon/sysfs.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 4f6e4720b7ce..708c2ffdd620 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1214,19 +1214,19 @@ static void damon_sysfs_before_terminate(struct dam= on_ctx *ctx) =20 /* * damon_sysfs_upd_schemes_stats() - Update schemes stats sysfs files. - * @kdamond: The kobject wrapper that associated to the kdamond thread. + * @data: The kobject wrapper that associated to the kdamond thread. * * This function reads the schemes stats of specific kdamond and update the * related values for sysfs files. This function should be called from DA= MON - * callbacks while holding ``damon_syfs_lock``, to safely access the DAMON - * contexts-internal data and DAMON sysfs variables. + * worker thread,to safely access the DAMON contexts-internal data. Caller + * should also ensure holding ``damon_syfs_lock``, and ->damon_ctx of @dat= a is + * not NULL but a valid pointer, to safely access DAMON sysfs variables. */ -static int damon_sysfs_upd_schemes_stats(struct damon_sysfs_kdamond *kdamo= nd) +static int damon_sysfs_upd_schemes_stats(void *data) { + struct damon_sysfs_kdamond *kdamond =3D data; struct damon_ctx *ctx =3D kdamond->damon_ctx; =20 - if (!ctx) - return -EINVAL; damon_sysfs_schemes_update_stats( kdamond->contexts->contexts_arr[0]->schemes, ctx); return 0; @@ -1371,9 +1371,6 @@ static int damon_sysfs_cmd_request_callback(struct da= mon_ctx *c, bool active, if (!kdamond || kdamond->damon_ctx !=3D c) goto out; switch (damon_sysfs_cmd_request.cmd) { - case DAMON_SYSFS_CMD_UPDATE_SCHEMES_STATS: - err =3D damon_sysfs_upd_schemes_stats(kdamond); - break; case DAMON_SYSFS_CMD_COMMIT: if (!after_aggregation) goto out; @@ -1511,6 +1508,18 @@ static int damon_sysfs_turn_damon_off(struct damon_s= ysfs_kdamond *kdamond) */ } =20 +static int damon_sysfs_damon_call(int (*fn)(void *data), + struct damon_sysfs_kdamond *kdamond) +{ + struct damon_call_control call_control =3D {}; + + if (!kdamond->damon_ctx) + return -EINVAL; + call_control.fn =3D fn; + call_control.data =3D kdamond; + return damon_call(kdamond->damon_ctx, &call_control); +} + /* * damon_sysfs_handle_cmd() - Handle a command for a specific kdamond. * @cmd: The command to handle. @@ -1529,12 +1538,14 @@ static int damon_sysfs_handle_cmd(enum damon_sysfs_= cmd cmd, { bool need_wait =3D true; =20 - /* Handle commands that doesn't access DAMON context-internal data */ switch (cmd) { case DAMON_SYSFS_CMD_ON: return damon_sysfs_turn_damon_on(kdamond); case DAMON_SYSFS_CMD_OFF: return damon_sysfs_turn_damon_off(kdamond); + case DAMON_SYSFS_CMD_UPDATE_SCHEMES_STATS: + return damon_sysfs_damon_call( + damon_sysfs_upd_schemes_stats, kdamond); case DAMON_SYSFS_CMD_CLEAR_SCHEMES_TRIED_REGIONS: return damon_sysfs_schemes_clear_regions( kdamond->contexts->contexts_arr[0]->schemes); --=20 2.39.5 From nobody Wed Dec 17 16:09:41 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E9C7D19342B; Fri, 3 Jan 2025 17:44:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735926257; cv=none; b=ruKrblyRvRhvGTmoFA0Yr0N8uOdnDvr5s4tu5KgaKSBeAfMTgJ/fh35eBBTQLvyWb/RUQjsWRtRCBeHYS9CPPEShTKo5wDetZO31XwY9RjFOrI8Yqd0YBvA0nGUzxHe+v0+SJWMTqdk7LzoqzDfW1yOOAUGiGOSh/ZmSGR2RaDo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735926257; c=relaxed/simple; bh=Qli68w9RR6OLGHO/urSk5Kw3GxzgWY+dpbdZAM29uik=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=BCwIRWYs8v/v120x/Qtb1BXlMpS1MWgCPytTDVKzUC3fF6Pc12eLyn40CLqVr9ewABPjXC2RmTAfZaYOSpw7THcE20WcGODTcbmu5gvIBFg7wbFY7H64tSatRnsYmGPGilQ5zWApMAkwEsnfHj4jNRVXH1IHUv5MY+P6fGaw8TI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JgU/JbFv; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JgU/JbFv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 43D48C4CECE; Fri, 3 Jan 2025 17:44:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735926256; bh=Qli68w9RR6OLGHO/urSk5Kw3GxzgWY+dpbdZAM29uik=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JgU/JbFvqWQxRNZrwv2u3F+e81eK1EgkWJYkhOHqGLuj7+9iCsEdy8uz0/EUuv2no IDaP5sZ58eVF5W03tH3XdL0IA/sDRyGBeBeTprwsygO7K9AYfQdv3zJs8jfwS6yCzz Az07ONWHLy4u2Fl3svvpsN7qVGh3Nbb9GkmrSrCrNrByHVxlE6iRNLxFFVAvRQdJec ICTLWpnV+Fgj3ajHByMevRJKnExULKU1MfF/d3EgBupzZqtPZsxNNttxMTDzE0Ujik U5LUpgi07rIR8HyHfkT2HTBaLms/BaZDA6QIGEJFx3S2zIOYfqG9WvxbfjtSzMJZmJ qldWRQ/c7hwEQ== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 05/10] mm/damon/sysfs: use damon_call() for commit_schemes_quota_goals Date: Fri, 3 Jan 2025 09:43:55 -0800 Message-Id: <20250103174400.54890-6-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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" DAMON sysfs interface uses damon_callback with its own synchronization facility to handle commit_schemes_quota_goals command. But damon_call() can support the use case without the additional synchronizations. Convert the code to use damon_call() instead. Signed-off-by: SeongJae Park --- mm/damon/sysfs.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 708c2ffdd620..7c2aa9830edc 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1307,9 +1307,9 @@ static int damon_sysfs_commit_input(struct damon_sysf= s_kdamond *kdamond) return err; } =20 -static int damon_sysfs_commit_schemes_quota_goals( - struct damon_sysfs_kdamond *sysfs_kdamond) +static int damon_sysfs_commit_schemes_quota_goals(void *data) { + struct damon_sysfs_kdamond *sysfs_kdamond =3D data; struct damon_ctx *ctx; struct damon_sysfs_context *sysfs_ctx; =20 @@ -1376,9 +1376,6 @@ static int damon_sysfs_cmd_request_callback(struct da= mon_ctx *c, bool active, goto out; err =3D damon_sysfs_commit_input(kdamond); break; - case DAMON_SYSFS_CMD_COMMIT_SCHEMES_QUOTA_GOALS: - err =3D damon_sysfs_commit_schemes_quota_goals(kdamond); - break; case DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_BYTES: total_bytes_only =3D true; fallthrough; @@ -1543,6 +1540,10 @@ static int damon_sysfs_handle_cmd(enum damon_sysfs_c= md cmd, return damon_sysfs_turn_damon_on(kdamond); case DAMON_SYSFS_CMD_OFF: return damon_sysfs_turn_damon_off(kdamond); + case DAMON_SYSFS_CMD_COMMIT_SCHEMES_QUOTA_GOALS: + return damon_sysfs_damon_call( + damon_sysfs_commit_schemes_quota_goals, + kdamond); case DAMON_SYSFS_CMD_UPDATE_SCHEMES_STATS: return damon_sysfs_damon_call( damon_sysfs_upd_schemes_stats, kdamond); --=20 2.39.5 From nobody Wed Dec 17 16:09:41 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A83E61FCF60; Fri, 3 Jan 2025 17:44:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735926257; cv=none; b=lfK1CfGiDkynZ4KqyNuhnz1RPqkk0Rm2qjsJe+soP54nRY9JEZ6ERvLG+PzLjtLZM7jZpVr0ymvz4nlV3ddX4oZrbsvyDS2LfNiWZUIxpa5BLkyFmWOrFsdeNiebUakisz8KDMsBfjhOBPKRLvST4JQJnilcJP6b7DF+MqRTOP4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735926257; c=relaxed/simple; bh=rbTL8cU3TZPcyGMSlZELKJLzpLND/6Ckurwp21Ndpas=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FJFb6uPqvC7Z7goSdJJKCkeAnBv1t1zUJvlgSnETPVinjeE3VRxfYbXNzt6ixPCkzj7+jk40SPZMbbkIuHBtLZHicnvtgIGSxmMdcF8Nps+KQmXlRHogDlUk7adMxeDh1KAA1YQ1uJzOI+CJjJclIlTe+WTv/XK9EeLVd64bIjA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MuPud1XT; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MuPud1XT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5289BC4CECE; Fri, 3 Jan 2025 17:44:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735926257; bh=rbTL8cU3TZPcyGMSlZELKJLzpLND/6Ckurwp21Ndpas=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MuPud1XTNdpWjKxTAN4F+wbJsgLZvLdZYH0KJLmKth0kVsf7jVwQrLIHw+N9qN9R6 JOGu08x22H8puHME/3+1jyzKrSQ2kpZ5dsQqh3Ri2S78gs6ei4cNzMY/KbWjPDhxb5 brktRmfBHiV8+0idfOUVGxIYxBkjQ3y8FjOPcYxnReEPYn3RtpowsjpTx1GamBVUtl 3s80v0c25U5yS+KlQ2cNZR+khOnSCVHhK5c0nC/Ej3BqM8D+wGv8tWEc8tCcel6nYS JgvfDB5PTjJGwLdhXeHqZameoLpCeDOoNXj26IdqsTkS5DE4CJ+lH8Kfnl/t1rP2mz bDQvGVOa7XOyw== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 06/10] mm/damon/sysfs: use damon_call() for update_schemes_effective_quotas Date: Fri, 3 Jan 2025 09:43:56 -0800 Message-Id: <20250103174400.54890-7-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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" DAMON sysfs interface uses damon_callback with its own synchronization facility to handle update_schemes_effective_quotas command. But damon_call() can support the use case without the additional synchronizations. Convert the code to use damon_call() instead. Signed-off-by: SeongJae Park --- mm/damon/sysfs.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 7c2aa9830edc..917e6aca3f58 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1327,20 +1327,18 @@ static int damon_sysfs_commit_schemes_quota_goals(v= oid *data) /* * damon_sysfs_upd_schemes_effective_quotas() - Update schemes effective q= uotas * sysfs files. - * @kdamond: The kobject wrapper that associated to the kdamond thread. + * @data: The kobject wrapper that associated to the kdamond thread. * * This function reads the schemes' effective quotas of specific kdamond a= nd * update the related values for sysfs files. This function should be cal= led * from DAMON callbacks while holding ``damon_syfs_lock``, to safely acces= s the * DAMON contexts-internal data and DAMON sysfs variables. */ -static int damon_sysfs_upd_schemes_effective_quotas( - struct damon_sysfs_kdamond *kdamond) +static int damon_sysfs_upd_schemes_effective_quotas(void *data) { + struct damon_sysfs_kdamond *kdamond =3D data; struct damon_ctx *ctx =3D kdamond->damon_ctx; =20 - if (!ctx) - return -EINVAL; damos_sysfs_update_effective_quotas( kdamond->contexts->contexts_arr[0]->schemes, ctx); return 0; @@ -1400,9 +1398,6 @@ static int damon_sysfs_cmd_request_callback(struct da= mon_ctx *c, bool active, damon_sysfs_schemes_regions_updating =3D false; } break; - case DAMON_SYSFS_CMD_UPDATE_SCHEMES_EFFECTIVE_QUOTAS: - err =3D damon_sysfs_upd_schemes_effective_quotas(kdamond); - break; default: break; } @@ -1550,6 +1545,10 @@ static int damon_sysfs_handle_cmd(enum damon_sysfs_c= md cmd, case DAMON_SYSFS_CMD_CLEAR_SCHEMES_TRIED_REGIONS: return damon_sysfs_schemes_clear_regions( kdamond->contexts->contexts_arr[0]->schemes); + case DAMON_SYSFS_CMD_UPDATE_SCHEMES_EFFECTIVE_QUOTAS: + return damon_sysfs_damon_call( + damon_sysfs_upd_schemes_effective_quotas, + kdamond); default: break; } --=20 2.39.5 From nobody Wed Dec 17 16:09:41 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 19ED61FCFF0; Fri, 3 Jan 2025 17:44:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735926259; cv=none; b=pFhyw3eTq3P4TisYlV4cj+sRV/ALzRPZkaySG99Fyn7yfxg/oX/ejDMxP+YzDFbhiMqKD2ktNNmjfW9dMpVuK6Up9i2ByeR4qTirzGakz0mcBHY/ZIqg2dcnQV4n8q+ik+u5tP3Ft+VFEI+0UNjTNLlgDgHMKorzqjorfPMyfDQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735926259; c=relaxed/simple; bh=m5b1QRjgbQAvEoZjEHeueE5i8801YUauSjCf8Zy53xI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tKy1YYjm3FEf46JTlPac2W/ZOdshvRzV+MYbn6b++yxzmtB9f7k89SLPv5CA5RfpDIo24mUv1HWfoViaQqeAB/HCUhl8fcVxdkt8gxgshxGkB4HqddZ4QcHur7UrTWoES39Z3HbP/4kcllchKhVMfZGBJDAihNQ4fXpQjysrBAg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZLv4U/hV; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ZLv4U/hV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 69DFAC4CEDF; Fri, 3 Jan 2025 17:44:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735926258; bh=m5b1QRjgbQAvEoZjEHeueE5i8801YUauSjCf8Zy53xI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZLv4U/hVN3Y0MuHy/MBIajZjK+xUYPX2FItpYfDWr1wwBrI2Kudci/SO765zhI34m 3RiLgV0XDZQMjgEglDXEBftK112UMe3urGPBtOgCtB9+sRkWTd0UTSvG3wZ1JqjoAk ZwN7MOUhHjPO36bA+vVBD3ZqIbBMF4DbxzLbVS4+7BEMvf25gosl93kZJdBmgboVAx UiJJUTl3YCJe1dOgL9aGT28FMBeBeePjN4bzDJ65wD5SsV1IcXUsLGLRwJag4yZnnz tgMqFn5GZDtUa43WTmjDaOAx6n9hEK8reRblceC6H+JeMcAwsgJpuh/Ay9Gtg/3hd2 RAD1Ckl9hPvCw== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 07/10] mm/damon/core: implement damos_walk() Date: Fri, 3 Jan 2025 09:43:57 -0800 Message-Id: <20250103174400.54890-8-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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Introduce a new core layer interface, damos_walk(). It aims to replace some damon_callback usages that access DAMOS schemes applied regions of ongoing kdamond with additional synchronizations. It receives a function pointer and asks kdamond to invoke it for any region that it tried to apply any DAMOS action within one scheme apply interval for every scheme of it. The function further waits until the kdamond finishes the invocations for every scheme, or cancels the request, and returns. The kdamond invokes the function as requested within the main loop. If it is deactivated by DAMOS watermarks or going out of the main loop, it marks the request as canceled, so that damos_walk() can wakeup and return. Signed-off-by: SeongJae Park --- include/linux/damon.h | 33 ++++++++++- mm/damon/core.c | 132 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 163 insertions(+), 2 deletions(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index ac2d42a50751..2889de3526c3 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -352,6 +352,31 @@ struct damos_filter { struct list_head list; }; =20 +struct damon_ctx; +struct damos; + +/** + * struct damos_walk_control - Control damos_walk(). + * + * @walk_fn: Function to be called back for each region. + * @data: Data that will be passed to walk functions. + * + * Control damos_walk(), which requests specific kdamond to invoke the giv= en + * function to each region that eligible to apply actions of the kdamond's + * schemes. Refer to damos_walk() for more details. + */ +struct damos_walk_control { + void (*walk_fn)(void *data, struct damon_ctx *ctx, + struct damon_target *t, struct damon_region *r, + struct damos *s); + void *data; +/* private: internal use only */ + /* informs if the kdamond finished handling of the walk request */ + struct completion completion; + /* informs if the walk is canceled. */ + bool canceled; +}; + /** * struct damos_access_pattern - Target access pattern of the given scheme. * @min_sz_region: Minimum size of target regions. @@ -415,6 +440,8 @@ struct damos { * @action */ unsigned long next_apply_sis; + /* informs if ongoing DAMOS walk for this scheme is finished */ + bool walk_completed; /* public: */ struct damos_quota quota; struct damos_watermarks wmarks; @@ -442,8 +469,6 @@ enum damon_ops_id { NR_DAMON_OPS, }; =20 -struct damon_ctx; - /** * struct damon_operations - Monitoring operations for given use cases. * @@ -656,6 +681,9 @@ struct damon_ctx { struct damon_call_control *call_control; struct mutex call_control_lock; =20 + struct damos_walk_control *walk_control; + struct mutex walk_control_lock; + /* public: */ struct task_struct *kdamond; struct mutex kdamond_lock; @@ -804,6 +832,7 @@ int damon_start(struct damon_ctx **ctxs, int nr_ctxs, b= ool exclusive); int damon_stop(struct damon_ctx **ctxs, int nr_ctxs); =20 int damon_call(struct damon_ctx *ctx, struct damon_call_control *control); +int damos_walk(struct damon_ctx *ctx, struct damos_walk_control *control); =20 int damon_set_region_biggest_system_ram_default(struct damon_target *t, unsigned long *start, unsigned long *end); diff --git a/mm/damon/core.c b/mm/damon/core.c index 97f19ec4179c..d02a7d6da855 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -505,6 +505,7 @@ struct damon_ctx *damon_new_ctx(void) =20 mutex_init(&ctx->kdamond_lock); mutex_init(&ctx->call_control_lock); + mutex_init(&ctx->walk_control_lock); =20 ctx->attrs.min_nr_regions =3D 10; ctx->attrs.max_nr_regions =3D 1000; @@ -1211,6 +1212,46 @@ int damon_call(struct damon_ctx *ctx, struct damon_c= all_control *control) return 0; } =20 +/** + * damos_walk() - Invoke a given functions while DAMOS walk regions. + * @ctx: DAMON context to call the functions for. + * @control: Control variable of the walk request. + * + * Ask DAMON worker thread (kdamond) of @ctx to call a function for each r= egion + * that the kdamond will apply DAMOS action to, and wait until the kdamond + * finishes handling of the request. + * + * The kdamond executes the given function in the main loop, for each regi= on + * just after it applied any DAMOS actions of @ctx to it. The invocation = is + * made only within one &damos->apply_interval_us since damos_walk() + * invocation, for each scheme. The given callback function can hence saf= ely + * access the internal data of &struct damon_ctx and &struct damon_region = that + * each of the scheme will apply the action for next interval, without + * additional synchronizations against the kdamond. If every scheme of @c= tx + * passed at least one &damos->apply_interval_us, kdamond marks the reques= t as + * completed so that damos_walk() can wakeup and return. + * + * Return: 0 on success, negative error code otherwise. + */ +int damos_walk(struct damon_ctx *ctx, struct damos_walk_control *control) +{ + init_completion(&control->completion); + control->canceled =3D false; + mutex_lock(&ctx->walk_control_lock); + if (ctx->walk_control) { + mutex_unlock(&ctx->walk_control_lock); + return -EBUSY; + } + ctx->walk_control =3D control; + mutex_unlock(&ctx->walk_control_lock); + if (!damon_is_running(ctx)) + return -EINVAL; + wait_for_completion(&control->completion); + if (control->canceled) + return -ECANCELED; + return 0; +} + /* * Reset the aggregated monitoring results ('nr_accesses' of each region). */ @@ -1390,6 +1431,91 @@ static bool damos_filter_out(struct damon_ctx *ctx, = struct damon_target *t, return false; } =20 +/* + * damos_walk_call_walk() - Call &damos_walk_control->walk_fn. + * @ctx: The context of &damon_ctx->walk_control. + * @t: The monitoring target of @r that @s will be applied. + * @r: The region of @t that @s will be applied. + * @s: The scheme of @ctx that will be applied to @r. + * + * This function is called from kdamond whenever it asked the operation se= t to + * apply a DAMOS scheme action to a region. If a DAMOS walk request is + * installed by damos_walk() and not yet uninstalled, invoke it. + */ +static void damos_walk_call_walk(struct damon_ctx *ctx, struct damon_targe= t *t, + struct damon_region *r, struct damos *s) +{ + struct damos_walk_control *control; + + mutex_lock(&ctx->walk_control_lock); + control =3D ctx->walk_control; + mutex_unlock(&ctx->walk_control_lock); + if (!control) + return; + control->walk_fn(control->data, ctx, t, r, s); +} + +/* + * damos_walk_complete() - Complete DAMOS walk request if all walks are do= ne. + * @ctx: The context of &damon_ctx->walk_control. + * @s: A scheme of @ctx that all walks are now done. + * + * This function is called when kdamond finished applying the action of a = DAMOS + * scheme to all regions that eligible for the given &damos->apply_interva= l_us. + * If every scheme of @ctx including @s now finished walking for at least = one + * &damos->apply_interval_us, this function makrs the handling of the given + * DAMOS walk request is done, so that damos_walk() can wake up and return. + */ +static void damos_walk_complete(struct damon_ctx *ctx, struct damos *s) +{ + struct damos *siter; + struct damos_walk_control *control; + + mutex_lock(&ctx->walk_control_lock); + control =3D ctx->walk_control; + mutex_unlock(&ctx->walk_control_lock); + if (!control) + return; + + s->walk_completed =3D true; + /* if all schemes completed, signal completion to walker */ + damon_for_each_scheme(siter, ctx) { + if (!siter->walk_completed) + return; + } + complete(&control->completion); + mutex_lock(&ctx->walk_control_lock); + ctx->walk_control =3D NULL; + mutex_unlock(&ctx->walk_control_lock); +} + +/* + * damos_walk_cancel() - Cancel the current DAMOS walk request. + * @ctx: The context of &damon_ctx->walk_control. + * + * This function is called when @ctx is deactivated by DAMOS watermarks, D= AMOS + * walk is requested but there is no DAMOS scheme to walk for, or the kdam= ond + * is already out of the main loop and therefore gonna be terminated, and = hence + * cannot continue the walks. This function therefore marks the walk requ= est + * as canceled, so that damos_walk() can wake up and return. + */ +static void damos_walk_cancel(struct damon_ctx *ctx) +{ + struct damos_walk_control *control; + + mutex_lock(&ctx->walk_control_lock); + control =3D ctx->walk_control; + mutex_unlock(&ctx->walk_control_lock); + + if (!control) + return; + control->canceled =3D true; + complete(&control->completion); + mutex_lock(&ctx->walk_control_lock); + ctx->walk_control =3D NULL; + mutex_unlock(&ctx->walk_control_lock); +} + static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t, struct damon_region *r, struct damos *s) { @@ -1444,6 +1570,7 @@ static void damos_apply_scheme(struct damon_ctx *c, s= truct damon_target *t, damon_nr_regions(t), do_trace); sz_applied =3D c->ops.apply_scheme(c, t, r, s); } + damos_walk_call_walk(c, t, r, s); ktime_get_coarse_ts64(&end); quota->total_charged_ns +=3D timespec64_to_ns(&end) - timespec64_to_ns(&begin); @@ -1712,6 +1839,7 @@ static void kdamond_apply_schemes(struct damon_ctx *c) damon_for_each_scheme(s, c) { if (c->passed_sample_intervals < s->next_apply_sis) continue; + damos_walk_complete(c, s); s->next_apply_sis =3D c->passed_sample_intervals + (s->apply_interval_us ? s->apply_interval_us : c->attrs.aggr_interval) / sample_interval; @@ -2024,6 +2152,7 @@ static int kdamond_wait_activation(struct damon_ctx *= ctx) ctx->callback.after_wmarks_check(ctx)) break; kdamond_call(ctx, true); + damos_walk_cancel(ctx); } return -EBUSY; } @@ -2117,6 +2246,8 @@ static int kdamond_fn(void *data) */ if (!list_empty(&ctx->schemes)) kdamond_apply_schemes(ctx); + else + damos_walk_cancel(ctx); =20 sample_interval =3D ctx->attrs.sample_interval ? ctx->attrs.sample_interval : 1; @@ -2157,6 +2288,7 @@ static int kdamond_fn(void *data) mutex_unlock(&ctx->kdamond_lock); =20 kdamond_call(ctx, true); + damos_walk_cancel(ctx); =20 mutex_lock(&damon_lock); nr_running_ctxs--; --=20 2.39.5 From nobody Wed Dec 17 16:09:41 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 623641FDE1A; Fri, 3 Jan 2025 17:44:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735926260; cv=none; b=RpkJ3KO1yVgivjiKmpmw55wPO89iX+l+PC0JgVKjjCEuBBuDjD9H4M8wxG0+pWwRqwvTtExxlVuTRgs6ihLTeSzynzJTg0q0NahEA0bjowM4IIHFKsXR/Hb2dpQrq9e2fDube/p8qu6HAmkNipGrUJ+eMsZZzxwQlSyVtkzZMHw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735926260; c=relaxed/simple; bh=ex2cW5mU/E6fAA+W/k+OvrLTIak6tQKdwMDzL9/VmTI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=RGLCjKCTsf7rf/0cEw5Ymc0ry36kwMinVBHMImfTrm4FNNBJRsdY5ZkSmBKTVdEAegFxPmRbowESigi4JlJ2pU9jt3gKLXJjBXyvTy2beNrY86WKhvy11PSxHoOCXWWep6VhRJ+/8hPy34/FKNUl47BUxL4+ukChY1eDu1FzE64= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=e7dfKc9L; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="e7dfKc9L" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9C88BC4CED6; Fri, 3 Jan 2025 17:44:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735926259; bh=ex2cW5mU/E6fAA+W/k+OvrLTIak6tQKdwMDzL9/VmTI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e7dfKc9LBbs8Wmv5ZSOAcOMAI9VAqDjbrtYkn5A85z4azDq2JNjiVPD//CxORn3ta 6Uop6Gjhi0KTg5+K1kU7cYPVCLaXdZdrbhJ2eKeu1VlcrGYq4LNDYbb4hDy6Fyqe37 kjIgj5NXNwzh0TcMweafCE3/jKAghPfv6woal8w7hiCLf/Dw6tCFB6SvWBib5Z8CwX eS1/mmfeJmf70lJ0mre8qE1gmOjkmbXyB3JKwgAc6O6CrJ0q56KFDGKLDYB8wVU//e LMac1HM3Ib+1+pVXBW8wkokXKU9UxUYkVoIr1+GTHGjt/Sz12bGhaw9k2MRimS1H2Q DIbdDtIJYiCfw== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , Jonathan Corbet , damon@lists.linux.dev, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 08/10] Docs/mm/damon/design: document DAMOS regions walking Date: Fri, 3 Jan 2025 09:43:58 -0800 Message-Id: <20250103174400.54890-9-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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" DAMOS' regions walking is a feature for efficiently retrieving monitoring results or DAMOS-internal behavior. It can be useful for multiple purposes including investigations and tuning. Add a section for it on the design document. Signed-off-by: SeongJae Park --- Documentation/mm/damon/design.rst | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Documentation/mm/damon/design.rst b/Documentation/mm/damon/des= ign.rst index 1c8a43b07b00..5385ea04c2fd 100644 --- a/Documentation/mm/damon/design.rst +++ b/Documentation/mm/damon/design.rst @@ -540,6 +540,17 @@ To know how user-space can set the watermarks via :ref= :`DAMON sysfs interface documentation. =20 =20 +Regions Walking +~~~~~~~~~~~~~~~ + +DAMOS feature allowing users access each region that a DAMOS action has ju= st +applied. Using this feature, DAMON :ref:`API ` allows u= sers +access full properties of the regions including the access monitoring resu= lts. +:ref:`DAMON sysfs interface ` also allows users read the = data +via special :ref:`files `. + +.. _damon_design_api: + Application Programming Interface --------------------------------- =20 --=20 2.39.5 From nobody Wed Dec 17 16:09:41 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 060971FDE33; Fri, 3 Jan 2025 17:44:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735926261; cv=none; b=gpr7188JPWfWrHY3IQMQ5AaUYJ9y+DtuS0CjrOZCGonBE7aO3KEXS9TuFc7kR+kt5lJq70kPzbxkBdzPYCYM9lM6HjnWyKACGElP5lqQ2wU0DsLspYt5nd/7Sy3vdQXk1wI/SlFXCtg/Lf6cKnKJCHUi4CZ2T3nkUfuG66HsrS8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735926261; c=relaxed/simple; bh=0AG/RC/M0bhm6WeM0GMTuPdy7IYbXvGsIfaoLaPfpCY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rQJ4letZXXc8oU5KuXqTvKjj+XcJ0N+zjCN/ZOzeswPVesOnq97AqLFGGlDZNgm3V60c7Dde/By3mmFov7ekUxL6elrivmqLsexEs/l6ruxxvM8+kSuD3KqM1HOQ9cmvXjVu48KVpAsGQkUSLjxu5LCcGHM2KsI5a+xHi36wX7Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hJjyRE9+; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hJjyRE9+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AF26CC4CECE; Fri, 3 Jan 2025 17:44:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735926260; bh=0AG/RC/M0bhm6WeM0GMTuPdy7IYbXvGsIfaoLaPfpCY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hJjyRE9+8H54mkpZ6BRFxdU14eB4Phkr6Ho40LTYktzdahdxWg1oftRRevZOtCu3f Qautu2v6d+NS6ozj/xOddO7xD9bEMTrAt8NOqv708mPGoOac9PiK/Ea/y65nPfx3N8 pfeeQwuJ2H1hcdhXBTwc9Gk5Y9WhPnJG3kD6gWIS4at0P4vocjSA+cxHXSjux2L7QD GTueVv+Wtt+5A93Q9NV099U3xDMSsEjSG3AhE6u7Ls8T/ZfYClEjqRZwdQ+oxFjYFf 1Hzu2poCoxe5n0guUXVGrEDKeZ2+Jf1BgsCFNb0hmRi3E43/QubKc5Fa6M9OgWrVd8 mNQPMKt0hD9tw== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 09/10] mm/damon/sysfs: use damos_walk() for update_schemes_tried_{bytes,regions} Date: Fri, 3 Jan 2025 09:43:59 -0800 Message-Id: <20250103174400.54890-10-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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" DAMON sysfs interface uses damon_callback with its own complicated synchronization facility to handle update_schemes_tried_bytes and update_schemes_tried_regions commands. But damos_walk() can support the use case without the additional synchronizations. Convert the code to use damos_walk() instead. Signed-off-by: SeongJae Park --- mm/damon/sysfs-common.h | 5 +++++ mm/damon/sysfs-schemes.c | 48 ++++++++++++++++++++++++++++++++++++++++ mm/damon/sysfs.c | 43 +++++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+) diff --git a/mm/damon/sysfs-common.h b/mm/damon/sysfs-common.h index e79b4a65ff2d..81f1c845118f 100644 --- a/mm/damon/sysfs-common.h +++ b/mm/damon/sysfs-common.h @@ -55,6 +55,11 @@ bool damos_sysfs_regions_upd_done(void); =20 int damon_sysfs_schemes_update_regions_stop(struct damon_ctx *ctx); =20 +void damos_sysfs_populate_region_dir(struct damon_sysfs_schemes *sysfs_sch= emes, + struct damon_ctx *ctx, struct damon_target *t, + struct damon_region *r, struct damos *s, + bool total_bytes_only); + int damon_sysfs_schemes_clear_regions( struct damon_sysfs_schemes *sysfs_schemes); =20 diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index c57ab47686ff..1d8ad637051a 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -2183,6 +2183,54 @@ static int damon_sysfs_before_damos_apply(struct dam= on_ctx *ctx, return 0; } =20 +/** + * damos_sysfs_populate_region_dir() - Populate a schemes tried region dir. + * @sysfs_schemes: Schemes directory to populate regions directory. + * @ctx: Corresponding DAMON context. + * @t: DAMON target of @r. + * @r: DAMON region to populate the directory for. + * @s: Corresponding scheme. + * @total_bytes_only: Whether the request is for bytes update only. + * + * Called from DAMOS walk callback while holding damon_sysfs_lock. + */ +void damos_sysfs_populate_region_dir(struct damon_sysfs_schemes *sysfs_sch= emes, + struct damon_ctx *ctx, struct damon_target *t, + struct damon_region *r, struct damos *s, bool total_bytes_only) +{ + struct damos *scheme; + struct damon_sysfs_scheme_regions *sysfs_regions; + struct damon_sysfs_scheme_region *region; + int schemes_idx =3D 0; + + damon_for_each_scheme(scheme, ctx) { + if (scheme =3D=3D s) + break; + schemes_idx++; + } + + /* user could have removed the scheme sysfs dir */ + if (schemes_idx >=3D sysfs_schemes->nr) + return; + + sysfs_regions =3D sysfs_schemes->schemes_arr[schemes_idx]->tried_regions; + sysfs_regions->total_bytes +=3D r->ar.end - r->ar.start; + if (total_bytes_only) + return; + + region =3D damon_sysfs_scheme_region_alloc(r); + if (!region) + return; + 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", + sysfs_regions->nr_regions++)) { + kobject_put(®ion->kobj); + } +} + /* * DAMON callback that called after each accesses sampling. While this * callback is registered, damon_sysfs_lock should be held to ensure the diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 917e6aca3f58..4ba44a314f2e 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1512,6 +1512,45 @@ static int damon_sysfs_damon_call(int (*fn)(void *da= ta), return damon_call(kdamond->damon_ctx, &call_control); } =20 +struct damon_sysfs_schemes_walk_data { + struct damon_sysfs_kdamond *sysfs_kdamond; + bool total_bytes_only; +}; + +/* populate the region directory */ +static void damon_sysfs_schemes_tried_regions_upd_one(void *data, struct d= amon_ctx *ctx, + struct damon_target *t, struct damon_region *r, + struct damos *s) +{ + struct damon_sysfs_schemes_walk_data *walk_data =3D data; + struct damon_sysfs_kdamond *sysfs_kdamond =3D walk_data->sysfs_kdamond; + + damos_sysfs_populate_region_dir( + sysfs_kdamond->contexts->contexts_arr[0]->schemes, + ctx, t, r, s, walk_data->total_bytes_only); +} + +static int damon_sysfs_update_schemes_tried_regions( + struct damon_sysfs_kdamond *sysfs_kdamond, bool total_bytes_only) +{ + struct damon_sysfs_schemes_walk_data walk_data =3D { + .sysfs_kdamond =3D sysfs_kdamond, + .total_bytes_only =3D total_bytes_only, + }; + struct damos_walk_control control =3D { + .walk_fn =3D damon_sysfs_schemes_tried_regions_upd_one, + .data =3D &walk_data, + }; + struct damon_ctx *ctx =3D sysfs_kdamond->damon_ctx; + + if (!ctx) + return -EINVAL; + + damon_sysfs_schemes_clear_regions( + sysfs_kdamond->contexts->contexts_arr[0]->schemes); + return damos_walk(ctx, &control); +} + /* * damon_sysfs_handle_cmd() - Handle a command for a specific kdamond. * @cmd: The command to handle. @@ -1542,6 +1581,10 @@ static int damon_sysfs_handle_cmd(enum damon_sysfs_c= md cmd, case DAMON_SYSFS_CMD_UPDATE_SCHEMES_STATS: return damon_sysfs_damon_call( damon_sysfs_upd_schemes_stats, kdamond); + case DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_BYTES: + return damon_sysfs_update_schemes_tried_regions(kdamond, true); + case DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_REGIONS: + return damon_sysfs_update_schemes_tried_regions(kdamond, false); case DAMON_SYSFS_CMD_CLEAR_SCHEMES_TRIED_REGIONS: return damon_sysfs_schemes_clear_regions( kdamond->contexts->contexts_arr[0]->schemes); --=20 2.39.5 From nobody Wed Dec 17 16:09:41 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 58FDB1FE45D; Fri, 3 Jan 2025 17:44:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735926262; cv=none; b=aD/eFUTbHbZVZPnETJ6JgScZFnZ6BUsk5zIJ+ojoXrNySIhILc4cgWYpdtg2HcFRz5/fVJppzu1EpFzSDMZZT9dckyeqrDprdUPiDGTsBOu2Uxb78z3eABfDOswwkHhoHmkn5F1mY1jZs0Tb8tbja0uCQ8HTjcGOBYUSrEhaFeM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735926262; c=relaxed/simple; bh=OfM4+ASQzquOI9PQ720oHjnGo91lYu+MMlnD/0TFf7o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tA5XonJqJI6EqrXxbIZFXezr9N7h15sZHV3Tqz52pe4mTF5s4bvmrzixM5a9SoA4mfwAbFjzx9pOGjmWXaY3ff3QUuGypKCa0TCndD1KY3Vs+fZSJyT6Gd5JVsflri7wa/sks/uuWKNL2kg3/3BKWSuXK4fzFxUfXX2HL0ZeJNo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gHVNUPVz; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="gHVNUPVz" 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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); =20 -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_sch= emes, 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_regi= on_ktype =3D { * scheme regions directory */ =20 -/* - * enum damos_sysfs_regions_upd_status - Represent DAMOS tried regions upd= ate - * 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 sta= tus - * 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 aft= er - * the scheme is completely applied to the given snapshot. Hence the cal= lback - * 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; }; =20 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 =3D 0; regions->total_bytes =3D 0; - regions->upd_status =3D DAMOS_TRIED_REGIONS_UPD_IDLE; return regions; } =20 @@ -2126,63 +2081,6 @@ void damon_sysfs_schemes_update_stats( } } =20 -/* - * damon_sysfs_schemes that need to update its schemes regions dir. Prote= cted - * 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 =3D - damon_sysfs_schemes_for_damos_callback; - int schemes_idx =3D 0; - - damon_for_each_scheme(scheme, ctx) { - if (scheme =3D=3D s) - break; - schemes_idx++; - } - - /* user could have removed the scheme sysfs dir */ - if (schemes_idx >=3D sysfs_schemes->nr) - return 0; - - sysfs_regions =3D sysfs_schemes->schemes_arr[schemes_idx]->tried_regions; - if (sysfs_regions->upd_status =3D=3D DAMOS_TRIED_REGIONS_UPD_FINISHED) - return 0; - if (sysfs_regions->upd_status =3D=3D DAMOS_TRIED_REGIONS_UPD_IDLE) - sysfs_regions->upd_status =3D DAMOS_TRIED_REGIONS_UPD_STARTED; - sysfs_regions->total_bytes +=3D r->ar.end - r->ar.start; - if (damos_regions_upd_total_bytes_only) - return 0; - - region =3D 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_sy= sfs_schemes *sysfs_schemes, } } =20 -/* - * 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 =3D - damon_sysfs_schemes_for_damos_callback; - struct damon_sysfs_scheme_regions *sysfs_regions; - int i; - - for (i =3D 0; i < sysfs_schemes->nr; i++) { - sysfs_regions =3D sysfs_schemes->schemes_arr[i]->tried_regions; - if (sysfs_regions->upd_status =3D=3D - DAMOS_TRIED_REGIONS_UPD_STARTED || - time_after(jiffies, - sysfs_regions->upd_timeout_jiffies)) - sysfs_regions->upd_status =3D - 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 =3D 0; - - damon_for_each_scheme(scheme, ctx) { - if (i =3D=3D 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 =3D 0; i < sysfs_schemes->nr; i++) { - sysfs_regions =3D sysfs_schemes->schemes_arr[i]->tried_regions; - scheme =3D damos_sysfs_nth_scheme(i, ctx); - if (!scheme) { - sysfs_regions->upd_status =3D - DAMOS_TRIED_REGIONS_UPD_FINISHED; - continue; - } - sysfs_regions->upd_status =3D DAMOS_TRIED_REGIONS_UPD_IDLE; - sysfs_regions->upd_timeout_jiffies =3D 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 =3D sysfs_schemes; - damos_tried_regions_init_upd_status(sysfs_schemes, ctx); - damos_regions_upd_total_bytes_only =3D total_bytes_only; - ctx->callback.before_damos_apply =3D damon_sysfs_before_damos_apply; - return 0; -} - -bool damos_sysfs_regions_upd_done(void) -{ - struct damon_sysfs_schemes *sysfs_schemes =3D - damon_sysfs_schemes_for_damos_callback; - struct damon_sysfs_scheme_regions *sysfs_regions; - int i; - - for (i =3D 0; i < sysfs_schemes->nr; i++) { - sysfs_regions =3D sysfs_schemes->schemes_arr[i]->tried_regions; - if (sysfs_regions->upd_status !=3D - DAMOS_TRIED_REGIONS_UPD_FINISHED) - return false; - } - return true; -} - -/* - * Called from damon_sysfs_cmd_request_callback under damon_sysfs_lock. C= aller - * 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 =3D NULL; - ctx->callback.before_damos_apply =3D NULL; - damon_sysfs_schemes_region_idx =3D 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; } =20 -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 =3D damon_sysfs_cmd_request.kdamond; - cmd =3D damon_sysfs_cmd_request.cmd; - if (kdamond && ctx =3D=3D kdamond->damon_ctx && - (cmd =3D=3D DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_REGIONS || - cmd =3D=3D DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_BYTES) && - damon_sysfs_schemes_regions_updating) { - damon_sysfs_schemes_update_regions_stop(ctx); - damon_sysfs_schemes_regions_updating =3D false; - mutex_unlock(&damon_sysfs_lock); - } =20 if (!damon_target_has_pid(ctx)) return; @@ -1232,28 +1216,6 @@ static int damon_sysfs_upd_schemes_stats(void *data) return 0; } =20 -static int damon_sysfs_upd_schemes_regions_start( - struct damon_sysfs_kdamond *kdamond, bool total_bytes_only) -{ - struct damon_ctx *ctx =3D 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 =3D 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 =3D false; int err =3D 0; =20 /* 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 =3D damon_sysfs_cmd_request.kdamond; if (!kdamond || kdamond->damon_ctx !=3D c) @@ -1374,39 +1334,13 @@ static int damon_sysfs_cmd_request_callback(struct = damon_ctx *c, bool active, goto out; err =3D damon_sysfs_commit_input(kdamond); break; - case DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_BYTES: - total_bytes_only =3D true; - fallthrough; - case DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_REGIONS: - if (!damon_sysfs_schemes_regions_updating) { - err =3D damon_sysfs_upd_schemes_regions_start(kdamond, - total_bytes_only); - if (!err) { - damon_sysfs_schemes_regions_updating =3D 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 =3D damon_sysfs_upd_schemes_regions_stop(kdamond); - damon_sysfs_schemes_regions_updating =3D false; - } - break; default: break; } /* Mark the request as invalid now. */ damon_sysfs_cmd_request.kdamond =3D NULL; out: - if (!damon_sysfs_schemes_regions_updating) - mutex_unlock(&damon_sysfs_lock); -keep_lock_out: + mutex_unlock(&damon_sysfs_lock); return err; } =20 --=20 2.39.5