From nobody Sat Sep 26 22:53:38 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B9E8A3BB669; Fri, 28 Aug 2026 18:36:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787942219; cv=none; b=M71kxZ94cTp4flR/C8cEfhzuwvL5LdOv2OFT0CnzFNwIaksN6+ju6f8eqKORYE39sBjECg5q24vOCZH96yjZBVDXQqUijOxuJm8gzXukytVLswfcX5BdH1VDTp0dmWUBbAAhFD6ZLh3cfN1yw8QG+kyad+fBOYhOlFZynl3LR/g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787942219; c=relaxed/simple; bh=zYSmy5K+uBSKqiQ6mGp6GOZRIgNJU5Mho+lWnM8XtL8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=N3kJhE1fcfuAbn+HNlpVb8q6BHr5pwtFdRK1WIPADDupfi9OuPQo3JnMG4gSbwtOCav3SqFR1Mf3P5k9OIhHbhJGhfGs6Io6bSoxVesG+DhpoEnNLq1h5XNkoy8C3TSuJFX39UphoPt3OlpsP1GvuoXNB+tGlfokf53ez8gkOTU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=T05ammM8; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="T05ammM8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 555551F00A3F; Fri, 28 Aug 2026 18:36:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1787942218; bh=+fW2+xE2H0LI68hS7+oEWra7KzRlcB7nNxeFxWmibVg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=T05ammM8ldq+G6bXx1kNn1wOtHyf0oeGDeu71AbtcDekKRYIydOLwGmjIc9uhk9X5 Ir3MfGZmKvcqnkGMsfP8dOUx4l/yB+CvyNAfA3lDzGNCMD6g2BPsqrTtwdNJVnoCvx x1C585X5TVS6xngWNLwcL2NnOeE6d7obk61ADtzwmfTa+0WnSTIjclPNl+itxnCpcT mRSGfb1O64QAV7SL4PK/Szh24CsX3fnmtH/wtaGh+HCbK+a/AVTQwgQzNpUCLY83SI EmDj1bcECwJxe8t9cIV8/9Mqx8I4Y0Lxjh0L9855tu+uInpjH5wGvgdwEQS1SVkFl/ kCjORItPBKqAg== From: SJ Park To: Cc: SJ Park , stable@vger.kernel.org, Andrew Morton , Brendan Higgins , David Gow , damon@lists.linux.dev, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH v1.3 1/4] mm/damon/tests/core-kunit: test committing psi goal to psi goal Date: Fri, 28 Aug 2026 11:36:45 -0700 Message-ID: <20260828183649.71192-2-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260828183649.71192-1-sj@kernel.org> References: <20260828183649.71192-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" damon_test_commit_quota_goal_for() is set to test committing a new psi goal on an existing psi goal. However, damon_test_commit_quota_goal() is mistakenly not covering the test case. Add the test case. Fixes: 99f89debafc5 ("mm/damon/tests/core-kunit: add damos_commit_quota_goa= l() test") Cc: # 6.19.x Signed-off-by: SJ Park --- mm/damon/tests/core-kunit.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h index 4a536d41cdb2d..b643f9a83f14a 100644 --- a/mm/damon/tests/core-kunit.h +++ b/mm/damon/tests/core-kunit.h @@ -787,6 +787,13 @@ static void damos_test_commit_quota_goal(struct kunit = *test) .last_psi_total =3D 456, }; =20 + damos_test_commit_quota_goal_for(test, &dst, + &(struct damos_quota_goal) { + .metric =3D DAMOS_QUOTA_SOME_MEM_PSI_US, + .target_value =3D 234, + .current_value =3D 345, + .last_psi_total =3D 567, + }); damos_test_commit_quota_goal_for(test, &dst, &(struct damos_quota_goal){ .metric =3D DAMOS_QUOTA_USER_INPUT, --=20 2.47.3 From nobody Sat Sep 26 22:53:38 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 614193B42C4; Fri, 28 Aug 2026 18:36:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787942220; cv=none; b=ou2wkWJRiZCX3PS76RdgaI3xJO3psiBtgR0mpE0j4m8XHoyGHKF7Bic59CwvHdZZ4ZOTP3rk+rRNC++Vlpmxdaz9V9Adf5qU4HYe6lTt7i2eJbFAgHe2XR7zUv2GnmTImJS/GaTyXj6+1bvtPq0hu8D63HSk4uaGAuB+mFUAZ6A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787942220; c=relaxed/simple; bh=tVNapXlYkQ32nnMP3sPEC54ww38RNCe9730GIg4dbSM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Wl0pi6ElZy8nF0XiF3AUzEzKPNfXFVpqX4A2UBrMJ6CVXMBT9bB9SQ/cN+8DKTg93y8TKwxvDgDCfWreIVqhipZUKLsIUkX19xyAk73/ikwHEFVWikTahqb3FIwjqkNswGeQfhdahakL66MbbJUk+RNy4/9//5+mjw+OGNIhxfU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IMSACD1G; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="IMSACD1G" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C8DB71F00A3E; Fri, 28 Aug 2026 18:36:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1787942219; bh=ILg2MhhSKzgWHRltlNiHRKhJSlsLIqjHOT6/IdLHUBo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=IMSACD1Gr+V+IdheVn8p1p0px7uNJyYwB8E3M8zhJRcnRIDJhGr6bCsbHlnSott92 mfy/kQF5Y5TYRvNPGXrMkzMa4YRbIfTD6siueBaTJ/5gFDdhSG2vlddpxHRsMxnz/Z TBXuTGEdx7yBV/dhx/eoJ9F6aG5HNdo8oJJzS84847cqo410rVZ/zriXvpdtJ3NIZn 16iM9DsuN50Wxw82IgD8/NcOUVixXiRV/IZrkM4GcsxUOcq5+UIYdUU770MZj/aFWa PbnBalsqnUqpYMz8KkKGPgVmHI8GbnWG+mrLGVApmIltzMOUrS+8mnk7/N0NmFfjlC q3lJnlwsL91tg== From: SJ Park To: Cc: SJ Park , stable@vger.kernel.org, Andrew Morton , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH v1.3 2/4] mm/damon/core: handle uninitialized damos_quota_goal->last_psi_total Date: Fri, 28 Aug 2026 11:36:46 -0700 Message-ID: <20260828183649.71192-3-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260828183649.71192-1-sj@kernel.org> References: <20260828183649.71192-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When DAMOS_QUOTA_SOME_MEM_PSI_US metric damos quota goal is set, the PSI delta for the feedback loop is calculated using damos_quota_goal->last_psi_total. However, it is initialized only after the first feedback loop. The first iteration of the loop uses the uninitialized value. As a result, the feedback loop can change the effective quota in an unexpected way at the first iteration. The user impact of the issue is not big, because the issue impacts only the first iteration of the feedback loop. The feedback loop also has an internal cap of the quota adjustment. The wrong adjustment will soon be corrected over a few iterations. For this reason, doing no initialization at commit time was intentional. It is also explicitly commented. That said, nobody likes behaviors that are unexpected or difficult to be expected. Check last_psi_total initialization and skip the tuning round when it is not initialized. For this, initialize last_psi_total with U64_MAX in the goal creation and the goal commit time. U64_MAX means the field is not initialized. The tuning round shows the value and adjusts it to guarantee the current quota is maintained for the round, and last_psi_total is correctly initialized on the next round. Before this change, committing a new PSI goal on an existing PSI goal with goal-only DAMON sysfs command (commit_schemes_quota_goals) just worked. After this change, the tuning round right after the commit will be unnecessarily skipped, because last_psi_total is unconditionally marked as not initialized in the damos_commit_quota_goal_union(). This is an intended tradeoff for simplicity. Skipping just one round of tuning is no problem. Meanwhile it makes both the code and the behavior simple to understand. Also update the quota goal commit unit test for changed last_psi_total setup behavior. The issue was discovered [1] by Sashiko. [1] https://lore.kernel.org/20260718005316.89585-1-sj@kernel.org Fixes: 2dbb60f789cb ("mm/damon/core: implement PSI metric DAMOS quota goal") Cc: # 6.9.x Signed-off-by: SJ Park --- mm/damon/core.c | 13 +++++++++++-- mm/damon/tests/core-kunit.h | 9 +++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/mm/damon/core.c b/mm/damon/core.c index f8dddbff74a77..39605e64dabf2 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -635,6 +635,8 @@ struct damos_quota_goal *damos_new_quota_goal( return NULL; goal->metric =3D metric; goal->target_value =3D target_value; + if (metric =3D=3D DAMOS_QUOTA_SOME_MEM_PSI_US) + goal->last_psi_total =3D U64_MAX; INIT_LIST_HEAD(&goal->list); return goal; } @@ -1122,6 +1124,9 @@ static void damos_commit_quota_goal_union( struct damos_quota_goal *dst, struct damos_quota_goal *src) { switch (dst->metric) { + case DAMOS_QUOTA_SOME_MEM_PSI_US: + dst->last_psi_total =3D U64_MAX; + break; case DAMOS_QUOTA_NODE_MEM_USED_BP: case DAMOS_QUOTA_NODE_MEM_FREE_BP: dst->nid =3D src->nid; @@ -1143,7 +1148,6 @@ static void damos_commit_quota_goal( dst->target_value =3D src->target_value; if (dst->metric =3D=3D DAMOS_QUOTA_USER_INPUT) dst->current_value =3D src->current_value; - /* keep last_psi_total as is, since it will be updated in next cycle */ damos_commit_quota_goal_union(dst, src); } =20 @@ -3032,7 +3036,12 @@ static void damos_set_quota_goal_current_value(struc= t damon_ctx *c, break; case DAMOS_QUOTA_SOME_MEM_PSI_US: now_psi_total =3D damos_get_some_mem_psi_total(); - goal->current_value =3D now_psi_total - goal->last_psi_total; + /* uninitialized last_psi_total; make no effect this round */ + if (goal->last_psi_total =3D=3D U64_MAX) + goal->current_value =3D goal->target_value; + else + goal->current_value =3D now_psi_total - + goal->last_psi_total; goal->last_psi_total =3D now_psi_total; break; case DAMOS_QUOTA_NODE_MEM_USED_BP: diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h index b643f9a83f14a..65443aba03300 100644 --- a/mm/damon/tests/core-kunit.h +++ b/mm/damon/tests/core-kunit.h @@ -751,19 +751,16 @@ static void damos_test_commit_quota_goal_for(struct k= unit *test, struct damos_quota_goal *dst, struct damos_quota_goal *src) { - u64 dst_last_psi_total =3D 0; - - if (dst->metric =3D=3D DAMOS_QUOTA_SOME_MEM_PSI_US) - dst_last_psi_total =3D dst->last_psi_total; damos_commit_quota_goal(dst, src); =20 KUNIT_EXPECT_EQ(test, dst->metric, src->metric); KUNIT_EXPECT_EQ(test, dst->target_value, src->target_value); if (src->metric =3D=3D DAMOS_QUOTA_USER_INPUT) KUNIT_EXPECT_EQ(test, dst->current_value, src->current_value); - if (dst_last_psi_total && src->metric =3D=3D DAMOS_QUOTA_SOME_MEM_PSI_US) - KUNIT_EXPECT_EQ(test, dst->last_psi_total, dst_last_psi_total); switch (dst->metric) { + case DAMOS_QUOTA_SOME_MEM_PSI_US: + KUNIT_EXPECT_EQ(test, dst->last_psi_total, U64_MAX); + break; case DAMOS_QUOTA_NODE_MEM_USED_BP: case DAMOS_QUOTA_NODE_MEM_FREE_BP: KUNIT_EXPECT_EQ(test, dst->nid, src->nid); --=20 2.47.3 From nobody Sat Sep 26 22:53:38 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A1F8B3BA246; Fri, 28 Aug 2026 18:36:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787942220; cv=none; b=LiyMe5TxFTeNEXw5clvn/8T63Vg6zmY5JaIsfCDgwPdZXzBuokQK/5DvgZ+j7ul2sBJAcXUcD7iw/sNQExZOAy81gBDHqlsfuK3e96R/xZGcSrdVkIMZY7fYIACLn9XT5S/haE1CC7LQQ2oWMRoWYVWeCpoYH96u4FPwb+SJNfg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787942220; c=relaxed/simple; bh=yua3+vJZxoD4D8iUD7DkUwYEHYEvn7FwxVTEKR9KqT0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UTazjpz/rrAf6y5v6hdH7rbgLhxYAPV3UMLjrbFq/+aZt0EdplqgWhWTIrntuS889vO/NJ9EQ2eEM/SAlGARR/24XONbIpgyJNmGIG+mNA5ui5xbSoou/LANyEZj3ywn7tLrhssPFmdsCj+ptQumU3lHQWzMT8n/8CQv1LjdPYI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GZ9DFD1H; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GZ9DFD1H" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 339101F00ADB; Fri, 28 Aug 2026 18:36:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1787942219; bh=+IOYzbq22lhYIf1iXAGWkCEwZrUSQpgR/aOknVb4vnM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=GZ9DFD1HCeOqE9xfWczRsB/Jf8bnqdi6VhHAyJPn52H77HPYsj9JTrPKSty0M2Kk9 0UL6R9253A8E9Br970ftJaIx8QNUQOOuwmGdFK4G2/v83ZRt4sfZMJEvZUl8+bXR6M qZ3w4yBwNfMPmRQilj2boskC6V+LcHz+iswV3QK8p+EdHpjoPotT+3I3d+6ghAMHeX A2mHtaVE8+YMuoss7QXfcfx9f4v5fSxNkqf1GlzfBoF46/uRnutowkv4Kx8kHxoBqJ pvr6YxvJYZFIoRGhklUa+6cVySPOxdDQ15BW9/9+joPEm4GH0nnhmMc3VGOlR0nQxp spC+8u8Q+Z7Ww== From: SJ Park To: Cc: SJ Park , stable@vger.kernel.org, Andrew Morton , Ravi Jonnalagadda , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH v1.3 3/4] mm/damon/core: copy nid for eligible_mem_bp damos quota goal commit Date: Fri, 28 Aug 2026 11:36:47 -0700 Message-ID: <20260828183649.71192-4-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260828183649.71192-1-sj@kernel.org> References: <20260828183649.71192-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" damos_commit_quota_goal_union() is not updating the ->nid union field when the goal metric is DAMOS_QUITA_NODE_ELIGIBLE_MEM_BP. Hence, if a DAMOS quota goal of the type is online committed in a way that it will reuse other quota goal's memory space, the new goal will work with a garbage nid value. As a result, the DAMOS scheme can show unexpected aggressiveness. Do the update. The user impact is not catastrophic. No leak or crash happens. Doing the quota goal online commit that can reproduce the issue is expected to be not common. This issue was not found by real users but the AI review. That said, the issue can reliably be reproduced. This issue was discovered [1] by Sashiko. [1] https://lore.kkernel.org/20260827045035.94611-1-sj@kernel.org Fixes: 9138e27a3bc3 ("mm/damon: add node_eligible_mem_bp goal metric") Cc: # 7.2.x Signed-off-by: SJ Park --- mm/damon/core.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/damon/core.c b/mm/damon/core.c index 39605e64dabf2..b3f8bea774c2d 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -1136,6 +1136,9 @@ static void damos_commit_quota_goal_union( dst->nid =3D src->nid; dst->memcg_id =3D src->memcg_id; break; + case DAMOS_QUOTA_NODE_ELIGIBLE_MEM_BP: + dst->nid =3D src->nid; + break; default: break; } --=20 2.47.3 From nobody Sat Sep 26 22:53:38 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E79343BB9F8; Fri, 28 Aug 2026 18:36:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787942230; cv=none; b=Sp4Q/J07JyxQ0KIm7w1J++Evdiku6dtcWqyhC0Q0aYuO528BeQ2O4XejCUtJsvxCpsrQf1ay+bsvW0CkZLNhyp2B3Ik03W24Zwf0hZPRwisgOQRZti5lRZdKgOWNozYnEsGnHdPvwdZqlG2rOZAYx8xsyAShD3hu6WwuFYiSXEk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787942230; c=relaxed/simple; bh=ncX71bZRwu4AuWDsk7FltFFxkbG60aAYKLG941OcN9c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=u/t+T+HMIQGhIqrEiPasPHsGOVlfn/Pvw5AfEhJaaHJnYlAiqtxf4waDrofkuKA1LEBae0KIttNzlEmoOkkCzjqLYlDB8+BRemnnbkvTm18XpA6Lz3zNOnW3IO8gB3peMIQNklyKGvWbRRWHMqnxXsji0U9b/QzmCxOSzA/p5gQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=j9FMR5Jn; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="j9FMR5Jn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 949BC1F00AC4; Fri, 28 Aug 2026 18:36:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1787942219; bh=9nWd2JiHbGpFxdKtIgR1/mA2jBP+r1D6KF4ucSMyulY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=j9FMR5JnmSH7efPrQrLnpZLbc7Yz1AcigZ2oXDJSOH7R3q+6I7rgrm+O0sLvmBJK8 xZf8nG4qvXcOnt+j9VyThzjR9Sfe3zfany2jSS/bQRGk1Rr/6KjiU0F8H06/dTsaff D2XKwF71uHMP5vP2RsodJkj97KtLehKD5EUkQDx5qRFZcxQJlgmYpmSv4Z1t7DDOLd uM4q1bVIScrAheTmJpDfRBCKmyWltOYiXf2K77JvOG+WoAsNObZLOQifqSFck50JXP MrkarOd6d6n+JAFTYqptHsuEHsamarp6wWpKvoYtcBSbiamIrOvZH8V2T/3pmMuVBI 8/uwDVYOpXdVg== From: SJ Park To: Cc: SJ Park , stable@vger.kernel.org, Andrew Morton , Quanmin Yan , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH v1.3 4/4] mm/damon/sysfs: set next refresh jiffies per sysfs context Date: Fri, 28 Aug 2026 11:36:48 -0700 Message-ID: <20260828183649.71192-5-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260828183649.71192-1-sj@kernel.org> References: <20260828183649.71192-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When 'refresh_ms' is set, DAMON sysfs interface periodically updates auto-tuned parameters and DAMOS stats. The timestamp for the next refresh is initialized when a DAMON context starts, and updated in its damon_call() callback function. That is, each DAMON context updates it. However, the timestamp is a global variable that is shared with all the contexts. When there are multiple DAMON contexts having different refresh_ms, the update frequency will be changed, depending on the order of the contexts. When there are multiple kdamonds, it will be even more chaotic. Fix the problem by having the timestamp per each context. The user impact is not very critical. It does not leak, corrupt or crash. The update will not be faster or slower than the lowest and largest refresh_ms values of the contexts, respectively. The user can also manually ask the updates on demand using kdamond state commands. That said, clearly this is a bug and can easily be reproduced. Fixes: 9fd7bb5083d1 ("mm/damon/sysfs: change next_update_jiffies to a globa= l variable") Cc: # 6.18.x Signed-off-by: SJ Park --- mm/damon/sysfs.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index e3858ffab4b22..f05b256c90ee7 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1789,6 +1789,7 @@ struct damon_sysfs_kdamond { struct damon_sysfs_contexts *contexts; struct damon_ctx *damon_ctx; unsigned int refresh_ms; + unsigned long next_refresh_jiffies; }; =20 static struct damon_sysfs_kdamond *damon_sysfs_kdamond_alloc(void) @@ -2215,17 +2216,15 @@ static struct damon_ctx *damon_sysfs_build_ctx( return ctx; } =20 -static unsigned long damon_sysfs_next_update_jiffies; - static int damon_sysfs_repeat_call_fn(void *data) { struct damon_sysfs_kdamond *sysfs_kdamond =3D data; =20 if (!sysfs_kdamond->refresh_ms) return 0; - if (time_before(jiffies, damon_sysfs_next_update_jiffies)) + if (time_before(jiffies, sysfs_kdamond->next_refresh_jiffies)) return 0; - damon_sysfs_next_update_jiffies =3D jiffies + + sysfs_kdamond->next_refresh_jiffies =3D jiffies + msecs_to_jiffies(sysfs_kdamond->refresh_ms); =20 if (!mutex_trylock(&damon_sysfs_lock)) @@ -2273,8 +2272,8 @@ static int damon_sysfs_turn_damon_on(struct damon_sys= fs_kdamond *kdamond) } kdamond->damon_ctx =3D ctx; =20 - damon_sysfs_next_update_jiffies =3D - jiffies + msecs_to_jiffies(kdamond->refresh_ms); + kdamond->next_refresh_jiffies =3D jiffies + + msecs_to_jiffies(kdamond->refresh_ms); =20 repeat_call_control->fn =3D damon_sysfs_repeat_call_fn; repeat_call_control->data =3D kdamond; --=20 2.47.3