Skip to contentSkip to conversation

mm/damon/core: keep the temporal tuner quota over an unmeasured PSI round

PATCH Applied SJ Park 4 participants 4 messages Sep 23 – Sep 24

Subsystems (3)
lore
Share & tools
lore

SJ Park

author maintainer
#0 lore raw

PATCH v3 1/1 mm/damon/core: keep the temporal tuner quota over an unmeasured PSI round

From: Karl Mehltretter <[email protected]>

The patch in mm-unstable of subject "mm/damon/core: handle uninitialized damos_quota_goal->last_psi_total" scores a PSI quota goal without a previous sample as achieved. This leaves the consist tuner's input unchanged, but the temporal tuner sets its quota to zero for an achieved goal. A running scheme with a nonzero temporal quota therefore loses a charge window after a quota-goal commit.

Use the effective quota to preserve the temporal tuner's previous goal-achievement state during an unmeasured round, as SJ suggested [1]. Score the goal as achieved when the effective quota is zero and as not achieved otherwise. A new scheme's initially zero quota stays zero, and the consist tuner's behavior is unchanged.

Move the PSI current-value calculation and last_psi_total update into a helper that takes the current PSI total. This lets a unit test cover the unmeasured and measured rounds without depending on system memory pressure.

Fixes 2dbb60f789cb ("mm/damon/core: implement PSI metric DAMOS quota goal")
Cc <[email protected]> # 6.9.x
Cc Lian Wang <[email protected]>
Cc Kunwu Chan <[email protected]>
Assisted-by LLM

---
This is a fixup of a patch [1] that is still in mm-unstable tree.

[1] https://lore.kernel.org/[email protected]

Changes from v2
- v2: https://lore.kernel.org/[email protected]
- Split out of the series for squashing into the broken patch.
- Collect R-b: from SJ.
- Update commit message to make clear this is a fixup of a patch in mm-unstable.
Changes since v1
- v1: https://lore.kernel.org/[email protected]/
- Use the previous effective quota for the temporal decision, including when it is zero. Keep resetting last_psi_total for new and updated goals.
- Move the current-value calculation and last_psi_total update into a helper. Test both tuners with explicit samples and check last_psi_total after each call.

 mm/damon/core.c | 30 +++++++++++++++++++++++-------
 1 file changed, 23 insertions(+), 7 deletions(-)
mm/damon/core.c +23 -7
index 4687b909d42c..733025b36745 100644
@@ -2956,6 +2956,28 @@ static inline u64 damos_get_some_mem_psi_total(void)
 
 #endif	/* CONFIG_PSI */
 
