[RFC PATCH 16/18] mm/damon/sysfs-schemes: implement DAMOS tried regions clear command

From: SeongJae Park
Date: Tue Oct 18 2022 - 20:14:29 EST


When there are huge number of DAMON regions that specific scheme actions
are tried to be applied, directories and files under 'tried_regions'
scheme directory could waste some memory. Add another special input
keyword for 'state' file of each kdamond sysfs directory that can be
used for cleanup of the 'tried_regions' sub-directories.

Signed-off-by: SeongJae Park <sj@xxxxxxxxxx>
---
mm/damon/sysfs-common.h | 4 ++++
mm/damon/sysfs-schemes.c | 17 +++++++++++++++++
mm/damon/sysfs.c | 18 ++++++++++++++++++
3 files changed, 39 insertions(+)

diff --git a/mm/damon/sysfs-common.h b/mm/damon/sysfs-common.h
index 634a6e7fca78..604a6cbc3ede 100644
--- a/mm/damon/sysfs-common.h
+++ b/mm/damon/sysfs-common.h
@@ -50,3 +50,7 @@ int damon_sysfs_schemes_update_regions_start(
struct damon_ctx *ctx);

int damon_sysfs_schemes_update_regions_stop(struct damon_ctx *ctx);
+
+int damon_sysfs_schemes_clear_regions(
+ 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 2cea58e49d8d..223de1d06740 100644
--- a/mm/damon/sysfs-schemes.c
+++ b/mm/damon/sysfs-schemes.c
@@ -1262,3 +1262,20 @@ int damon_sysfs_schemes_update_regions_stop(struct damon_ctx *ctx)
damon_sysfs_schemes_region_idx = 0;
return 0;
}
+
+int damon_sysfs_schemes_clear_regions(
+ 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_scheme *sysfs_scheme;
+
+ sysfs_scheme = sysfs_schemes->schemes_arr[schemes_idx++];
+ damon_sysfs_scheme_regions_rm_dirs(
+ sysfs_scheme->tried_regions);
+ }
+ return 0;
+}
diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c
index 6d26ae6052b6..acc16473f6fd 100644
--- a/mm/damon/sysfs.c
+++ b/mm/damon/sysfs.c
@@ -1001,6 +1001,9 @@ enum damon_sysfs_cmd {
DAMON_SYSFS_CMD_UPDATE_SCHEMES_STATS,
/* @DAMON_SYSFS_CMD_UPDATE_SCHEMES_REGIONS: Update scheme regions */
DAMON_SYSFS_CMD_UPDATE_SCHEMES_REGIONS,
+ /* @DAMON_SYSFS_CMD_CLEAR_SCHEMES_REGIONS: Clear scheme regions */
+ DAMON_SYSFS_CMD_CLEAR_SCHEMES_REGIONS,
+
/*
* @NR_DAMON_SYSFS_CMDS: Total number of DAMON sysfs commands.
*/
@@ -1014,6 +1017,7 @@ static const char * const damon_sysfs_cmd_strs[] = {
"commit",
"update_schemes_stats",
"update_schemes_regions",
+ "clear_schemes_regions",
};

/*
@@ -1259,6 +1263,17 @@ static int damon_sysfs_upd_schemes_regions_stop(
return damon_sysfs_schemes_update_regions_stop(ctx);
}

+static int damon_sysfs_clear_schemes_regions(
+ struct damon_sysfs_kdamond *kdamond)
+{
+ struct damon_ctx *ctx = kdamond->damon_ctx;
+
+ if (!ctx)
+ return -EINVAL;
+ return damon_sysfs_schemes_clear_regions(
+ kdamond->contexts->contexts_arr[0]->schemes, ctx);
+}
+
static inline bool damon_sysfs_kdamond_running(
struct damon_sysfs_kdamond *kdamond)
{
@@ -1340,6 +1355,9 @@ static int damon_sysfs_cmd_request_callback(struct damon_ctx *c)
damon_sysfs_schemes_regions_updating = false;
}
break;
+ case DAMON_SYSFS_CMD_CLEAR_SCHEMES_REGIONS:
+ err = damon_sysfs_clear_schemes_regions(kdamond);
+ break;
default:
break;
}
--
2.25.1