All of lore.kernel.org
 help / color / mirror / Atom feed
From: SeongJae Park <sj@kernel.org>
To: SeongJae Park <sj@kernel.org>, Andrew Morton <akpm@linux-foundation.org>
Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: [RFC PATCH 16/18] mm/damon/sysfs-schemes: implement DAMOS tried regions clear command
Date: Wed, 19 Oct 2022 00:13:15 +0000	[thread overview]
Message-ID: <20221019001317.104270-17-sj@kernel.org> (raw)
In-Reply-To: <20221019001317.104270-1-sj@kernel.org>

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@kernel.org>
---
 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


  parent reply	other threads:[~2022-10-19  0:13 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-19  0:12 [RFC PATCH 00/18] efficiently expose damos action tried regions information SeongJae Park
2022-10-19  0:13 ` [RFC PATCH 01/18] mm/damon/modules: deduplicate init steps for DAMON context setup SeongJae Park
2022-10-19  0:13 ` [RFC PATCH 02/18] mm/damon/core: split out DAMOS-charged region skip logic into a new function SeongJae Park
2022-10-19  0:13 ` [RFC PATCH 03/18] mm/damon/core: split damos application " SeongJae Park
2022-10-19  0:13 ` [RFC PATCH 04/18] mm/damon/core: split out scheme stat update " SeongJae Park
2022-10-19  0:13 ` [RFC PATCH 05/18] mm/damon/core: split out scheme quota adjustment " SeongJae Park
2022-10-19  0:13 ` [RFC PATCH 06/18] mm/damon/core: add a DAMON callback for scheme target regions check SeongJae Park
2022-10-19  0:13 ` [RFC PATCH 07/18] mm/damon/sysfs: Use damon_addr_range for regions' start and end values SeongJae Park
2022-10-19  0:13 ` [RFC PATCH 08/18] mm/damon/sysfs: remove parameters of damon_sysfs_region_alloc() SeongJae Park
2022-10-19  0:13 ` [RFC PATCH 09/18] mm/damon/sysfs: move sysfs_lock to common module SeongJae Park
2022-10-19  0:13 ` [RFC PATCH 10/18] mm/damon/sysfs: move unsigned long range directory " SeongJae Park
2022-10-19  0:13 ` [RFC PATCH 11/18] mm/damon/sysfs: split out kdamond-independent schemes stats update logic into a new function SeongJae Park
2022-10-19  0:13 ` [RFC PATCH 12/18] mm/damon/sysfs: move schemes directory implementation to separate module SeongJae Park
2022-10-19  0:13 ` [RFC PATCH 13/18] mm/damon/sysfs-schemes: implement schemes/tried_regions directory SeongJae Park
2022-10-19  0:13 ` [RFC PATCH 14/18] mm/damon/sysfs-schemes: implement scheme region directory SeongJae Park
2022-10-19  0:13 ` [RFC PATCH 15/18] mm/damon/sysfs: implement DAMOS-tried regions update command SeongJae Park
2022-10-19  0:13 ` SeongJae Park [this message]
2022-10-19  0:13 ` [RFC PATCH 17/18] Docs/admin-guide/mm/damon/usage: document schemes/<s>/tried_regions directory SeongJae Park
2022-10-19  0:13 ` [RFC PATCH 18/18] Docs/ABI/damon: document 'schemes/<s>/tried_regions' directory SeongJae Park
2022-10-19 17:32 ` [RFC PATCH 00/18] efficiently expose damos action tried regions information SeongJae Park

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221019001317.104270-17-sj@kernel.org \
    --to=sj@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=damon@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.