]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
mm/damon/sysfs: change next_update_jiffies to a global variable
authorQuanmin Yan <yanquanmin1@huawei.com>
Thu, 30 Oct 2025 02:07:46 +0000 (10:07 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 24 Nov 2025 09:37:43 +0000 (10:37 +0100)
commit 9fd7bb5083d1e1027b8ac1e365c29921ab88b177 upstream.

In DAMON's damon_sysfs_repeat_call_fn(), time_before() is used to compare
the current jiffies with next_update_jiffies to determine whether to
update the sysfs files at this moment.

On 32-bit systems, the kernel initializes jiffies to "-5 minutes" to make
jiffies wrap bugs appear earlier. However, this causes time_before() in
damon_sysfs_repeat_call_fn() 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
does not update sysfs files during that period.

There is also an issue unrelated to the system's word size[2]: if the
user stops DAMON just after next_update_jiffies is updated and restarts
it after 'refresh_ms' or a longer delay, next_update_jiffies will retain
an older value, causing time_before() to return false and the update to
happen earlier than expected.

Fix these issues by making next_update_jiffies a global variable and
initializing it each time DAMON is started.

Link: https://lkml.kernel.org/r/20251030020746.967174-3-yanquanmin1@huawei.com
Link: https://lkml.kernel.org/r/20250822025057.1740854-1-ekffu200098@gmail.com
Link: https://lore.kernel.org/all/20251029013038.66625-1-sj@kernel.org/
Fixes: d809a7c64ba8 ("mm/damon/sysfs: implement refresh_ms file internal work")
Suggested-by: SeongJae Park <sj@kernel.org>
Reviewed-by: SeongJae Park <sj@kernel.org>
Signed-off-by: Quanmin Yan <yanquanmin1@huawei.com>
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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
mm/damon/sysfs.c

index 2959beb4bcbfd5dc21f690bad44b7c394e467fd6..ea2feddc4b886e9f14e73a7a63a0c991fb1e6cfd 100644 (file)
@@ -1514,16 +1514,17 @@ static struct damon_ctx *damon_sysfs_build_ctx(
        return ctx;
 }
 
+static unsigned long damon_sysfs_next_update_jiffies;
+
 static int damon_sysfs_repeat_call_fn(void *data)
 {
        struct damon_sysfs_kdamond *sysfs_kdamond = data;
-       static unsigned long next_update_jiffies;
 
        if (!sysfs_kdamond->refresh_ms)
                return 0;
-       if (time_before(jiffies, next_update_jiffies))
+       if (time_before(jiffies, damon_sysfs_next_update_jiffies))
                return 0;
-       next_update_jiffies = jiffies +
+       damon_sysfs_next_update_jiffies = jiffies +
                msecs_to_jiffies(sysfs_kdamond->refresh_ms);
 
        if (!mutex_trylock(&damon_sysfs_lock))
@@ -1569,6 +1570,9 @@ static int damon_sysfs_turn_damon_on(struct damon_sysfs_kdamond *kdamond)
        }
        kdamond->damon_ctx = ctx;
 
+       damon_sysfs_next_update_jiffies =
+               jiffies + msecs_to_jiffies(kdamond->refresh_ms);
+
        repeat_call_control->fn = damon_sysfs_repeat_call_fn;
        repeat_call_control->data = kdamond;
        repeat_call_control->repeat = true;