linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/damon: prevent activated scheme from sleeping by deactivated schemes
@ 2022-03-30 10:53 Jonghyeon Kim
  2022-03-30 11:55 ` sj
  0 siblings, 1 reply; 2+ messages in thread
From: Jonghyeon Kim @ 2022-03-30 10:53 UTC (permalink / raw)
  To: SeongJae Park; +Cc: Andrew Morton, linux-mm, linux-kernel, Jonghyeon Kim

In the DAMON, the minimum wait time of the schemes decides whether the
kernel wakes up 'kdamon_fn()'. But since the minimum wait time is
initialized to zero, there are corner cases against the original objective.

For example, if we have several schemes for one target, and if the wait
time of the first scheme is zero, the minimum wait time will set zero,
which means 'kdamond_fn()' should wake up to apply this scheme. However,
in the following scheme, wait time can be set to non-zero. Thus, the
mininum wait time will be set to non-zero, which can cause sleeping this
interval for 'kdamon_fn()' due to one deactivated last scheme.

This commit prevents making DAMON monitoring inactive state due to other
deactivated schemes.

Signed-off-by: Jonghyeon Kim <tome01@ajou.ac.kr>
---
 mm/damon/core.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/mm/damon/core.c b/mm/damon/core.c
index c1e0fed4e877..5ce8d7c867f0 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -1019,12 +1019,15 @@ static int kdamond_wait_activation(struct damon_ctx *ctx)
 	struct damos *s;
 	unsigned long wait_time;
 	unsigned long min_wait_time = 0;
+	bool init_wait_time = false;
 
 	while (!kdamond_need_stop(ctx)) {
 		damon_for_each_scheme(s, ctx) {
 			wait_time = damos_wmark_wait_us(s);
-			if (!min_wait_time || wait_time < min_wait_time)
+			if (!init_wait_time || wait_time < min_wait_time) {
+				init_wait_time = true;
 				min_wait_time = wait_time;
+			}
 		}
 		if (!min_wait_time)
 			return 0;
-- 
2.17.1


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

* Re: [PATCH] mm/damon: prevent activated scheme from sleeping by deactivated schemes
  2022-03-30 10:53 [PATCH] mm/damon: prevent activated scheme from sleeping by deactivated schemes Jonghyeon Kim
@ 2022-03-30 11:55 ` sj
  0 siblings, 0 replies; 2+ messages in thread
From: sj @ 2022-03-30 11:55 UTC (permalink / raw)
  To: Jonghyeon Kim; +Cc: SeongJae Park, Andrew Morton, linux-mm, linux-kernel

Hi Jonghyeon,

On Wed, 30 Mar 2022 19:53:02 +0900 Jonghyeon Kim <tome01@ajou.ac.kr> wrote:

> In the DAMON, the minimum wait time of the schemes decides whether the
> kernel wakes up 'kdamon_fn()'. But since the minimum wait time is
> initialized to zero, there are corner cases against the original objective.
> 
> For example, if we have several schemes for one target, and if the wait
> time of the first scheme is zero, the minimum wait time will set zero,
> which means 'kdamond_fn()' should wake up to apply this scheme. However,
> in the following scheme, wait time can be set to non-zero. Thus, the
> mininum wait time will be set to non-zero, which can cause sleeping this
> interval for 'kdamon_fn()' due to one deactivated last scheme.

Good catch, thanks!

> 
> This commit prevents making DAMON monitoring inactive state due to other
> deactivated schemes.
> 
> Signed-off-by: Jonghyeon Kim <tome01@ajou.ac.kr>

Reviewed-by: SeongJae Park <sj@kernel.org>


Thanks,
SJ

> ---
>  mm/damon/core.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/damon/core.c b/mm/damon/core.c
> index c1e0fed4e877..5ce8d7c867f0 100644
> --- a/mm/damon/core.c
> +++ b/mm/damon/core.c
> @@ -1019,12 +1019,15 @@ static int kdamond_wait_activation(struct damon_ctx *ctx)
>  	struct damos *s;
>  	unsigned long wait_time;
>  	unsigned long min_wait_time = 0;
> +	bool init_wait_time = false;
>  
>  	while (!kdamond_need_stop(ctx)) {
>  		damon_for_each_scheme(s, ctx) {
>  			wait_time = damos_wmark_wait_us(s);
> -			if (!min_wait_time || wait_time < min_wait_time)
> +			if (!init_wait_time || wait_time < min_wait_time) {
> +				init_wait_time = true;
>  				min_wait_time = wait_time;
> +			}
>  		}
>  		if (!min_wait_time)
>  			return 0;
> -- 
> 2.17.1
> 

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

end of thread, other threads:[~2022-03-30 12:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-30 10:53 [PATCH] mm/damon: prevent activated scheme from sleeping by deactivated schemes Jonghyeon Kim
2022-03-30 11:55 ` sj

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