]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
mm/damon/sysfs: implement a kdamond command for updating schemes' effective quotas
authorSeongJae Park <sj@kernel.org>
Mon, 19 Feb 2024 19:44:14 +0000 (11:44 -0800)
committerAndrew Morton <akpm@linux-foundation.org>
Sat, 24 Feb 2024 01:48:26 +0000 (17:48 -0800)
Implement yet another kdamond 'state' file input command, namely
'update_schemes_effective_quotas'.  If it is written, the
'effective_bytes' files of the kdamond will be updated to provide the
current effective size quota of each scheme in bytes.

Link: https://lkml.kernel.org/r/20240219194431.159606-4-sj@kernel.org
Signed-off-by: SeongJae Park <sj@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/damon/sysfs-common.h
mm/damon/sysfs-schemes.c
mm/damon/sysfs.c

index ec0703e1e90b699e27805053cea2ceef7693bc57..5a1ac15fb2f8b73802b6fd3f748556ea603478ee 100644 (file)
@@ -61,3 +61,7 @@ int damon_sysfs_schemes_clear_regions(
 
 void damos_sysfs_set_quota_scores(struct damon_sysfs_schemes *sysfs_schemes,
                struct damon_ctx *ctx);
+
+void damos_sysfs_update_effective_quotas(
+               struct damon_sysfs_schemes *sysfs_schemes,
+               struct damon_ctx *ctx);
index dd46b2db5455af41296a633a3f96e300d9d55a3b..9d90e7b757b7653757619fb9dd878a90a635be7e 100644 (file)
@@ -1930,6 +1930,26 @@ void 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)
+{
+       struct damos *scheme;
+       int schemes_idx = 0;
+
+       damon_for_each_scheme(scheme, ctx) {
+               struct damon_sysfs_quotas *sysfs_quotas;
+
+               /* user could have removed the scheme sysfs dir */
+               if (schemes_idx >= sysfs_schemes->nr)
+                       break;
+
+               sysfs_quotas =
+                       sysfs_schemes->schemes_arr[schemes_idx++]->quotas;
+               sysfs_quotas->effective_sz = scheme->quota.esz;
+       }
+}
+
 static struct damos *damon_sysfs_mk_scheme(
                struct damon_sysfs_scheme *sysfs_scheme)
 {
index 678de97fcc888d42f6930c32baf77638121d75ce..cc2d88a901f45f90a446847111bf3116329e955f 100644 (file)
@@ -1019,6 +1019,11 @@ enum damon_sysfs_cmd {
         * regions
         */
        DAMON_SYSFS_CMD_CLEAR_SCHEMES_TRIED_REGIONS,
+       /*
+        * @DAMON_SYSFS_CMD_UPDATE_SCHEMES_EFFECTIVE_QUOTAS: Update the
+        * effective size quota of the scheme in bytes.
+        */
+       DAMON_SYSFS_CMD_UPDATE_SCHEMES_EFFECTIVE_QUOTAS,
        /*
         * @NR_DAMON_SYSFS_CMDS: Total number of DAMON sysfs commands.
         */
@@ -1035,6 +1040,7 @@ static const char * const damon_sysfs_cmd_strs[] = {
        "update_schemes_tried_bytes",
        "update_schemes_tried_regions",
        "clear_schemes_tried_regions",
+       "update_schemes_effective_quotas",
 };
 
 /*
@@ -1375,6 +1381,29 @@ static int damon_sysfs_commit_schemes_quota_goals(
        return 0;
 }
 
+/*
+ * damon_sysfs_upd_schemes_effective_quotas() - Update schemes effective quotas
+ * sysfs files.
+ * @kdamond:   The kobject wrapper that associated to the kdamond thread.
+ *
+ * This function reads the schemes' effective quotas of specific kdamond and
+ * update the related values for sysfs files.  This function should be called
+ * from DAMON callbacks while holding ``damon_syfs_lock``, to safely access the
+ * DAMON contexts-internal data and DAMON sysfs variables.
+ */
+static int damon_sysfs_upd_schemes_effective_quotas(
+               struct damon_sysfs_kdamond *kdamond)
+{
+       struct damon_ctx *ctx = kdamond->damon_ctx;
+
+       if (!ctx)
+               return -EINVAL;
+       damos_sysfs_update_effective_quotas(
+                       kdamond->contexts->contexts_arr[0]->schemes, ctx);
+       return 0;
+}
+
+
 /*
  * damon_sysfs_cmd_request_callback() - DAMON callback for handling requests.
  * @c:         The DAMON context of the callback.
@@ -1437,6 +1466,9 @@ static int damon_sysfs_cmd_request_callback(struct damon_ctx *c, bool active,
        case DAMON_SYSFS_CMD_CLEAR_SCHEMES_TRIED_REGIONS:
                err = damon_sysfs_clear_schemes_regions(kdamond);
                break;
+       case DAMON_SYSFS_CMD_UPDATE_SCHEMES_EFFECTIVE_QUOTAS:
+               err = damon_sysfs_upd_schemes_effective_quotas(kdamond);
+               break;
        default:
                break;
        }