linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/damon/core: Optimize kdamod.%d thread creation code
@ 2021-10-16 16:56 Xin Hao
  2021-10-16 16:58 ` xhao
  0 siblings, 1 reply; 2+ messages in thread
From: Xin Hao @ 2021-10-16 16:56 UTC (permalink / raw)
  To: sjpark; +Cc: xhao, akpm, linux-mm, linux-kernel

When the ctx->adaptive_targets list is empty,
i did some test on monitor_on interface like this.

echo on > /sys/kernel/debug/damon/monitor_on
[  851.988307] damon: kdamond (5390) starts

Though the ctx->adaptive_targets list is empty, but the
kthread_run still be called, and the kdamond.x thread still
be created, this is meaningless, so t

So there adds a judgment. only if the ctx->adaptive_targets
list is not empty, and ctx->kdamond pointer is NULL, then call
the __damon_start function.

Signed-off-by: Xin Hao <xhao@linux.alibaba.com>
---
 mm/damon/core.c | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/mm/damon/core.c b/mm/damon/core.c
index 30e9211f494a..998c707fdca2 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -107,6 +107,11 @@ void damon_add_target(struct damon_ctx *ctx, struct damon_target *t)
 	list_add_tail(&t->list, &ctx->adaptive_targets);
 }
 
+static int damon_target_empty(struct damon_ctx *ctx)
+{
+	return list_empty(&ctx->adaptive_targets);
+}
+
 static void damon_del_target(struct damon_target *t)
 {
 	list_del(&t->list);
@@ -307,15 +312,14 @@ static int __damon_start(struct damon_ctx *ctx)
 	int err = -EBUSY;
 
 	mutex_lock(&ctx->kdamond_lock);
-	if (!ctx->kdamond) {
+	ctx->kdamond_stop = false;
+	ctx->kdamond = kthread_run(kdamond_fn, ctx, "kdamond.%d",
+				   nr_running_ctxs);
+	if (IS_ERR(ctx->kdamond)) {
+		err = PTR_ERR(ctx->kdamond);
+		ctx->kdamond = 0;
+	} else {
 		err = 0;
-		ctx->kdamond_stop = false;
-		ctx->kdamond = kthread_run(kdamond_fn, ctx, "kdamond.%d",
-				nr_running_ctxs);
-		if (IS_ERR(ctx->kdamond)) {
-			err = PTR_ERR(ctx->kdamond);
-			ctx->kdamond = 0;
-		}
 	}
 	mutex_unlock(&ctx->kdamond_lock);
 
@@ -347,10 +351,12 @@ int damon_start(struct damon_ctx **ctxs, int nr_ctxs)
 	}
 
 	for (i = 0; i < nr_ctxs; i++) {
-		err = __damon_start(ctxs[i]);
-		if (err)
-			break;
-		nr_running_ctxs++;
+		if (!damon_target_empty(ctxs[i]) && !ctxs[i]->kdamond) {
+			err = __damon_start(ctxs[i]);
+			if (err)
+				break;
+			nr_running_ctxs++;
+		}
 	}
 	mutex_unlock(&damon_lock);
 
-- 
2.31.0



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] mm/damon/core: Optimize kdamod.%d thread creation code
  2021-10-16 16:56 [PATCH] mm/damon/core: Optimize kdamod.%d thread creation code Xin Hao
@ 2021-10-16 16:58 ` xhao
  0 siblings, 0 replies; 2+ messages in thread
From: xhao @ 2021-10-16 16:58 UTC (permalink / raw)
  To: sjpark; +Cc: akpm, linux-mm, linux-kernel


On 2021/10/17 上午12:56, Xin Hao wrote:
> When the ctx->adaptive_targets list is empty,
> i did some test on monitor_on interface like this.
>
> echo on > /sys/kernel/debug/damon/monitor_on
> [  851.988307] damon: kdamond (5390) starts
>
> Though the ctx->adaptive_targets list is empty, but the
> kthread_run still be called, and the kdamond.x thread still
> be created, this is meaningless, so t

Sorry there made a mistake, i will send a new one.

>
> So there adds a judgment. only if the ctx->adaptive_targets
> list is not empty, and ctx->kdamond pointer is NULL, then call
> the __damon_start function.
>
> Signed-off-by: Xin Hao <xhao@linux.alibaba.com>
> ---
>   mm/damon/core.c | 30 ++++++++++++++++++------------
>   1 file changed, 18 insertions(+), 12 deletions(-)
>
> diff --git a/mm/damon/core.c b/mm/damon/core.c
> index 30e9211f494a..998c707fdca2 100644
> --- a/mm/damon/core.c
> +++ b/mm/damon/core.c
> @@ -107,6 +107,11 @@ void damon_add_target(struct damon_ctx *ctx, struct damon_target *t)
>   	list_add_tail(&t->list, &ctx->adaptive_targets);
>   }
>   
> +static int damon_target_empty(struct damon_ctx *ctx)
> +{
> +	return list_empty(&ctx->adaptive_targets);
> +}
> +
>   static void damon_del_target(struct damon_target *t)
>   {
>   	list_del(&t->list);
> @@ -307,15 +312,14 @@ static int __damon_start(struct damon_ctx *ctx)
>   	int err = -EBUSY;
>   
>   	mutex_lock(&ctx->kdamond_lock);
> -	if (!ctx->kdamond) {
> +	ctx->kdamond_stop = false;
> +	ctx->kdamond = kthread_run(kdamond_fn, ctx, "kdamond.%d",
> +				   nr_running_ctxs);
> +	if (IS_ERR(ctx->kdamond)) {
> +		err = PTR_ERR(ctx->kdamond);
> +		ctx->kdamond = 0;
> +	} else {
>   		err = 0;
> -		ctx->kdamond_stop = false;
> -		ctx->kdamond = kthread_run(kdamond_fn, ctx, "kdamond.%d",
> -				nr_running_ctxs);
> -		if (IS_ERR(ctx->kdamond)) {
> -			err = PTR_ERR(ctx->kdamond);
> -			ctx->kdamond = 0;
> -		}
>   	}
>   	mutex_unlock(&ctx->kdamond_lock);
>   
> @@ -347,10 +351,12 @@ int damon_start(struct damon_ctx **ctxs, int nr_ctxs)
>   	}
>   
>   	for (i = 0; i < nr_ctxs; i++) {
> -		err = __damon_start(ctxs[i]);
> -		if (err)
> -			break;
> -		nr_running_ctxs++;
> +		if (!damon_target_empty(ctxs[i]) && !ctxs[i]->kdamond) {
> +			err = __damon_start(ctxs[i]);
> +			if (err)
> +				break;
> +			nr_running_ctxs++;
> +		}
>   	}
>   	mutex_unlock(&damon_lock);
>   

-- 
Best Regards!
Xin Hao



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-10-16 16:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-16 16:56 [PATCH] mm/damon/core: Optimize kdamod.%d thread creation code Xin Hao
2021-10-16 16:58 ` xhao

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).