linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/8] mm/damon: add sysfs dirs for managing DAMOS filters based on handling layers
@ 2025-02-20 19:46 SeongJae Park
  2025-02-20 19:46 ` [PATCH 1/8] mm/damon/sysfs-schemes: let damon_sysfs_scheme_set_filters() be used for different named directories SeongJae Park
                   ` (8 more replies)
  0 siblings, 9 replies; 11+ messages in thread
From: SeongJae Park @ 2025-02-20 19:46 UTC (permalink / raw)
  Cc: SeongJae Park, Andrew Morton, Jonathan Corbet, damon,
	kernel-team, linux-doc, linux-kernel, linux-mm

DAMOS filters are categorized into two groups based on their handling
layers, namely core and operations layers.  The categorization affects
when each filter is evaluated.  Core layer handled filters are evaluated
first.  The order meant nothing before, but introduction of allow
filters changed that.

DAMOS sysfs interface provides single directory for filters, namely
'filters'.  Users can install any filters in any order there.  DAMON
will internally categorize those into core and operations layer handled
ones, and apply the evaluation order rule.  The ordering rule is clearly
documented.  But the interface could still confuse users since it is
allowed to install filters on the directory in mixed ways.

Add two sysfs directories for managing filters by handling layer, namely
'core_filters' and 'ops_filters' for filters that handled by core and
operations layer, respectively.  Those are avoided to be used for
installing filters that not handled by the assumed layer.

For backward compatibility, keep 'filters' directory with its curernt
behavior.  Filters installed in the directory will be added to DAMON
after those of 'core_filters' and 'ops_filters' directories, with the
automatic categorizations.  Also recommend users to use the new
directories, and noticee 'filters' directory could be deprecated in
future.

Note that new directories provide all features that were provided with
'filters', but just in a more clear way.  Deprecating 'filters' is not
expected to make an irreversal breakge.

Also note that this patch series depend on filters default
behavior change patch series[1].

[1] https://lore.kernel.org/20250220193509.36379-1-sj@kernel.org

SeongJae Park (8):
  mm/damon/sysfs-schemes: let damon_sysfs_scheme_set_filters() be used
    for different named directories
  mm/damon/sysfs-schemes: implement core_filters and ops_filters
    directories
  mm/damon/sysfs-schemes: commit filters in {core,ops}_filters
    directories
  mm/damon/core: expose damos_filter_for_ops() to DAMON kernel API
    callers
  mm/damon/sysfs-schemes: set filters handling layer of directories
  mm/damon/sysfs-schemes: return error for wrong filter type on given
    directory
  Docs/ABI/damon: document {core,ops}_filters directories
  Docs/admin-guide/mm/damon/usage: update for {core,ops}_filters
    directories

 .../ABI/testing/sysfs-kernel-mm-damon         |  16 +++
 Documentation/admin-guide/mm/damon/usage.rst  |  31 +++--
 include/linux/damon.h                         |   1 +
 mm/damon/core.c                               |   9 +-
 mm/damon/sysfs-schemes.c                      | 119 ++++++++++++++++--
 5 files changed, 153 insertions(+), 23 deletions(-)


base-commit: c6ff92c642d665270c718aece87bc33d264d2c00
-- 
2.39.5


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 1/8] mm/damon/sysfs-schemes: let damon_sysfs_scheme_set_filters() be used for different named directories
  2025-02-20 19:46 [PATCH 0/8] mm/damon: add sysfs dirs for managing DAMOS filters based on handling layers SeongJae Park
@ 2025-02-20 19:46 ` SeongJae Park
  2025-02-20 19:46 ` [PATCH 2/8] mm/damon/sysfs-schemes: implement core_filters and ops_filters directories SeongJae Park
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: SeongJae Park @ 2025-02-20 19:46 UTC (permalink / raw)
  Cc: SeongJae Park, Andrew Morton, damon, kernel-team, linux-kernel, linux-mm

damon_sysfs_scheme_set_filters() is using a hard-coded directory name,
"filters".  Refactor for general named directories of same files
hierarchy, to use from upcoming changes.

Signed-off-by: SeongJae Park <sj@kernel.org>
---
 mm/damon/sysfs-schemes.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c
index 66a1c46cee84..541ca5887b24 100644
--- a/mm/damon/sysfs-schemes.c
+++ b/mm/damon/sysfs-schemes.c
@@ -1604,7 +1604,9 @@ static int damon_sysfs_scheme_set_watermarks(struct damon_sysfs_scheme *scheme)
 	return err;
 }
 
-static int damon_sysfs_scheme_set_filters(struct damon_sysfs_scheme *scheme)
+static int damon_sysfs_scheme_set_filters(struct damon_sysfs_scheme *scheme,
+		const char *name,
+		struct damon_sysfs_scheme_filters **filters_ptr)
 {
 	struct damon_sysfs_scheme_filters *filters =
 		damon_sysfs_scheme_filters_alloc();
@@ -1614,11 +1616,11 @@ static int damon_sysfs_scheme_set_filters(struct damon_sysfs_scheme *scheme)
 		return -ENOMEM;
 	err = kobject_init_and_add(&filters->kobj,
 			&damon_sysfs_scheme_filters_ktype, &scheme->kobj,
-			"filters");
+			name);
 	if (err)
 		kobject_put(&filters->kobj);
 	else
