Skip to content

Commit 2f6ce7e

Browse files
Quanmin Yanakpm00
authored andcommitted
mm/damon/stat: change last_refresh_jiffies to a global variable
Patch series "mm/damon: fixes for the jiffies-related issues", v2. On 32-bit systems, the kernel initializes jiffies to "-5 minutes" to make jiffies wrap bugs appear earlier. However, this may cause the time_before() series of functions to return unexpected values, resulting in DAMON not functioning as intended. Meanwhile, similar issues exist in some specific user operation scenarios. This patchset addresses these issues. The first patch is about the DAMON_STAT module, and the second patch is about the core layer's sysfs. This patch (of 2): In DAMON_STAT's damon_stat_damon_call_fn(), time_before_eq() is used to avoid unnecessarily frequent stat update. On 32-bit systems, the kernel initializes jiffies to "-5 minutes" to make jiffies wrap bugs appear earlier. However, this causes time_before_eq() in DAMON_STAT to unexpectedly return true during the first 5 minutes after boot on 32-bit systems (see [1] for more explanation, which fixes another jiffies-related issue before). As a result, DAMON_STAT does not update any monitoring results during that period, which becomes more confusing when DAMON_STAT_ENABLED_DEFAULT is enabled. There is also an issue unrelated to the system's word size[2]: if the user stops DAMON_STAT just after last_refresh_jiffies is updated and restarts it after 5 seconds or a longer delay, last_refresh_jiffies will retain an older value, causing time_before_eq() to return false and the update to happen earlier than expected. Fix these issues by making last_refresh_jiffies a global variable and initializing it each time DAMON_STAT is started. Link: https://lkml.kernel.org/r/20251030020746.967174-2-yanquanmin1@huawei.com Link: https://lkml.kernel.org/r/20250822025057.1740854-1-ekffu200098@gmail.com [1] Link: https://lore.kernel.org/all/20251028143250.50144-1-sj@kernel.org/ [2] Fixes: fabdd1e ("mm/damon/stat: calculate and expose estimated memory bandwidth") Signed-off-by: Quanmin Yan <yanquanmin1@huawei.com> Suggested-by: SeongJae Park <sj@kernel.org> Reviewed-by: SeongJae Park <sj@kernel.org> Cc: Kefeng Wang <wangkefeng.wang@huawei.com> Cc: ze zuo <zuoze1@huawei.com> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 91a5409 commit 2f6ce7e

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

mm/damon/stat.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ MODULE_PARM_DESC(aggr_interval_us,
4646

4747
static struct damon_ctx *damon_stat_context;
4848

49+
static unsigned long damon_stat_last_refresh_jiffies;
50+
4951
static void damon_stat_set_estimated_memory_bandwidth(struct damon_ctx *c)
5052
{
5153
struct damon_target *t;
@@ -130,13 +132,12 @@ static void damon_stat_set_idletime_percentiles(struct damon_ctx *c)
130132
static int damon_stat_damon_call_fn(void *data)
131133
{
132134
struct damon_ctx *c = data;
133-
static unsigned long last_refresh_jiffies;
134135

135136
/* avoid unnecessarily frequent stat update */
136-
if (time_before_eq(jiffies, last_refresh_jiffies +
137+
if (time_before_eq(jiffies, damon_stat_last_refresh_jiffies +
137138
msecs_to_jiffies(5 * MSEC_PER_SEC)))
138139
return 0;
139-
last_refresh_jiffies = jiffies;
140+
damon_stat_last_refresh_jiffies = jiffies;
140141

141142
aggr_interval_us = c->attrs.aggr_interval;
142143
damon_stat_set_estimated_memory_bandwidth(c);
@@ -210,6 +211,8 @@ static int damon_stat_start(void)
210211
err = damon_start(&damon_stat_context, 1, true);
211212
if (err)
212213
return err;
214+
215+
damon_stat_last_refresh_jiffies = jiffies;
213216
call_control.data = damon_stat_context;
214217
return damon_call(damon_stat_context, &call_control);
215218
}

0 commit comments

Comments
 (0)