Add the logic to copy the current_value from the internal
damos_quota_goal structure to the damos_sysfs_quota_goal sysfs structure.
Introduce the DAMON_SYSFS_CMD_UPDATE_SCHEMES_QUOTA_GOALS command
and integrate it with the sysfs interface via the 'state' file.

Assisted-by: Antigravity:Gemini-3.1-Pro
Signed-off-by: Maksym Shcherba <[email protected]>
---
 mm/damon/sysfs-common.h  |  4 ++++
 mm/damon/sysfs-schemes.c | 29 +++++++++++++++++++++++++++++
 mm/damon/sysfs.c         | 21 +++++++++++++++++++++
 3 files changed, 54 insertions(+)

diff --git a/mm/damon/sysfs-common.h b/mm/damon/sysfs-common.h
index 2099adee11d0..9703414fa15f 100644
--- a/mm/damon/sysfs-common.h
+++ b/mm/damon/sysfs-common.h
@@ -59,3 +59,7 @@ int damos_sysfs_set_quota_scores(struct damon_sysfs_schemes 
*sysfs_schemes,
 void damos_sysfs_update_effective_quotas(
                struct damon_sysfs_schemes *sysfs_schemes,
                struct damon_ctx *ctx);
+
+void damos_sysfs_update_quota_goals(
+               struct damon_sysfs_schemes *sysfs_schemes,
+               struct damon_ctx *ctx);
diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c
index 5d966ac86419..5793659403ca 100644
--- a/mm/damon/sysfs-schemes.c
+++ b/mm/damon/sysfs-schemes.c
@@ -2812,6 +2812,35 @@ void damos_sysfs_update_effective_quotas(
        }
 }
 
+void damos_sysfs_update_quota_goals(
+               struct damon_sysfs_schemes *sysfs_schemes,
+               struct damon_ctx *ctx)
+{
+       struct damos *scheme;
+       int schemes_idx = 0;
+
+       damon_for_each_scheme(scheme, ctx) {
+               struct damos_sysfs_quota_goals *sysfs_goals;
+               struct damos_quota_goal *goal;
+               int goals_idx = 0;
+
+               /* user could have removed the scheme sysfs dir */
+               if (schemes_idx >= sysfs_schemes->nr)
+                       break;
+
+               sysfs_goals =
+                       
sysfs_schemes->schemes_arr[schemes_idx++]->quotas->goals;
+
+               damos_for_each_quota_goal(goal, &scheme->quota) {
+                       if (goals_idx >= sysfs_goals->nr)
+                               break;
+
+                       sysfs_goals->goals_arr[goals_idx++]->current_value =
+                               goal->current_value;
+               }
+       }
+}
+
 static int damos_sysfs_add_migrate_dest(struct damos *scheme,
                struct damos_sysfs_dests *sysfs_dests)
 {
diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c
index d5863cc33d23..ecc880b52b32 100644
--- a/mm/damon/sysfs.c
+++ b/mm/damon/sysfs.c
@@ -1320,6 +1320,11 @@ enum damon_sysfs_cmd {
         * effective size quota of the scheme in bytes.
         */
        DAMON_SYSFS_CMD_UPDATE_SCHEMES_EFFECTIVE_QUOTAS,
+       /*
+        * @DAMON_SYSFS_CMD_UPDATE_SCHEMES_QUOTA_GOALS: Update the
+        * current value of the scheme quota goals.
+        */
+       DAMON_SYSFS_CMD_UPDATE_SCHEMES_QUOTA_GOALS,
        /*
         * @DAMON_SYSFS_CMD_UPDATE_TUNED_INTERVALS: Update the tuned monitoring
         * intervals.
@@ -1342,6 +1347,7 @@ static const char * const damon_sysfs_cmd_strs[] = {
        "update_schemes_tried_regions",
        "clear_schemes_tried_regions",
        "update_schemes_effective_quotas",
+       "update_schemes_quota_goals",
        "update_tuned_intervals",
 };
 
@@ -1606,6 +1612,16 @@ static int damon_sysfs_upd_schemes_effective_quotas(void 
*data)
        return 0;
 }
 
+static int damon_sysfs_upd_schemes_quota_goals(void *data)
+{
+       struct damon_sysfs_kdamond *kdamond = data;
+       struct damon_ctx *ctx = kdamond->damon_ctx;
+
+       damos_sysfs_update_quota_goals(
+                       kdamond->contexts->contexts_arr[0]->schemes, ctx);
+       return 0;
+}
+
 static int damon_sysfs_upd_tuned_intervals(void *data)
 {
        struct damon_sysfs_kdamond *kdamond = data;
@@ -1656,6 +1672,7 @@ static int damon_sysfs_repeat_call_fn(void *data)
        damon_sysfs_upd_tuned_intervals(sysfs_kdamond);
        damon_sysfs_upd_schemes_stats(sysfs_kdamond);
        damon_sysfs_upd_schemes_effective_quotas(sysfs_kdamond);
+       damon_sysfs_upd_schemes_quota_goals(sysfs_kdamond);
 out:
        mutex_unlock(&damon_sysfs_lock);
        return 0;
@@ -1813,6 +1830,10 @@ static int damon_sysfs_handle_cmd(enum damon_sysfs_cmd 
cmd,
                return damon_sysfs_damon_call(
                                damon_sysfs_upd_schemes_effective_quotas,
                                kdamond);
+       case DAMON_SYSFS_CMD_UPDATE_SCHEMES_QUOTA_GOALS:
+               return damon_sysfs_damon_call(
+                               damon_sysfs_upd_schemes_quota_goals,
+                               kdamond);
        case DAMON_SYSFS_CMD_UPDATE_TUNED_INTERVALS:
                return damon_sysfs_damon_call(
                                damon_sysfs_upd_tuned_intervals, kdamond);
-- 
2.43.0


Reply via email to