-		scheme->filters = filters;
+		*filters_ptr = filters;
 	return err;
 }
 
@@ -1670,7 +1672,8 @@ static int damon_sysfs_scheme_add_dirs(struct damon_sysfs_scheme *scheme)
 	err = damon_sysfs_scheme_set_watermarks(scheme);
 	if (err)
 		goto put_quotas_access_pattern_out;
-	err = damon_sysfs_scheme_set_filters(scheme);
+	err = damon_sysfs_scheme_set_filters(scheme, "filters",
+			&scheme->filters);
 	if (err)
 		goto put_watermarks_quotas_access_pattern_out;
 	err = damon_sysfs_scheme_set_stats(scheme);
-- 
2.39.5


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 2/8] mm/damon/sysfs-schemes: implement core_filters and ops_filters directories
  2025-02-20 19:46 [PATCH 0/8] mm/damon: add sysfs dirs for managing DAMOS filters based on handling layers SeongJae Park
  2025-02-20 19:46 ` [PATCH 1/8] mm/damon/sysfs-schemes: let damon_sysfs_scheme_set_filters() be used for different named directories SeongJae Park
@ 2025-02-20 19:46 ` SeongJae Park
  2025-02-20 19:46 ` [PATCH 3/8] mm/damon/sysfs-schemes: commit filters in {core,ops}_filters directories SeongJae Park
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: SeongJae Park @ 2025-02-20 19:46 UTC (permalink / raw)
  Cc: SeongJae Park, Andrew Morton, damon, kernel-team, linux-kernel, linux-mm

Implement two DAMOS sysfs directories for managing core and operations
layer handled filters separately.  Those are named as 'core_filters' and
'ops_filters', and have files hierarchy same to 'filters'.  This commit
is only populating and cleaning up the directories, not really the files
with DAMON.  Following changes will make the connections.

Signed-off-by: SeongJae Park <sj@kernel.org>
---
 mm/damon/sysfs-schemes.c | 40 ++++++++++++++++++++++++++++++++++++++--
 1 file changed, 38 insertions(+), 2 deletions(-)

diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c
index 541ca5887b24..61ff800ce78d 100644
--- a/mm/damon/sysfs-schemes.c
+++ b/mm/damon/sysfs-schemes.c
@@ -1504,6 +1504,8 @@ struct damon_sysfs_scheme {
 	unsigned long apply_interval_us;
 	struct damon_sysfs_quotas *quotas;
 	struct damon_sysfs_watermarks *watermarks;
+	struct damon_sysfs_scheme_filters *core_filters;
+	struct damon_sysfs_scheme_filters *ops_filters;
 	struct damon_sysfs_scheme_filters *filters;
 	struct damon_sysfs_stats *stats;
 	struct damon_sysfs_scheme_regions *tried_regions;
@@ -1624,6 +1626,33 @@ static int damon_sysfs_scheme_set_filters(struct damon_sysfs_scheme *scheme,
 	return err;
 }
 
+static int damos_sysfs_set_filter_dirs(struct damon_sysfs_scheme *scheme)
+{
+	int err;
+
+	err = damon_sysfs_scheme_set_filters(scheme, "filters",
+			&scheme->filters);
+	if (err)
+		return err;
+	err = damon_sysfs_scheme_set_filters(scheme, "core_filters",
+			&scheme->core_filters);
+	if (err)
+		goto put_filters_out;
+	err = damon_sysfs_scheme_set_filters(scheme, "ops_filters",
+			&scheme->ops_filters);
+	if (err)
+		goto put_core_filters_out;
+	return 0;
+
+put_core_filters_out:
+	kobject_put(&scheme->core_filters->kobj);
+	scheme->core_filters = NULL;
+put_filters_out:
+	kobject_put(&scheme->filters->kobj);
+	scheme->filters = NULL;
+	return err;
+}
+
 static int damon_sysfs_scheme_set_stats(struct damon_sysfs_scheme *scheme)
 {
 	struct damon_sysfs_stats *stats = damon_sysfs_stats_alloc();
@@ -1672,8 +1701,7 @@ static int damon_sysfs_scheme_add_dirs(struct damon_sysfs_scheme *scheme)
 	err = damon_sysfs_scheme_set_watermarks(scheme);
 	if (err)
 		goto put_quotas_access_pattern_out;
-	err = damon_sysfs_scheme_set_filters(scheme, "filters",
-			&scheme->filters);
+	err = damos_sysfs_set_filter_dirs(scheme);
 	if (err)
 		goto put_watermarks_quotas_access_pattern_out;
 	err = damon_sysfs_scheme_set_stats(scheme);
@@ -1688,6 +1716,10 @@ static int damon_sysfs_scheme_add_dirs(struct damon_sysfs_scheme *scheme)
 	kobject_put(&scheme->tried_regions->kobj);
 	scheme->tried_regions = NULL;
 put_filters_watermarks_quotas_access_pattern_out:
+	kobject_put(&scheme->ops_filters->kobj);
+	scheme->ops_filters = NULL;
+	kobject_put(&scheme->core_filters->kobj);
+	scheme->core_filters = NULL;
 	kobject_put(&scheme->filters->kobj);
 	scheme->filters = NULL;
 put_watermarks_quotas_access_pattern_out:
@@ -1711,6 +1743,10 @@ static void damon_sysfs_scheme_rm_dirs(struct damon_sysfs_scheme *scheme)
 	kobject_put(&scheme->watermarks->kobj);
 	damon_sysfs_scheme_filters_rm_dirs(scheme->filters);
 	kobject_put(&scheme->filters->kobj);
+	damon_sysfs_scheme_filters_rm_dirs(scheme->core_filters);
+	kobject_put(&scheme->core_filters->kobj);
+	damon_sysfs_scheme_filters_rm_dirs(scheme->ops_filters);
+	kobject_put(&scheme->ops_filters->kobj);
 	kobject_put(&scheme->stats->kobj);
 	damon_sysfs_scheme_regions_rm_dirs(scheme->tried_regions);
 	kobject_put(&scheme->tried_regions->kobj);
-- 
2.39.5


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 3/8] mm/damon/sysfs-schemes: commit filters in {core,ops}_filters directories
  2025-02-20 19:46 [PATCH 0/8] mm/damon: add sysfs dirs for managing DAMOS filters based on handling layers SeongJae Park
  2025-02-20 19:46 ` [PATCH 1/8] mm/damon/sysfs-schemes: let damon_sysfs_scheme_set_filters() be used for different named directories SeongJae Park
  2025-02-20 19:46 ` [PATCH 2/8] mm/damon/sysfs-schemes: implement core_filters and ops_filters directories SeongJae Park
@ 2025-02-20 19:46 ` SeongJae Park
  2025-02-20 19:46 ` [PATCH 4/8] mm/damon/core: expose damos_filter_for_ops() to DAMON kernel API callers SeongJae Park
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: SeongJae Park @ 2025-02-20 19:46 UTC (permalink / raw)
  Cc: SeongJae Park, Andrew Morton, damon, kernel-team, linux-kernel, linux-mm

Connect user inputs to files under core_filters and ops_filters with
DAMON, so that the files can really function.  Becasuse
{core,ops}_filters are easier to be managed in terms of expecting
filters evaluation order, add filters in {core,ops}_filters before
'filters' directory.

Signed-off-by: SeongJae Park <sj@kernel.org>
---
 mm/damon/sysfs-schemes.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c
index 61ff800ce78d..e85feb329bd6 100644
--- a/mm/damon/sysfs-schemes.c
+++ b/mm/damon/sysfs-schemes.c
@@ -2143,8 +2143,6 @@ static struct damos *damon_sysfs_mk_scheme(
 	struct damon_sysfs_quotas *sysfs_quotas = sysfs_scheme->quotas;
 	struct damon_sysfs_weights *sysfs_weights = sysfs_quotas->weights;
 	struct damon_sysfs_watermarks *sysfs_wmarks = sysfs_scheme->watermarks;
-	struct damon_sysfs_scheme_filters *sysfs_filters =
-		sysfs_scheme->filters;
 	struct damos *scheme;
 	int err;
 
@@ -2184,7 +2182,17 @@ static struct damos *damon_sysfs_mk_scheme(
 		return NULL;
 	}
 
-	err = damon_sysfs_add_scheme_filters(scheme, sysfs_filters);
+	err = damon_sysfs_add_scheme_filters(scheme, sysfs_scheme->core_filters);
+	if (err) {
+		damon_destroy_scheme(scheme);
+		return NULL;
+	}
+	err = damon_sysfs_add_scheme_filters(scheme, sysfs_scheme->ops_filters);
+	if (err) {
+		damon_destroy_scheme(scheme);
+		return NULL;
+	}
+	err = damon_sysfs_add_scheme_filters(scheme, sysfs_scheme->filters);
 	if (err) {
 		damon_destroy_scheme(scheme);
 		return NULL;
-- 
2.39.5


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 4/8] mm/damon/core: expose damos_filter_for_ops() to DAMON kernel API callers
  2025-02-20 19:46 [PATCH 0/8] mm/damon: add sysfs dirs for managing DAMOS filters based on handling layers SeongJae Park
                   ` (2 preceding siblings ...)
  2025-02-20 19:46 ` [PATCH 3/8] mm/damon/sysfs-schemes: commit filters in {core,ops}_filters directories SeongJae Park
@ 2025-02-20 19:46 ` SeongJae Park
  2025-02-20 19:46 ` [PATCH 5/8] mm/damon/sysfs-schemes: set filters handling layer of directories SeongJae Park
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: SeongJae Park @ 2025-02-20 19:46 UTC (permalink / raw)
  Cc: SeongJae Park, Andrew Morton, damon, kernel-team, linux-kernel, linux-mm

damos_filter_for_ops() can be useful to avoid putting wrong type of
filters in wrong place.  Make it be exposed to DAMON kernel API callers.

Signed-off-by: SeongJae Park <sj@kernel.org>
---
 include/linux/damon.h | 1 +
 mm/damon/core.c       | 9 ++++++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/include/linux/damon.h b/include/linux/damon.h
index 1d8479f57f85..085f26a2e702 100644
--- a/include/linux/damon.h
+++ b/include/linux/damon.h
@@ -846,6 +846,7 @@ void damon_update_region_access_rate(struct damon_region *r, bool accessed,
 struct damos_filter *damos_new_filter(enum damos_filter_type type,
 		bool matching, bool allow);
 void damos_add_filter(struct damos *s, struct damos_filter *f);
+bool damos_filter_for_ops(enum damos_filter_type type);
 void damos_destroy_filter(struct damos_filter *f);
 
 struct damos_quota_goal *damos_new_quota_goal(
diff --git a/mm/damon/core.c b/mm/damon/core.c
index 9744ab9ca5c5..273c91e6df86 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -281,7 +281,14 @@ struct damos_filter *damos_new_filter(enum damos_filter_type type,
 	return filter;
 }
 
-static bool damos_filter_for_ops(enum damos_filter_type type)
+/**
+ * damos_filter_for_ops() - Return if the filter is ops-hndled one.
+ * @type:	type of the filter.
+ *
+ * Return: true if the filter of @type needs to be handled by ops layer, false
+ * otherwise.
+ */
+bool damos_filter_for_ops(enum damos_filter_type type)
 {
 	switch (type) {
 	case DAMOS_FILTER_TYPE_ADDR:
-- 
2.39.5


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 5/8] mm/damon/sysfs-schemes: set filters handling layer of directories
  2025-02-20 19:46 [PATCH 0/8] mm/damon: add sysfs dirs for managing DAMOS filters based on handling layers SeongJae Park
                   ` (3 preceding siblings ...)
  2025-02-20 19:46 ` [PATCH 4/8] mm/damon/core: expose damos_filter_for_ops() to DAMON kernel API callers SeongJae Park
@ 2025-02-20 19:46 ` SeongJae Park
  2025-02-20 19:46 ` [PATCH 6/8] mm/damon/sysfs-schemes: return error for wrong filter type on given directory SeongJae Park
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: SeongJae Park @ 2025-02-20 19:46 UTC (permalink / raw)
  Cc: SeongJae Park, Andrew Morton, damon, kernel-team, linux-kernel, linux-mm

Unlike their name and assumed purposes, {core,ops}_filters DAMOS sysfs
directories are allowing installing any type of filters.  To restrict
wrong type of filters to the directories, first add information about
filters that handled by what layer should the filters allow installing
to DAMOS sysfs internal data structures.

Signed-off-by: SeongJae Park <sj@kernel.org>
---
 mm/damon/sysfs-schemes.c | 46 +++++++++++++++++++++++++++++++---------
 1 file changed, 36 insertions(+), 10 deletions(-)

diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c
index e85feb329bd6..b9f035f4b00f 100644
--- a/mm/damon/sysfs-schemes.c
+++ b/mm/damon/sysfs-schemes.c
@@ -309,8 +309,18 @@ static const struct kobj_type damon_sysfs_stats_ktype = {
  * filter directory
  */
 
+/*
+ * enum damos_sysfs_filter_handle_layer - Layers handling filters of a dir.
+ */
+enum damos_sysfs_filter_handle_layer {
+	DAMOS_SYSFS_FILTER_HANDLE_LAYER_CORE,
+	DAMOS_SYSFS_FILTER_HANDLE_LAYER_OPS,
+	DAMOS_SYSFS_FILTER_HANDLE_LAYER_BOTH,
+};
+
 struct damon_sysfs_scheme_filter {
 	struct kobject kobj;
+	enum damos_sysfs_filter_handle_layer handle_layer;
 	enum damos_filter_type type;
 	bool matching;
 	bool allow;
@@ -320,9 +330,15 @@ struct damon_sysfs_scheme_filter {
 	int target_idx;
 };
 
-static struct damon_sysfs_scheme_filter *damon_sysfs_scheme_filter_alloc(void)
+static struct damon_sysfs_scheme_filter *damon_sysfs_scheme_filter_alloc(
+		enum damos_sysfs_filter_handle_layer layer)
 {
-	return kzalloc(sizeof(struct damon_sysfs_scheme_filter), GFP_KERNEL);
+	struct damon_sysfs_scheme_filter *filter;
+
+	filter = kzalloc(sizeof(struct damon_sysfs_scheme_filter), GFP_KERNEL);
+	if (filter)
+		filter->handle_layer = layer;
+	return filter;
 }
 
 /* Should match with enum damos_filter_type */
@@ -595,14 +611,20 @@ static const struct kobj_type damon_sysfs_scheme_filter_ktype = {
 
 struct damon_sysfs_scheme_filters {
 	struct kobject kobj;
+	enum damos_sysfs_filter_handle_layer handle_layer;
 	struct damon_sysfs_scheme_filter **filters_arr;
 	int nr;
 };
 
 static struct damon_sysfs_scheme_filters *
-damon_sysfs_scheme_filters_alloc(void)
+damon_sysfs_scheme_filters_alloc(enum damos_sysfs_filter_handle_layer layer)
 {
-	return kzalloc(sizeof(struct damon_sysfs_scheme_filters), GFP_KERNEL);
+	struct damon_sysfs_scheme_filters *filters;
+
+	filters = kzalloc(sizeof(struct damon_sysfs_scheme_filters), GFP_KERNEL);
+	if (filters)
+		filters->handle_layer = layer;
+	return filters;
 }
 
 static void damon_sysfs_scheme_filters_rm_dirs(
@@ -635,7 +657,8 @@ static int damon_sysfs_scheme_filters_add_dirs(
 	filters->filters_arr = filters_arr;
 
 	for (i = 0; i < nr_filters; i++) {
-		filter = damon_sysfs_scheme_filter_alloc();
+		filter = damon_sysfs_scheme_filter_alloc(
+				filters->handle_layer);
 		if (!filter) {
 			damon_sysfs_scheme_filters_rm_dirs(filters);
 			return -ENOMEM;
@@ -1607,11 +1630,11 @@ static int damon_sysfs_scheme_set_watermarks(struct damon_sysfs_scheme *scheme)
 }
 
 static int damon_sysfs_scheme_set_filters(struct damon_sysfs_scheme *scheme,
-		const char *name,
+		enum damos_sysfs_filter_handle_layer layer, const char *name,
 		struct damon_sysfs_scheme_filters **filters_ptr)
 {
 	struct damon_sysfs_scheme_filters *filters =
-		damon_sysfs_scheme_filters_alloc();
+		damon_sysfs_scheme_filters_alloc(layer);
 	int err;
 
 	if (!filters)
@@ -1630,15 +1653,18 @@ static int damos_sysfs_set_filter_dirs(struct damon_sysfs_scheme *scheme)
 {
 	int err;
 
-	err = damon_sysfs_scheme_set_filters(scheme, "filters",
+	err = damon_sysfs_scheme_set_filters(scheme,
+			DAMOS_SYSFS_FILTER_HANDLE_LAYER_BOTH, "filters",
 			&scheme->filters);
 	if (err)
 		return err;
-	err = damon_sysfs_scheme_set_filters(scheme, "core_filters",
+	err = damon_sysfs_scheme_set_filters(scheme,
+			DAMOS_SYSFS_FILTER_HANDLE_LAYER_CORE, "core_filters",
 			&scheme->core_filters);
 	if (err)
 		goto put_filters_out;
-	err = damon_sysfs_scheme_set_filters(scheme, "ops_filters",
+	err = damon_sysfs_scheme_set_filters(scheme,
+			DAMOS_SYSFS_FILTER_HANDLE_LAYER_OPS, "ops_filters",
 			&scheme->ops_filters);
 	if (err)
 		goto put_core_filters_out;
-- 
2.39.5


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 6/8] mm/damon/sysfs-schemes: return error for wrong filter type on given directory
  2025-02-20 19:46 [PATCH 0/8] mm/damon: add sysfs dirs for managing DAMOS filters based on handling layers SeongJae Park
                   ` (4 preceding siblings ...)
  2025-02-20 19:46 ` [PATCH 5/8] mm/damon/sysfs-schemes: set filters handling layer of directories SeongJae Park
@ 2025-02-20 19:46 ` SeongJae Park
  2025-02-20 19:46 ` [PATCH 7/8] Docs/ABI/damon: document {core,ops}_filters directories SeongJae Park
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: SeongJae Park @ 2025-02-20 19:46 UTC (permalink / raw)
  Cc: SeongJae Park, Andrew Morton, damon, kernel-team, linux-kernel, linux-mm

Return error if the user tries to install a DAMOS filter on DAMOS
filters sysfs directory that assumed to be used for filters that handled
by a DAMON layer that not same to that for the installing filter.

Signed-off-by: SeongJae Park <sj@kernel.org>
---
 mm/damon/sysfs-schemes.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c
index b9f035f4b00f..ed834622df2a 100644
--- a/mm/damon/sysfs-schemes.c
+++ b/mm/damon/sysfs-schemes.c
@@ -362,6 +362,23 @@ static ssize_t type_show(struct kobject *kobj,
 			damon_sysfs_scheme_filter_type_strs[filter->type]);
 }
 
+static bool damos_sysfs_scheme_filter_valid_type(
+		enum damos_sysfs_filter_handle_layer layer,
+		enum damos_filter_type type)
+{
+	switch (layer) {
+	case DAMOS_SYSFS_FILTER_HANDLE_LAYER_BOTH:
+		return true;
+	case DAMOS_SYSFS_FILTER_HANDLE_LAYER_CORE:
+		return !damos_filter_for_ops(type);
+	case DAMOS_SYSFS_FILTER_HANDLE_LAYER_OPS:
+		return damos_filter_for_ops(type);
+	default:
+		break;
+	}
+	return false;
+}
+
 static ssize_t type_store(struct kobject *kobj,
 		struct kobj_attribute *attr, const char *buf, size_t count)
 {
@@ -373,6 +390,9 @@ static ssize_t type_store(struct kobject *kobj,
 	for (type = 0; type < NR_DAMOS_FILTER_TYPES; type++) {
 		if (sysfs_streq(buf, damon_sysfs_scheme_filter_type_strs[
 					type])) {
+			if (!damos_sysfs_scheme_filter_valid_type(
+						filter->handle_layer, type))
+				break;
 			filter->type = type;
 			ret = count;
 			break;
-- 
2.39.5


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 7/8] Docs/ABI/damon: document {core,ops}_filters directories
  2025-02-20 19:46 [PATCH 0/8] mm/damon: add sysfs dirs for managing DAMOS filters based on handling layers SeongJae Park
                   ` (5 preceding siblings ...)
  2025-02-20 19:46 ` [PATCH 6/8] mm/damon/sysfs-schemes: return error for wrong filter type on given directory SeongJae Park
@ 2025-02-20 19:46 ` SeongJae Park
  2025-02-20 19:46 ` [PATCH 8/8] Docs/admin-guide/mm/damon/usage: update for " SeongJae Park
  2025-02-20 22:14 ` [PATCH 0/8] mm/damon: add sysfs dirs for managing DAMOS filters based on handling layers SeongJae Park
  8 siblings, 0 replies; 11+ messages in thread
