* [PATCH] mm/damon/sysfs: simplify the judgement whether kdamonds are busy
@ 2022-09-04 14:36 xiakaixu1987
2022-09-05 18:20 ` SeongJae Park
0 siblings, 1 reply; 2+ messages in thread
From: xiakaixu1987 @ 2022-09-04 14:36 UTC (permalink / raw)
To: sj, akpm; +Cc: damon, linux-mm, linux-kernel, Kaixu Xia
From: Kaixu Xia <kaixuxia@tencent.com>
It is unnecessary to get the number of the running kdamond to judge
whether kdamonds are busy. Here we can use the
damon_sysfs_kdamond_running() helper and return -EBUSY directly
when finding a running kdamond. Meanwhile, merging with the judgement
that a kdamond has current sysfs command callback request to make
the code more clear.
Signed-off-by: Kaixu Xia <kaixuxia@tencent.com>
---
mm/damon/sysfs.c | 25 +++++++------------------
1 file changed, 7 insertions(+), 18 deletions(-)
diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c
index 7488e27c87c3..fe6c6870cf86 100644
--- a/mm/damon/sysfs.c
+++ b/mm/damon/sysfs.c
@@ -2657,23 +2657,18 @@ static void damon_sysfs_kdamonds_rm_dirs(struct damon_sysfs_kdamonds *kdamonds)
kdamonds->kdamonds_arr = NULL;
}
-static int damon_sysfs_nr_running_ctxs(struct damon_sysfs_kdamond **kdamonds,
+static bool damon_sysfs_kdamonds_busy(struct damon_sysfs_kdamond **kdamonds,
int nr_kdamonds)
{
- int nr_running_ctxs = 0;
int i;
for (i = 0; i < nr_kdamonds; i++) {
- struct damon_ctx *ctx = kdamonds[i]->damon_ctx;
-
- if (!ctx)
- continue;
- mutex_lock(&ctx->kdamond_lock);
- if (ctx->kdamond)
- nr_running_ctxs++;
- mutex_unlock(&ctx->kdamond_lock);
+ if (damon_sysfs_kdamond_running(kdamonds[i]) ||
+ damon_sysfs_cmd_request.kdamond == kdamonds[i])
+ return true;
}
- return nr_running_ctxs;
+
+ return false;
}
static int damon_sysfs_kdamonds_add_dirs(struct damon_sysfs_kdamonds *kdamonds,
@@ -2682,15 +2677,9 @@ static int damon_sysfs_kdamonds_add_dirs(struct damon_sysfs_kdamonds *kdamonds,
struct damon_sysfs_kdamond **kdamonds_arr, *kdamond;
int err, i;
- if (damon_sysfs_nr_running_ctxs(kdamonds->kdamonds_arr, kdamonds->nr))
+ if (damon_sysfs_kdamonds_busy(kdamonds->kdamonds_arr, kdamonds->nr))
return -EBUSY;
- for (i = 0; i < kdamonds->nr; i++) {
- if (damon_sysfs_cmd_request.kdamond ==
- kdamonds->kdamonds_arr[i])
- return -EBUSY;
- }
-
damon_sysfs_kdamonds_rm_dirs(kdamonds);
if (!nr_kdamonds)
return 0;
--
2.27.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] mm/damon/sysfs: simplify the judgement whether kdamonds are busy
2022-09-04 14:36 [PATCH] mm/damon/sysfs: simplify the judgement whether kdamonds are busy xiakaixu1987
@ 2022-09-05 18:20 ` SeongJae Park
0 siblings, 0 replies; 2+ messages in thread
From: SeongJae Park @ 2022-09-05 18:20 UTC (permalink / raw)
To: xiakaixu1987; +Cc: sj, akpm, damon, linux-mm, linux-kernel, Kaixu Xia
Hi Kaixu,
On Sun, 4 Sep 2022 22:36:06 +0800 xiakaixu1987@gmail.com wrote:
> From: Kaixu Xia <kaixuxia@tencent.com>
>
> It is unnecessary to get the number of the running kdamond to judge
> whether kdamonds are busy. Here we can use the
> damon_sysfs_kdamond_running() helper and return -EBUSY directly
> when finding a running kdamond. Meanwhile, merging with the judgement
> that a kdamond has current sysfs command callback request to make
> the code more clear.
>
> Signed-off-by: Kaixu Xia <kaixuxia@tencent.com>
Reviewed-by: SeongJae Park <sj@kernel.org>
Thanks,
SJ
> ---
> mm/damon/sysfs.c | 25 +++++++------------------
> 1 file changed, 7 insertions(+), 18 deletions(-)
>
> diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c
> index 7488e27c87c3..fe6c6870cf86 100644
> --- a/mm/damon/sysfs.c
> +++ b/mm/damon/sysfs.c
> @@ -2657,23 +2657,18 @@ static void damon_sysfs_kdamonds_rm_dirs(struct damon_sysfs_kdamonds *kdamonds)
> kdamonds->kdamonds_arr = NULL;
> }
>
> -static int damon_sysfs_nr_running_ctxs(struct damon_sysfs_kdamond **kdamonds,
> +static bool damon_sysfs_kdamonds_busy(struct damon_sysfs_kdamond **kdamonds,
> int nr_kdamonds)
> {
> - int nr_running_ctxs = 0;
> int i;
>
> for (i = 0; i < nr_kdamonds; i++) {
> - struct damon_ctx *ctx = kdamonds[i]->damon_ctx;
> -
> - if (!ctx)
> - continue;
> - mutex_lock(&ctx->kdamond_lock);
> - if (ctx->kdamond)
> - nr_running_ctxs++;
> - mutex_unlock(&ctx->kdamond_lock);
> + if (damon_sysfs_kdamond_running(kdamonds[i]) ||
> + damon_sysfs_cmd_request.kdamond == kdamonds[i])
> + return true;
> }
> - return nr_running_ctxs;
> +
> + return false;
> }
>
> static int damon_sysfs_kdamonds_add_dirs(struct damon_sysfs_kdamonds *kdamonds,
> @@ -2682,15 +2677,9 @@ static int damon_sysfs_kdamonds_add_dirs(struct damon_sysfs_kdamonds *kdamonds,
> struct damon_sysfs_kdamond **kdamonds_arr, *kdamond;
> int err, i;
>
> - if (damon_sysfs_nr_running_ctxs(kdamonds->kdamonds_arr, kdamonds->nr))
> + if (damon_sysfs_kdamonds_busy(kdamonds->kdamonds_arr, kdamonds->nr))
> return -EBUSY;
>
> - for (i = 0; i < kdamonds->nr; i++) {
> - if (damon_sysfs_cmd_request.kdamond ==
> - kdamonds->kdamonds_arr[i])
> - return -EBUSY;
> - }
> -
> damon_sysfs_kdamonds_rm_dirs(kdamonds);
> if (!nr_kdamonds)
> return 0;
> --
> 2.27.0
>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-09-05 18:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-04 14:36 [PATCH] mm/damon/sysfs: simplify the judgement whether kdamonds are busy xiakaixu1987
2022-09-05 18:20 ` SeongJae Park
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).