[PATCH] mm/damon/core: reinitialize when passed_sample_intervals occurred overflow

JaeJoon Jung posted 1 patch 3 weeks, 1 day ago
mm/damon/core.c | 5 +++++
1 file changed, 5 insertions(+)
[PATCH] mm/damon/core: reinitialize when passed_sample_intervals occurred overflow
Posted by JaeJoon Jung 3 weeks, 1 day ago
To concisely explain the variables that calculate the time flow in
kdamond_fn(), we write them as follows:

unsigned long ctx->passed_sample_intervals: c.psi
unsigned long ctx->next_ops_update_sis: c.nui

Normal:
[-----------------+---------------+-------------------+----------]
                c.psi           c.nui
                  --------------->              next c.nui
                        if (c.psi >= c.nui) ---------->

Overflow(OF):
[-----------------+---------------+-------------------+----------]
                                c.psi               c.nui
                                  -------------------->
                                            if (c.psi >= c.nui) ---> OF
[-----+-----------
    next c.nui

Overflow(OF) occurred if (c.psi >= next c.nui):
Overflow may occur as shown above. In this case, re-run kdamond_init_ctx()
to reinitialize the relevant variables.

Signed-off-by: JaeJoon Jung <rgbi3307@gmail.com>
---
 mm/damon/core.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/mm/damon/core.c b/mm/damon/core.c
index f9fc0375890a..c4b2831cff89 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -2740,6 +2740,11 @@ static int kdamond_fn(void *data)
 			if (ctx->ops.update)
 				ctx->ops.update(ctx);
 			sz_limit = damon_region_sz_limit(ctx);
+
+			/* reinitialize when overflow occurs */
+			if (ctx->passed_sample_intervals >=
+					ctx->next_ops_update_sis)
+				kdamond_init_ctx(ctx);
 		}
 	}
 done:
--
2.43.0