From: SeongJae Park @ 2025-02-20 19:46 UTC (permalink / raw)
  Cc: SeongJae Park, Andrew Morton, damon, kernel-team, linux-kernel, linux-mm

Document the new DAMOS filters sysfs directories on ABI doc.

Signed-off-by: SeongJae Park <sj@kernel.org>
---
 Documentation/ABI/testing/sysfs-kernel-mm-damon | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-kernel-mm-damon b/Documentation/ABI/testing/sysfs-kernel-mm-damon
index ccd13ca668c8..9666074f06f3 100644
--- a/Documentation/ABI/testing/sysfs-kernel-mm-damon
+++ b/Documentation/ABI/testing/sysfs-kernel-mm-damon
@@ -379,6 +379,22 @@ Description:	Writing 'Y' or 'N' to this file sets whether to allow or reject
 		applying the scheme's action to the memory that satisfies the
 		'type' and the 'matching' of the directory.
 
+What:		/sys/kernel/mm/damon/admin/kdamonds/<K>/contexts/<C>/schemes/<S>/core_filters
+Date:		Feb 2025
+Contact:	SeongJae Park <sj@kernel.org>
+Description:	Directory for DAMON core layer-handled DAMOS filters.  Files
+		under this directory works same to those of
+		/sys/kernel/mm/damon/admin/kdamonds/<K>/contexts/<C>/schemes/<S>/filters
+		directory.
+
+What:		/sys/kernel/mm/damon/admin/kdamonds/<K>/contexts/<C>/schemes/<S>/ops_filters
+Date:		Feb 2025
+Contact:	SeongJae Park <sj@kernel.org>
+Description:	Directory for DAMON operations set layer-handled DAMOS filters.
+		Files under this directory works same to those of
+		/sys/kernel/mm/damon/admin/kdamonds/<K>/contexts/<C>/schemes/<S>/filters
+		directory.
+
 What:		/sys/kernel/mm/damon/admin/kdamonds/<K>/contexts/<C>/schemes/<S>/stats/nr_tried
 Date:		Mar 2022
 Contact:	SeongJae Park <sj@kernel.org>