+static void damos_set_psi_current_val(u64 now_psi_total,
+		struct damos_quota_goal *goal, struct damos *s)
+{
+	u64 last_psi_total = goal->last_psi_total;
+
+	goal->last_psi_total = now_psi_total;
+	if (last_psi_total != U64_MAX) {
+		goal->current_value = now_psi_total - last_psi_total;
+		return;
+	}
+	/* uninitialized last_psi_total; make no effect this round */
+	if (s->quota.goal_tuner == DAMOS_QUOTA_GOAL_TUNER_CONSIST) {
+		goal->current_value = goal->target_value;
+		return;
+	}
+	/* let temporal tuner show the same achievement as in the last round */
+	if (!s->quota.esz)
+		goal->current_value = goal->target_value;
+	else
+		goal->current_value = 0;
+}
+
 #ifdef CONFIG_NUMA
 static bool invalid_mem_node(int nid)
 {
@@ -3208,13 +3230,7 @@ static void damos_set_quota_goal_current_value(struct damon_ctx *c,
 		break;
 	case DAMOS_QUOTA_SOME_MEM_PSI_US:
 		now_psi_total = damos_get_some_mem_psi_total();
-		/* uninitialized last_psi_total; make no effect this round */
-		if (goal->last_psi_total == U64_MAX)
-			goal->current_value = goal->target_value;
-		else
-			goal->current_value = now_psi_total -
-				goal->last_psi_total;
-		goal->last_psi_total = now_psi_total;
+		damos_set_psi_current_val(now_psi_total, goal, s);
 		break;
 	case DAMOS_QUOTA_NODE_MEM_USED_BP:
 	case DAMOS_QUOTA_NODE_MEM_FREE_BP:

base-commit: 4b811cf44e3dd87981f18631be832027385f7d4f

Signature · 1 line
2.47.3
#1 lore raw
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 20 lines

From: Karl Mehltretter <[email protected]>

The patch in mm-unstable of subject "mm/damon/core: handle uninitialized damos_quota_goal->last_psi_total" scores a PSI quota goal without a previous sample as achieved. This leaves the consist tuner's input unchanged, but the temporal tuner sets its quota to zero for an achieved goal. A running scheme with a nonzero temporal quota therefore loses a charge window after a quota-goal commit.

Use the effective quota to preserve the temporal tuner's previous goal-achievement state during an unmeasured round, as SJ suggested [1]. Score the goal as achieved when the effective quota is zero and as not achieved otherwise. A new scheme's initially zero quota stays zero, and the consist tuner's behavior is unchanged.

Move the PSI current-value calculation and last_psi_total update into a helper that takes the current PSI total. This lets a unit test cover the unmeasured and measured rounds without depending on system memory pressure.

Quoted 10 lines
Fixes 2dbb60f789cb ("mm/damon/core: implement PSI metric DAMOS quota goal")
Cc <[email protected]> # 6.9.x
Cc Lian Wang <[email protected]>
Cc Kunwu Chan <[email protected]>
Assisted-by LLM

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Reviewed-by on v3 1/1
#2 lore raw
In reply to SJ Park

Thanks for the update.

I also checked the issue I raised on v1 regarding unmeasured rounds. The temporal case now uses the effective quota to determine current_value when there is no previous PSI sample, while measured rounds continue to use the PSI delta and update last_psi_total.

Thanks,
Kunwu

Quoted 106 lines · SJ Park

From: Karl Mehltretter <[email protected]>

The patch in mm-unstable of subject "mm/damon/core: handle uninitialized damos_quota_goal->last_psi_total" scores a PSI quota goal without a previous sample as achieved. This leaves the consist tuner's input unchanged, but the temporal tuner sets its quota to zero for an achieved goal. A running scheme with a nonzero temporal quota therefore loses a charge window after a quota-goal commit.

Use the effective quota to preserve the temporal tuner's previous goal-achievement state during an unmeasured round, as SJ suggested [1]. Score the goal as achieved when the effective quota is zero and as not achieved otherwise. A new scheme's initially zero quota stays zero, and the consist tuner's behavior is unchanged.

Move the PSI current-value calculation and last_psi_total update into a helper that takes the current PSI total. This lets a unit test cover the unmeasured and measured rounds without depending on system memory pressure.

Fixes 2dbb60f789cb ("mm/damon/core: implement PSI metric DAMOS quota goal")
Cc <[email protected]> # 6.9.x
Cc Lian Wang <[email protected]>
Cc Kunwu Chan <[email protected]>
Assisted-by LLM

---
This is a fixup of a patch [1] that is still in mm-unstable tree.

[1] https://lore.kernel.org/[email protected]

Changes from v2
- v2: https://lore.kernel.org/[email protected]
- Split out of the series for squashing into the broken patch.
- Collect R-b: from SJ.
- Update commit message to make clear this is a fixup of a patch in mm-unstable.
Changes since v1
- v1: https://lore.kernel.org/[email protected]/
- Use the previous effective quota for the temporal decision, including when it is zero. Keep resetting last_psi_total for new and updated goals.
- Move the current-value calculation and last_psi_total update into a helper. Test both tuners with explicit samples and check last_psi_total after each call.

 mm/damon/core.c | 30 +++++++++++++++++++++++-------
 1 file changed, 23 insertions(+), 7 deletions(-)
mm/damon/core.c +23 -7
index 4687b909d42c..733025b36745 100644
@@ -2956,6 +2956,28 @@ static inline u64 damos_get_some_mem_psi_total(void)
 
 #endif /* CONFIG_PSI */
 
+static void damos_set_psi_current_val(u64 now_psi_total,
+               struct damos_quota_goal *goal, struct damos *s)
+{
+       u64 last_psi_total = goal->last_psi_total;
+
+       goal->last_psi_total = now_psi_total;
+       if (last_psi_total != U64_MAX) {
+               goal->current_value = now_psi_total - last_psi_total;
+               return;
+       }
+       /* uninitialized last_psi_total; make no effect this round */
+       if (s->quota.goal_tuner == DAMOS_QUOTA_GOAL_TUNER_CONSIST) {
+               goal->current_value = goal->target_value;
+               return;
+       }
+       /* let temporal tuner show the same achievement as in the last round */
+       if (!s->quota.esz)
+               goal->current_value = goal->target_value;
+       else
+               goal->current_value = 0;
+}
+
 #ifdef CONFIG_NUMA
 static bool invalid_mem_node(int nid)
 {
@@ -3208,13 +3230,7 @@ static void damos_set_quota_goal_current_value(struct damon_ctx *c,
                break;
        case DAMOS_QUOTA_SOME_MEM_PSI_US:
                now_psi_total = damos_get_some_mem_psi_total();
-               /* uninitialized last_psi_total; make no effect this round */
-               if (goal->last_psi_total == U64_MAX)
-                       goal->current_value = goal->target_value;
-               else
-                       goal->current_value = now_psi_total -
-                               goal->last_psi_total;
-               goal->last_psi_total = now_psi_total;
+               damos_set_psi_current_val(now_psi_total, goal, s);
                break;
        case DAMOS_QUOTA_NODE_MEM_USED_BP:
        case DAMOS_QUOTA_NODE_MEM_FREE_BP:

base-commit: 4b811cf44e3dd87981f18631be832027385f7d4f --
2.47.3

maintainer
#3 lore raw
In reply to SJ Park
Quoted 20 lines · On Tue, 22 Sep 2026 22:51:37 -0700 SJ Park <[email protected]> wrote:

From: Karl Mehltretter <[email protected]>

The patch in mm-unstable of subject "mm/damon/core: handle uninitialized damos_quota_goal->last_psi_total" scores a PSI quota goal without a previous sample as achieved. This leaves the consist tuner's input unchanged, but the temporal tuner sets its quota to zero for an achieved goal. A running scheme with a nonzero temporal quota therefore loses a charge window after a quota-goal commit.

Use the effective quota to preserve the temporal tuner's previous goal-achievement state during an unmeasured round, as SJ suggested [1]. Score the goal as achieved when the effective quota is zero and as not achieved otherwise. A new scheme's initially zero quota stays zero, and the consist tuner's behavior is unchanged.

Move the PSI current-value calculation and last_psi_total update into a helper that takes the current PSI total. This lets a unit test cover the unmeasured and measured rounds without depending on system memory pressure.

Quoted 5 lines

...

This is a fixup of a patch [1] that is still in mm-unstable tree.

[1] https://lore.kernel.org/[email protected]

thanks, I'll queue this as a squashable fix against "mm/damon/core:
handle uninitialized damos_quota_goal->last_psi_total".

Which means I locally named it mm-damon-core-handle-uninitialized-damos_quota_goal-last_psi_total-fix.patch and shall squash it in before moving things into mm-stable. Karl's contribution will be captured in a footer note and a Signed-off-by:.