-- 
2.39.5


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 8/8] Docs/admin-guide/mm/damon/usage: update for {core,ops}_filters directories
  2025-02-20 19:46 [PATCH 0/8] mm/damon: add sysfs dirs for managing DAMOS filters based on handling layers SeongJae Park
                   ` (6 preceding siblings ...)
  2025-02-20 19:46 ` [PATCH 7/8] Docs/ABI/damon: document {core,ops}_filters directories SeongJae Park
@ 2025-02-20 19:46 ` SeongJae Park
  2025-03-05 22:23   ` SeongJae Park
  2025-02-20 22:14 ` [PATCH 0/8] mm/damon: add sysfs dirs for managing DAMOS filters based on handling layers SeongJae Park
  8 siblings, 1 reply; 11+ messages in thread
From: SeongJae Park @ 2025-02-20 19:46 UTC (permalink / raw)
  Cc: SeongJae Park, Andrew Morton, Jonathan Corbet, damon,
	kernel-team, linux-doc, linux-kernel, linux-mm

Document {core,ops}_filters directories on usage document.

Signed-off-by: SeongJae Park <sj@kernel.org>
---
 Documentation/admin-guide/mm/damon/usage.rst | 31 ++++++++++++++------
 1 file changed, 22 insertions(+), 9 deletions(-)

diff --git a/Documentation/admin-guide/mm/damon/usage.rst b/Documentation/admin-guide/mm/damon/usage.rst
index dc37bba96273..4b25c25d4f4f 100644
--- a/Documentation/admin-guide/mm/damon/usage.rst
+++ b/Documentation/admin-guide/mm/damon/usage.rst
@@ -82,7 +82,7 @@ comma (",").
     │ │ │ │ │ │ │ │ :ref:`goals <sysfs_schemes_quota_goals>`/nr_goals
     │ │ │ │ │ │ │ │ │ 0/target_metric,target_value,current_value
     │ │ │ │ │ │ │ :ref:`watermarks <sysfs_watermarks>`/metric,interval_us,high,mid,low
-    │ │ │ │ │ │ │ :ref:`filters <sysfs_filters>`/nr_filters
+    │ │ │ │ │ │ │ :ref:`{core_,ops_,}filters <sysfs_filters>`/nr_filters
     │ │ │ │ │ │ │ │ 0/type,matching,allow,memcg_path,addr_start,addr_end,target_idx,min,max
     │ │ │ │ │ │ │ :ref:`stats <sysfs_schemes_stats>`/nr_tried,sz_tried,nr_applied,sz_applied,sz_ops_filter_passed,qt_exceeds
     │ │ │ │ │ │ │ :ref:`tried_regions <sysfs_schemes_tried_regions>`/total_bytes
@@ -282,9 +282,10 @@ to ``N-1``.  Each directory represents each DAMON-based operation scheme.
 schemes/<N>/
 ------------
 
-In each scheme directory, five directories (``access_pattern``, ``quotas``,
-``watermarks``, ``filters``, ``stats``, and ``tried_regions``) and three files
-(``action``, ``target_nid`` and ``apply_interval``) exist.
+In each scheme directory, seven directories (``access_pattern``, ``quotas``,
+``watermarks``, ``core_filters``, ``ops_filters``, ``filters``, ``stats``, and
+``tried_regions``) and three files (``action``, ``target_nid`` and
+``apply_interval``) exist.
 
 The ``action`` file is for setting and getting the scheme's :ref:`action
 <damon_design_damos_action>`.  The keywords that can be written to and read
@@ -395,13 +396,24 @@ The ``interval`` should written in microseconds unit.
 
 .. _sysfs_filters:
 
-schemes/<N>/filters/
---------------------
+schemes/<N>/{core_,ops_,}filters/
+-------------------------------
 
-The directory for the :ref:`filters <damon_design_damos_filters>` of the given
+Directories for :ref:`filters <damon_design_damos_filters>` of the given
 DAMON-based operation scheme.
 
-In the beginning, this directory has only one file, ``nr_filters``.  Writing a
+``core_filters`` and ``ops_filters`` directories are for the filters handled by
+the DAMON core layer and operations set layer, respectively.  ``filters``
+directory can be used for installing filters regardless of their handled
+layers.  Filters that requested by ``core_filters`` and ``ops_filters`` will be
+installed before those of ``filters``.  All three directories have same files.
+
+Use of ``filters`` directory can make expecting evaluation orders of given
+filters with the files under directory bit confusing.  Users are hence
+recommended to use ``core_filters`` and ``ops_filters`` directories.  The
+``filters`` directory could be deprecated in future.
+
+In the beginning, the directory has only one file, ``nr_filters``.  Writing a
 number (``N``) to the file creates the number of child directories named ``0``
 to ``N-1``.  Each directory represents each filter.  The filters are evaluated
 in the numeric order.
@@ -410,7 +422,7 @@ Each filter directory contains nine files, namely ``type``, ``matching``,
 ``allow``, ``memcg_path``, ``addr_start``, ``addr_end``, ``min``, ``max``
 and ``target_idx``.  To ``type`` file, you can write the type of the filter.
 Refer to :ref:`the design doc <damon_design_damos_filters>` for available type
-names and their meanings.
+names, their meaning and on what layer those are handled.
 
 For ``memcg`` type, you can specify the memory cgroup of the interest by
 writing the path of the memory cgroup from the cgroups mount point to
@@ -430,6 +442,7 @@ the ``type`` and ``matching`` should be allowed or not.
 For example, below restricts a DAMOS action to be applied to only non-anonymous
 pages of all memory cgroups except ``/having_care_already``.::
 
+    # cd ops_filters/0/
     # echo 2 > nr_filters
     # # disallow anonymous pages
     echo anon > 0/type
-- 
2.39.5


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 0/8] mm/damon: add sysfs dirs for managing DAMOS filters based on handling layers
  2025-02-20 19:46 [PATCH 0/8] mm/damon: add sysfs dirs for managing DAMOS filters based on handling layers SeongJae Park
                   ` (7 preceding siblings ...)
  2025-02-20 19:46 ` [PATCH 8/8] Docs/admin-guide/mm/damon/usage: update for " SeongJae Park
@ 2025-02-20 22:14 ` SeongJae Park
  8 siblings, 0 replies; 11+ messages in thread
From: SeongJae Park @ 2025-02-20 22:14 UTC (permalink / raw)
  To: SeongJae Park
  Cc: Andrew Morton, Jonathan Corbet, damon, kernel-team, linux-doc,
	linux-kernel, linux-mm

[...]
> Also note that this patch series depend on filters default
> behavior change patch series[1].
> 
> [1] https://lore.kernel.org/20250220193509.36379-1-sj@kernel.org

This is an RFC that depends on another RFC patch series I listed above.  But I
made yet another mistake on the subject.  Sorry if it made any confusion.


Thanks,
SJ

[...]


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 8/8] Docs/admin-guide/mm/damon/usage: update for {core,ops}_filters directories
  2025-02-20 19:46 ` [PATCH 8/8] Docs/admin-guide/mm/damon/usage: update for " SeongJae Park
@ 2025-03-05 22:23   ` SeongJae Park
  0 siblings, 0 replies; 11+ messages in thread
From: SeongJae Park @ 2025-03-05 22:23 UTC (permalink / raw)
  To: SeongJae Park
  Cc: Andrew Morton, Jonathan Corbet, damon, kernel-team, linux-doc,
	linux-kernel, linux-mm

On Thu, 20 Feb 2025 11:46:46 -0800 SeongJae Park <sj@kernel.org> wrote:

> Document {core,ops}_filters directories on usage document.
> 
> Signed-off-by: SeongJae Park <sj@kernel.org>
> ---
>  Documentation/admin-guide/mm/damon/usage.rst | 31 ++++++++++++++------
>  1 file changed, 22 insertions(+), 9 deletions(-)
> 
> diff --git a/Documentation/admin-guide/mm/damon/usage.rst b/Documentation/admin-guide/mm/damon/usage.rst
> index dc37bba96273..4b25c25d4f4f 100644
> --- a/Documentation/admin-guide/mm/damon/usage.rst
> +++ b/Documentation/admin-guide/mm/damon/usage.rst
> @@ -82,7 +82,7 @@ comma (",").
>      │ │ │ │ │ │ │ │ :ref:`goals <sysfs_schemes_quota_goals>`/nr_goals
>      │ │ │ │ │ │ │ │ │ 0/target_metric,target_value,current_value
>      │ │ │ │ │ │ │ :ref:`watermarks <sysfs_watermarks>`/metric,interval_us,high,mid,low
> -    │ │ │ │ │ │ │ :ref:`filters <sysfs_filters>`/nr_filters
> +    │ │ │ │ │ │ │ :ref:`{core_,ops_,}filters <sysfs_filters>`/nr_filters
>      │ │ │ │ │ │ │ │ 0/type,matching,allow,memcg_path,addr_start,addr_end,target_idx,min,max
>      │ │ │ │ │ │ │ :ref:`stats <sysfs_schemes_stats>`/nr_tried,sz_tried,nr_applied,sz_applied,sz_ops_filter_passed,qt_exceeds
>      │ │ │ │ │ │ │ :ref:`tried_regions <sysfs_schemes_tried_regions>`/total_bytes
> @@ -282,9 +282,10 @@ to ``N-1``.  Each directory represents each DAMON-based operation scheme.
>  schemes/<N>/
>  ------------
>  
> -In each scheme directory, five directories (``access_pattern``, ``quotas``,
> -``watermarks``, ``filters``, ``stats``, and ``tried_regions``) and three files
> -(``action``, ``target_nid`` and ``apply_interval``) exist.
> +In each scheme directory, seven directories (``access_pattern``, ``quotas``,
> +``watermarks``, ``core_filters``, ``ops_filters``, ``filters``, ``stats``, and
> +``tried_regions``) and three files (``action``, ``target_nid`` and
> +``apply_interval``) exist.
>  
>  The ``action`` file is for setting and getting the scheme's :ref:`action
>  <damon_design_damos_action>`.  The keywords that can be written to and read
> @@ -395,13 +396,24 @@ The ``interval`` should written in microseconds unit.
>  
>  .. _sysfs_filters:
>  
> -schemes/<N>/filters/
> ---------------------
> +schemes/<N>/{core_,ops_,}filters/
> +-------------------------------

Just found this causes below document build warning and error during 'make
htmldocs':

    Documentation/admin-guide/mm/damon/usage.rst:425: WARNING: Title underline too short.
    Documentation/admin-guide/mm/damon/usage.rst:425: ERROR: Unknown target name: "core".

I will fix this in the next spin as below.

    -schemes/<N>/{core_,ops_,}filters/
    --------------------------------
    +schemes/<N>/{core\_,ops\_,}filters/
    +-----------------------------------


Thanks,
SJ

[...]


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2025-03-05 22:24 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-20 19:46 [PATCH 0/8] mm/damon: add sysfs dirs for managing DAMOS filters based on handling layers SeongJae Park
2025-02-20 19:46 ` [PATCH 1/8] mm/damon/sysfs-schemes: let damon_sysfs_scheme_set_filters() be used for different named directories SeongJae Park
2025-02-20 19:46 ` [PATCH 2/8] mm/damon/sysfs-schemes: implement core_filters and ops_filters directories SeongJae Park
2025-02-20 19:46 ` [PATCH 3/8] mm/damon/sysfs-schemes: commit filters in {core,ops}_filters directories SeongJae Park
2025-02-20 19:46 ` [PATCH 4/8] mm/damon/core: expose damos_filter_for_ops() to DAMON kernel API callers SeongJae Park
2025-02-20 19:46 ` [PATCH 5/8] mm/damon/sysfs-schemes: set filters handling layer of directories SeongJae Park
2025-02-20 19:46 ` [PATCH 6/8] mm/damon/sysfs-schemes: return error for wrong filter type on given directory SeongJae Park
2025-02-20 19:46 ` [PATCH 7/8] Docs/ABI/damon: document {core,ops}_filters directories SeongJae Park
2025-02-20 19:46 ` [PATCH 8/8] Docs/admin-guide/mm/damon/usage: update for " SeongJae Park
2025-03-05 22:23   ` SeongJae Park
2025-02-20 22:14 ` [PATCH 0/8] mm/damon: add sysfs dirs for managing DAMOS filters based on handling layers SeongJae Park

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox