* [RFC PATCH v2 0/9] mm/damon: make allow filters after reject filters useful and intuitive
@ 2025-02-27 1:57 SeongJae Park
2025-02-27 1:57 ` [RFC PATCH v2 1/9] mm/damon/core: introduce damos->ops_filters SeongJae Park
` (8 more replies)
0 siblings, 9 replies; 12+ messages in thread
From: SeongJae Park @ 2025-02-27 1:57 UTC (permalink / raw)
Cc: SeongJae Park, Andrew Morton, Jonathan Corbet, damon, kernel-team,
linux-doc, linux-kernel, linux-mm
DAMOS filters do allow or reject elements of memory for given DAMOS
scheme only if those match the filter criterias. For elements that
don't match any DAMOS filter, 'allowing' is the default behavior. This
makes allow-filters that don't have any reject-filter after them
meaningless sources of overhead. The decision was made to keep the
behavior consistent with that before the introduction of allow-filters.
This, however, makes usage of DAMOS filters confusing and inefficient.
There is an apparently more intuitive behavior for the case. If there
is no filter at all or the last filter is a reject filter, allowing by
default.
Update the filtering logic to work in the way. Decide the default
behavior as the opposite of the last isntalled filter. If it is an
allow filter, reject by default. If it is a reject filter or no filter
is installed at all, allow by default.
Note that this is changing the old behavior. But the old behavior for
the problematic filter combination was definitely confusing, inefficient
and anyway useless. Also, the behavior has relatively recently
introduced. It is difficult to anticipate any user that depends on the
behavior. Hence this is not a user-breaking behavior change but an
obvious improvement.
Changes from RFC v1
(https://lore.kernel.org/20250220193509.36379-1-sj@kernel.org)
- Set default behavior on core layer filtering stage as allow if any ops
layer filter exists.
- Wordsmith commit messages
- Rebase on latest mm-unstable
SeongJae Park (9):
mm/damon/core: introduce damos->ops_filters
mm/damon/paddr: support ops_filters
mm/damon/core: support committing ops_filters
mm/damon/core: put ops-handled filters to damos->ops_filters
mm/damon/paddr: support only damos->ops_filters
mm/damon: add default allow/reject behavior fields to struct damos
mm/damon/core: set damos_filter default allowance behavior based on
installed filters
mm/damon/paddr: respect ops_filters_default_reject
Docs/mm/damon/design: update for changed filter-default behavior
Documentation/mm/damon/design.rst | 10 ++--
include/linux/damon.h | 11 ++++
mm/damon/core.c | 90 +++++++++++++++++++++++++++++--
mm/damon/paddr.c | 8 +--
4 files changed, 105 insertions(+), 14 deletions(-)
base-commit: d5c41979a39f18ccd660b25eb79e805eb5442e18
--
2.39.5
^ permalink raw reply [flat|nested] 12+ messages in thread
* [RFC PATCH v2 1/9] mm/damon/core: introduce damos->ops_filters
2025-02-27 1:57 [RFC PATCH v2 0/9] mm/damon: make allow filters after reject filters useful and intuitive SeongJae Park
@ 2025-02-27 1:57 ` SeongJae Park
2025-02-27 1:57 ` [RFC PATCH v2 2/9] mm/damon/paddr: support ops_filters SeongJae Park
` (7 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: SeongJae Park @ 2025-02-27 1:57 UTC (permalink / raw)
Cc: SeongJae Park, Andrew Morton, damon, kernel-team, linux-kernel,
linux-mm
DAMOS filters can be categorized into two groups depending on which
layer they are handled, namely core layer and ops layer. The groups are
important because the evaluation sequence of filters decides the overall
behavior, and core layer-handled filters are evaluated before operations
layer-handled ones.
Currently, all filters are maintained in a single list (damos->filters)
in mix. Filters evaluation logics in core layer and operations layer
iterates all the filters on the list, while skipping filters that should
be not handled by the layer of the logic. It is inefficient. Making
future extensions having differentiations for filters of different
handling layers will also be complicated. Add a new list that will be
used for having all operations layer-handled DAMOS filters to DAMOS
scheme data structure, with support of its initialization and basic
traversals.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
include/linux/damon.h | 8 ++++++++
mm/damon/core.c | 1 +
2 files changed, 9 insertions(+)
diff --git a/include/linux/damon.h b/include/linux/damon.h
index 795ca09b1107..add82fdc1117 100644
--- a/include/linux/damon.h
+++ b/include/linux/damon.h
@@ -448,6 +448,7 @@ struct damos_access_pattern {
* @wmarks: Watermarks for automated (in)activation of this scheme.
* @target_nid: Destination node if @action is "migrate_{hot,cold}".
* @filters: Additional set of &struct damos_filter for &action.
+ * @ops_filters: ops layer handling &struct damos_filter objects list.
* @last_applied: Last @action applied ops-managing entity.
* @stat: Statistics of this scheme.
* @list: List head for siblings.
@@ -503,6 +504,7 @@ struct damos {
int target_nid;
};
struct list_head filters;
+ struct list_head ops_filters;
void *last_applied;
struct damos_stat stat;
struct list_head list;
@@ -810,6 +812,12 @@ static inline unsigned long damon_sz_region(struct damon_region *r)
#define damos_for_each_filter_safe(f, next, scheme) \
list_for_each_entry_safe(f, next, &(scheme)->filters, list)
+#define damos_for_each_ops_filter(f, scheme) \
+ list_for_each_entry(f, &(scheme)->ops_filters, list)
+
+#define damos_for_each_ops_filter_safe(f, next, scheme) \
+ list_for_each_entry_safe(f, next, &(scheme)->ops_filters, list)
+
#ifdef CONFIG_DAMON
struct damon_region *damon_new_region(unsigned long start, unsigned long end);
diff --git a/mm/damon/core.c b/mm/damon/core.c
index 38f545fea585..bcb7e42098dc 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -374,6 +374,7 @@ struct damos *damon_new_scheme(struct damos_access_pattern *pattern,
*/
scheme->next_apply_sis = 0;
INIT_LIST_HEAD(&scheme->filters);
+ INIT_LIST_HEAD(&scheme->ops_filters);
scheme->stat = (struct damos_stat){};
INIT_LIST_HEAD(&scheme->list);
--
2.39.5
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [RFC PATCH v2 2/9] mm/damon/paddr: support ops_filters
2025-02-27 1:57 [RFC PATCH v2 0/9] mm/damon: make allow filters after reject filters useful and intuitive SeongJae Park
2025-02-27 1:57 ` [RFC PATCH v2 1/9] mm/damon/core: introduce damos->ops_filters SeongJae Park
@ 2025-02-27 1:57 ` SeongJae Park
2025-02-27 1:57 ` [RFC PATCH v2 3/9] mm/damon/core: support committing ops_filters SeongJae Park
` (6 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: SeongJae Park @ 2025-02-27 1:57 UTC (permalink / raw)
Cc: SeongJae Park, Andrew Morton, damon, kernel-team, linux-kernel,
linux-mm
DAMON keeps all DAMOS filters in damos->filters. No filter is saved in
damos->ops_filters, but upcoming changes will make it to use
damos->ops_filters to have all operations layer handled DAMOS filters.
DAMON physical address space operations set implementation (paddr) is
not ready for the changes, since it handles only damos->filters. To
avoid any breakage during the upcoming changes, make paddr to handle
both lists. After the change is made, ->filters support on paddr can be
safely removed.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
mm/damon/paddr.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
index 25090230da17..3e651308ba5d 100644
--- a/mm/damon/paddr.c
+++ b/mm/damon/paddr.c
@@ -257,6 +257,10 @@ static bool damos_pa_filter_out(struct damos *scheme, struct folio *folio)
if (damos_pa_filter_match(filter, folio))
return !filter->allow;
}
+ damos_for_each_ops_filter(filter, scheme) {
+ if (damos_pa_filter_match(filter, folio))
+ return !filter->allow;
+ }
return false;
}
@@ -287,6 +291,12 @@ static unsigned long damon_pa_pageout(struct damon_region *r, struct damos *s,
break;
}
}
+ damos_for_each_ops_filter(filter, s) {
+ if (filter->type == DAMOS_FILTER_TYPE_YOUNG) {
+ install_young_filter = false;
+ break;
+ }
+ }
if (install_young_filter) {
filter = damos_new_filter(
DAMOS_FILTER_TYPE_YOUNG, true, false);
@@ -535,6 +545,8 @@ static bool damon_pa_scheme_has_filter(struct damos *s)
damos_for_each_filter(f, s)
return true;
+ damos_for_each_ops_filter(f, s)
+ return true;
return false;
}
--
2.39.5
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [RFC PATCH v2 3/9] mm/damon/core: support committing ops_filters
2025-02-27 1:57 [RFC PATCH v2 0/9] mm/damon: make allow filters after reject filters useful and intuitive SeongJae Park
2025-02-27 1:57 ` [RFC PATCH v2 1/9] mm/damon/core: introduce damos->ops_filters SeongJae Park
2025-02-27 1:57 ` [RFC PATCH v2 2/9] mm/damon/paddr: support ops_filters SeongJae Park
@ 2025-02-27 1:57 ` SeongJae Park
2025-02-27 1:57 ` [RFC PATCH v2 4/9] mm/damon/core: put ops-handled filters to damos->ops_filters SeongJae Park
` (5 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: SeongJae Park @ 2025-02-27 1:57 UTC (permalink / raw)
Cc: SeongJae Park, Andrew Morton, damon, kernel-team, linux-kernel,
linux-mm
DAMON kernel API callers should use damon_commit_ctx() to install DAMON
parameters including DAMOS filters. But damos_commit_ops_filters(),
which is called by damon_commit_ctx() for filters installing, is not
handling damos->ops_filters. Hence, no DAMON kernel API caller can use
damos->ops_filters. Do the committing of the ops_filters to make it
usable.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
mm/damon/core.c | 40 +++++++++++++++++++++++++++++++++++++++-
1 file changed, 39 insertions(+), 1 deletion(-)
diff --git a/mm/damon/core.c b/mm/damon/core.c
index bcb7e42098dc..ffdd84ff6fa5 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -793,7 +793,7 @@ static void damos_commit_filter(
damos_commit_filter_arg(dst, src);
}
-static int damos_commit_filters(struct damos *dst, struct damos *src)
+static int damos_commit_core_filters(struct damos *dst, struct damos *src)
{
struct damos_filter *dst_filter, *next, *src_filter, *new_filter;
int i = 0, j = 0;
@@ -821,6 +821,44 @@ static int damos_commit_filters(struct damos *dst, struct damos *src)
return 0;
}
+static int damos_commit_ops_filters(struct damos *dst, struct damos *src)
+{
+ struct damos_filter *dst_filter, *next, *src_filter, *new_filter;
+ int i = 0, j = 0;
+
+ damos_for_each_ops_filter_safe(dst_filter, next, dst) {
+ src_filter = damos_nth_filter(i++, src);
+ if (src_filter)
+ damos_commit_filter(dst_filter, src_filter);
+ else
+ damos_destroy_filter(dst_filter);
+ }
+
+ damos_for_each_ops_filter_safe(src_filter, next, src) {
+ if (j++ < i)
+ continue;
+
+ new_filter = damos_new_filter(
+ src_filter->type, src_filter->matching,
+ src_filter->allow);
+ if (!new_filter)
+ return -ENOMEM;
+ damos_commit_filter_arg(new_filter, src_filter);
+ damos_add_filter(dst, new_filter);
+ }
+ return 0;
+}
+
+static int damos_commit_filters(struct damos *dst, struct damos *src)
+{
+ int err;
+
+ err = damos_commit_core_filters(dst, src);
+ if (err)
+ return err;
+ return damos_commit_ops_filters(dst, src);
+}
+
static struct damos *damon_nth_scheme(int n, struct damon_ctx *ctx)
{
struct damos *s;
--
2.39.5
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [RFC PATCH v2 4/9] mm/damon/core: put ops-handled filters to damos->ops_filters
2025-02-27 1:57 [RFC PATCH v2 0/9] mm/damon: make allow filters after reject filters useful and intuitive SeongJae Park
` (2 preceding siblings ...)
2025-02-27 1:57 ` [RFC PATCH v2 3/9] mm/damon/core: support committing ops_filters SeongJae Park
@ 2025-02-27 1:57 ` SeongJae Park
2025-02-27 1:57 ` [RFC PATCH v2 5/9] mm/damon/paddr: support only damos->ops_filters SeongJae Park
` (4 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: SeongJae Park @ 2025-02-27 1:57 UTC (permalink / raw)
Cc: SeongJae Park, Andrew Morton, damon, kernel-team, linux-kernel,
linux-mm
damos->ops_filters has introduced to be used for all operations layer
handled filters. But DAMON kernel API callers can put any type of DAMOS
filters to any of damos->filters and damos->ops_filters. DAMON
user-space ABI users have no way to use ->ops_filters at all. Update
damos_add_filter(), which should be used by API callers to install DAMOS
filters, to given filters to ->filters and ->ops_filters depending on
their handling layer. The change forces both API callers and ABI users
to use proper lists since ABI users use the API internally.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
mm/damon/core.c | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/mm/damon/core.c b/mm/damon/core.c
index ffdd84ff6fa5..78126a5145fd 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -281,9 +281,24 @@ struct damos_filter *damos_new_filter(enum damos_filter_type type,
return filter;
}
+static bool damos_filter_for_ops(enum damos_filter_type type)
+{
+ switch (type) {
+ case DAMOS_FILTER_TYPE_ADDR:
+ case DAMOS_FILTER_TYPE_TARGET:
+ return false;
+ default:
+ break;
+ }
+ return true;
+}
+
void damos_add_filter(struct damos *s, struct damos_filter *f)
{
- list_add_tail(&f->list, &s->filters);
+ if (damos_filter_for_ops(f->type))
+ list_add_tail(&f->list, &s->ops_filters);
+ else
+ list_add_tail(&f->list, &s->filters);
}
static void damos_del_filter(struct damos_filter *f)
--
2.39.5
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [RFC PATCH v2 5/9] mm/damon/paddr: support only damos->ops_filters
2025-02-27 1:57 [RFC PATCH v2 0/9] mm/damon: make allow filters after reject filters useful and intuitive SeongJae Park
` (3 preceding siblings ...)
2025-02-27 1:57 ` [RFC PATCH v2 4/9] mm/damon/core: put ops-handled filters to damos->ops_filters SeongJae Park
@ 2025-02-27 1:57 ` SeongJae Park
2025-02-27 1:57 ` [RFC PATCH v2 6/9] mm/damon: add default allow/reject behavior fields to struct damos SeongJae Park
` (3 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: SeongJae Park @ 2025-02-27 1:57 UTC (permalink / raw)
Cc: SeongJae Park, Andrew Morton, damon, kernel-team, linux-kernel,
linux-mm
DAMON physical address space operation set implementation (paddr)
started handling both ->filters and ->ops_filters to avoid breakage
during the change for the ->ops_filters setup. Now the change is done,
so paddr's support of ->filters is a waste that can safely dropped.
Remove it.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
mm/damon/paddr.c | 12 ------------
1 file changed, 12 deletions(-)
diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
index 3e651308ba5d..432ea4efdc4b 100644
--- a/mm/damon/paddr.c
+++ b/mm/damon/paddr.c
@@ -253,10 +253,6 @@ static bool damos_pa_filter_out(struct damos *scheme, struct folio *folio)
{
struct damos_filter *filter;
- damos_for_each_filter(filter, scheme) {
- if (damos_pa_filter_match(filter, folio))
- return !filter->allow;
- }
damos_for_each_ops_filter(filter, scheme) {
if (damos_pa_filter_match(filter, folio))
return !filter->allow;
@@ -285,12 +281,6 @@ static unsigned long damon_pa_pageout(struct damon_region *r, struct damos *s,
struct folio *folio;
/* check access in page level again by default */
- damos_for_each_filter(filter, s) {
- if (filter->type == DAMOS_FILTER_TYPE_YOUNG) {
- install_young_filter = false;
- break;
- }
- }
damos_for_each_ops_filter(filter, s) {
if (filter->type == DAMOS_FILTER_TYPE_YOUNG) {
install_young_filter = false;
@@ -543,8 +533,6 @@ static bool damon_pa_scheme_has_filter(struct damos *s)
{
struct damos_filter *f;
- damos_for_each_filter(f, s)
- return true;
damos_for_each_ops_filter(f, s)
return true;
return false;
--
2.39.5
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [RFC PATCH v2 6/9] mm/damon: add default allow/reject behavior fields to struct damos
2025-02-27 1:57 [RFC PATCH v2 0/9] mm/damon: make allow filters after reject filters useful and intuitive SeongJae Park
` (4 preceding siblings ...)
2025-02-27 1:57 ` [RFC PATCH v2 5/9] mm/damon/paddr: support only damos->ops_filters SeongJae Park
@ 2025-02-27 1:57 ` SeongJae Park
2025-02-27 1:57 ` [RFC PATCH v2 7/9] mm/damon/core: set damos_filter default allowance behavior based on installed filters SeongJae Park
` (2 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: SeongJae Park @ 2025-02-27 1:57 UTC (permalink / raw)
Cc: SeongJae Park, Andrew Morton, damon, kernel-team, linux-kernel,
linux-mm
Current default allow/reject behavior of filters handling stage has made
before introduction of the allow behavior. For allow-filters usage, it
is confusing and inefficient.
It is more intuitive to decide the default filtering stage allow/reject
behavior as opposite to the last filter's behavior. The decision should
be made separately for core and operations layers' filtering stages,
since last core layer-handled filter is not really a last filter if
there are operations layer handling filters.
Keeping separate decisions for the two categories can make the logic
simpler. Add fields for storing the two decisions.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
include/linux/damon.h | 3 +++
1 file changed, 3 insertions(+)
diff --git a/include/linux/damon.h b/include/linux/damon.h
index add82fdc1117..1d8479f57f85 100644
--- a/include/linux/damon.h
+++ b/include/linux/damon.h
@@ -497,6 +497,9 @@ struct damos {
unsigned long next_apply_sis;
/* informs if ongoing DAMOS walk for this scheme is finished */
bool walk_completed;
+ /* whether to reject core/ops filters umatched regions */
+ bool core_filters_default_reject;
+ bool ops_filters_default_reject;
/* public: */
struct damos_quota quota;
struct damos_watermarks wmarks;
--
2.39.5
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [RFC PATCH v2 7/9] mm/damon/core: set damos_filter default allowance behavior based on installed filters
2025-02-27 1:57 [RFC PATCH v2 0/9] mm/damon: make allow filters after reject filters useful and intuitive SeongJae Park
` (5 preceding siblings ...)
2025-02-27 1:57 ` [RFC PATCH v2 6/9] mm/damon: add default allow/reject behavior fields to struct damos SeongJae Park
@ 2025-02-27 1:57 ` SeongJae Park
2025-02-27 5:50 ` SeongJae Park
2025-02-27 1:57 ` [RFC PATCH v2 8/9] mm/damon/paddr: respect ops_filters_default_reject SeongJae Park
2025-02-27 1:57 ` [RFC PATCH v2 9/9] Docs/mm/damon/design: update for changed filter-default behavior SeongJae Park
8 siblings, 1 reply; 12+ messages in thread
From: SeongJae Park @ 2025-02-27 1:57 UTC (permalink / raw)
Cc: SeongJae Park, Andrew Morton, damon, kernel-team, linux-kernel,
linux-mm
Decide whether to allow or reject by default on core and opertions layer
handled filters evaluation stages. It is decided as the opposite of the
last installed filter's behavior. If there is no filter at all, allow
by default. If there is any operations layer handled filters, core
layer's filtering stage sets allowing as the default behavior regardless
of the last filter of core layer-handling ones, since the last filter of
core layer handled filters in the case is not really the last filter of
the entire filtering stage.
Also, make the core layer's DAMOS filters handling stage uses the newly
set behavior field.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
mm/damon/core.c | 34 ++++++++++++++++++++++++++++++++--
1 file changed, 32 insertions(+), 2 deletions(-)
diff --git a/mm/damon/core.c b/mm/damon/core.c
index 78126a5145fd..8661f64ab1b4 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -864,6 +864,32 @@ static int damos_commit_ops_filters(struct damos *dst, struct damos *src)
return 0;
}
+/**
+ * damos_filters_default_reject() - decide whether to reject memory that didn't
+ * match with any given filter.
+ * @filters: Given DAMOS filters of a group.
+ */
+static bool damos_filters_default_reject(struct list_head *filters)
+{
+ struct damos_filter *last_filter;
+
+ if (list_empty(filters))
+ return false;
+ last_filter = list_last_entry(filters, struct damos_filter, list);
+ return last_filter->allow;
+}
+
+static void damos_set_filters_default_reject(struct damos *s)
+{
+ if (!list_empty(&s->ops_filters))
+ s->core_filters_default_reject = false;
+ else
+ s->core_filters_default_reject =
+ damos_filters_default_reject(&s->filters);
+ s->ops_filters_default_reject =
+ damos_filters_default_reject(&s->ops_filters);
+}
+
static int damos_commit_filters(struct damos *dst, struct damos *src)
{
int err;
@@ -871,7 +897,11 @@ static int damos_commit_filters(struct damos *dst, struct damos *src)
err = damos_commit_core_filters(dst, src);
if (err)
return err;
- return damos_commit_ops_filters(dst, src);
+ err = damos_commit_ops_filters(dst, src);
+ if (err)
+ return err;
+ damos_set_filters_default_reject(dst);
+ return 0;
}
static struct damos *damon_nth_scheme(int n, struct damon_ctx *ctx)
@@ -1490,7 +1520,7 @@ static bool damos_filter_out(struct damon_ctx *ctx, struct damon_target *t,
if (damos_filter_match(ctx, t, r, filter))
return !filter->allow;
}
- return false;
+ return s->core_filters_default_reject;
}
/*
--
2.39.5
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [RFC PATCH v2 8/9] mm/damon/paddr: respect ops_filters_default_reject
2025-02-27 1:57 [RFC PATCH v2 0/9] mm/damon: make allow filters after reject filters useful and intuitive SeongJae Park
` (6 preceding siblings ...)
2025-02-27 1:57 ` [RFC PATCH v2 7/9] mm/damon/core: set damos_filter default allowance behavior based on installed filters SeongJae Park
@ 2025-02-27 1:57 ` SeongJae Park
2025-02-27 1:57 ` [RFC PATCH v2 9/9] Docs/mm/damon/design: update for changed filter-default behavior SeongJae Park
8 siblings, 0 replies; 12+ messages in thread
From: SeongJae Park @ 2025-02-27 1:57 UTC (permalink / raw)
Cc: SeongJae Park, Andrew Morton, damon, kernel-team, linux-kernel,
linux-mm
Use damos->ops_filters_default_reject, which is set based on the
installed filters' behaviors, from physical address space DAMON
operations set.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
mm/damon/paddr.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
index 432ea4efdc4b..fee66a3cc82b 100644
--- a/mm/damon/paddr.c
+++ b/mm/damon/paddr.c
@@ -257,7 +257,7 @@ static bool damos_pa_filter_out(struct damos *scheme, struct folio *folio)
if (damos_pa_filter_match(filter, folio))
return !filter->allow;
}
- return false;
+ return scheme->ops_filters_default_reject;
}
static bool damon_pa_invalid_damos_folio(struct folio *folio, struct damos *s)
--
2.39.5
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [RFC PATCH v2 9/9] Docs/mm/damon/design: update for changed filter-default behavior
2025-02-27 1:57 [RFC PATCH v2 0/9] mm/damon: make allow filters after reject filters useful and intuitive SeongJae Park
` (7 preceding siblings ...)
2025-02-27 1:57 ` [RFC PATCH v2 8/9] mm/damon/paddr: respect ops_filters_default_reject SeongJae Park
@ 2025-02-27 1:57 ` SeongJae Park
8 siblings, 0 replies; 12+ messages in thread
From: SeongJae Park @ 2025-02-27 1:57 UTC (permalink / raw)
Cc: SeongJae Park, Andrew Morton, Jonathan Corbet, damon, kernel-team,
linux-doc, linux-kernel, linux-mm
Update the design documentation for changed DAMOS filters default
allowance behaviors.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
Documentation/mm/damon/design.rst | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/Documentation/mm/damon/design.rst b/Documentation/mm/damon/design.rst
index 5af991551a86..ffea744e4889 100644
--- a/Documentation/mm/damon/design.rst
+++ b/Documentation/mm/damon/design.rst
@@ -581,9 +581,10 @@ When multiple filters are installed, the group of filters that handled by the
core layer are evaluated first. After that, the group of filters that handled
by the operations layer are evaluated. Filters in each of the groups are
evaluated in the installed order. If a part of memory is matched to one of the
-filter, next filters are ignored. If the memory passes through the filters
+filter, next filters are ignored. If the part passes through the filters
evaluation stage because it is not matched to any of the filters, applying the
-scheme's action to it is allowed, same to the behavior when no filter exists.
+scheme's action to it depends on the last filter's allowance type. If the last
+filter was for allowing, the part of memory will be rejected, and vice versa.
For example, let's assume 1) a filter for allowing anonymous pages and 2)
another filter for rejecting young pages are installed in the order. If a page
@@ -595,11 +596,6 @@ second reject-filter blocks it. If the page is neither anonymous nor young,
the page will pass through the filters evaluation stage since there is no
matching filter, and the action will be applied to the page.
-Note that the action can equally be applied to memory that either explicitly
-filter-allowed or filters evaluation stage passed. It means that installing
-allow-filters at the end of the list makes no practical change but only
-filters-checking overhead.
-
Below ``type`` of filters are currently supported.
- Core layer handled
--
2.39.5
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [RFC PATCH v2 7/9] mm/damon/core: set damos_filter default allowance behavior based on installed filters
2025-02-27 1:57 ` [RFC PATCH v2 7/9] mm/damon/core: set damos_filter default allowance behavior based on installed filters SeongJae Park
@ 2025-02-27 5:50 ` SeongJae Park
2025-02-28 4:48 ` SeongJae Park
0 siblings, 1 reply; 12+ messages in thread
From: SeongJae Park @ 2025-02-27 5:50 UTC (permalink / raw)
To: SeongJae Park; +Cc: Andrew Morton, damon, kernel-team, linux-kernel, linux-mm
On Wed, 26 Feb 2025 17:57:52 -0800 SeongJae Park <sj@kernel.org> wrote:
> Decide whether to allow or reject by default on core and opertions layer
> handled filters evaluation stages. It is decided as the opposite of the
> last installed filter's behavior. If there is no filter at all, allow
> by default. If there is any operations layer handled filters, core
> layer's filtering stage sets allowing as the default behavior regardless
> of the last filter of core layer-handling ones, since the last filter of
> core layer handled filters in the case is not really the last filter of
> the entire filtering stage.
This is not sufficient enough. Even with this change, core-handled allow
filters after core-handled reject filters are still meaningless.
If a region is matched to a core layer handled filter, the allow/reject
decision should be respected while ignoring all remaining filters, regardless
of on what layer those are handled. It works in the way for reect filters,
since core layer-rejected regions are not passed to the ops layer at all. In
case of allow filter, however, the region is passed to ops layer without the
information about whether it has passed to the ops layer because it was
allowed, or just not matched to any filter. Hence, all ops filters can be
applied to the region.
We can implement this missing part by storing the core layer filtering stage
decision somewhere and let ops filter filtering stage repsect it. Changes like
attached diff at the end of this mail may work. I will add such changes to
next version of this patch series.
Thanks,
SJ
[...]
=================================== >8 ========================================
diff --git a/include/linux/damon.h b/include/linux/damon.h
index b7a4d12ce532..8d8621d8b58d 100644
--- a/include/linux/damon.h
+++ b/include/linux/damon.h
@@ -528,6 +528,7 @@ struct damos {
unsigned long next_apply_sis;
/* informs if ongoing DAMOS walk for this scheme is finished */
bool walk_completed;
+ bool skip_ops_filters;
/* whether to reject core/ops filters umatched regions */
bool core_filters_default_reject;
bool ops_filters_default_reject;
diff --git a/mm/damon/core.c b/mm/damon/core.c
index 783cc05a9fcc..a2e4bdbb6b19 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -1662,9 +1662,19 @@ static bool damos_filter_out(struct damon_ctx *ctx, struct damon_target *t,
{
struct damos_filter *filter;
+ s->skip_ops_filters = false;
damos_for_each_filter(filter, s) {
- if (damos_filter_match(ctx, t, r, filter))
+ if (damos_filter_match(ctx, t, r, filter)) {
+ /*
+ * ops layer filters should also respect the decision.
+ * Store the information in s->skip_ops_filters.
+ * If the decision is reject, the region will not be
+ * passed to ops layer, so no need to set the flag.
+ */
+ if (filter->allow)
+ s->skip_ops_filters = true;
return !filter->allow;
+ }
}
return s->core_filters_default_reject;
}
diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
index 4a170086852a..8568b5a34888 100644
--- a/mm/damon/paddr.c
+++ b/mm/damon/paddr.c
@@ -393,6 +393,9 @@ static bool damos_pa_filter_out(struct damos *scheme, struct folio *folio)
{
struct damos_filter *filter;
+ if (scheme->skip_ops_filters)
+ return false;
+
damos_for_each_ops_filter(filter, scheme) {
if (damos_pa_filter_match(filter, folio))
return !filter->allow;
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [RFC PATCH v2 7/9] mm/damon/core: set damos_filter default allowance behavior based on installed filters
2025-02-27 5:50 ` SeongJae Park
@ 2025-02-28 4:48 ` SeongJae Park
0 siblings, 0 replies; 12+ messages in thread
From: SeongJae Park @ 2025-02-28 4:48 UTC (permalink / raw)
To: SeongJae Park; +Cc: Andrew Morton, damon, kernel-team, linux-kernel, linux-mm
On Wed, 26 Feb 2025 21:50:54 -0800 SeongJae Park <sj@kernel.org> wrote:
> On Wed, 26 Feb 2025 17:57:52 -0800 SeongJae Park <sj@kernel.org> wrote:
>
> > Decide whether to allow or reject by default on core and opertions layer
> > handled filters evaluation stages. It is decided as the opposite of the
> > last installed filter's behavior. If there is no filter at all, allow
> > by default. If there is any operations layer handled filters, core
> > layer's filtering stage sets allowing as the default behavior regardless
> > of the last filter of core layer-handling ones, since the last filter of
> > core layer handled filters in the case is not really the last filter of
> > the entire filtering stage.
>
> This is not sufficient enough. Even with this change, core-handled allow
> filters after core-handled reject filters are still meaningless.
>
> If a region is matched to a core layer handled filter, the allow/reject
> decision should be respected while ignoring all remaining filters, regardless
> of on what layer those are handled. It works in the way for reect filters,
> since core layer-rejected regions are not passed to the ops layer at all. In
> case of allow filter, however, the region is passed to ops layer without the
> information about whether it has passed to the ops layer because it was
> allowed, or just not matched to any filter. Hence, all ops filters can be
> applied to the region.
>
> We can implement this missing part by storing the core layer filtering stage
> decision somewhere and let ops filter filtering stage repsect it. Changes like
> attached diff at the end of this mail may work. I will add such changes to
> next version of this patch series.
I now realize this is not a missing part of this improvement patch series, but
a sole fix for the allow filter behavior. The current behavior is not matching
with the documented one, and this change will fix it. I will post a patch for
this fix separately from this patch series.
Thanks,
SJ
[...]
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2025-02-28 4:48 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-27 1:57 [RFC PATCH v2 0/9] mm/damon: make allow filters after reject filters useful and intuitive SeongJae Park
2025-02-27 1:57 ` [RFC PATCH v2 1/9] mm/damon/core: introduce damos->ops_filters SeongJae Park
2025-02-27 1:57 ` [RFC PATCH v2 2/9] mm/damon/paddr: support ops_filters SeongJae Park
2025-02-27 1:57 ` [RFC PATCH v2 3/9] mm/damon/core: support committing ops_filters SeongJae Park
2025-02-27 1:57 ` [RFC PATCH v2 4/9] mm/damon/core: put ops-handled filters to damos->ops_filters SeongJae Park
2025-02-27 1:57 ` [RFC PATCH v2 5/9] mm/damon/paddr: support only damos->ops_filters SeongJae Park
2025-02-27 1:57 ` [RFC PATCH v2 6/9] mm/damon: add default allow/reject behavior fields to struct damos SeongJae Park
2025-02-27 1:57 ` [RFC PATCH v2 7/9] mm/damon/core: set damos_filter default allowance behavior based on installed filters SeongJae Park
2025-02-27 5:50 ` SeongJae Park
2025-02-28 4:48 ` SeongJae Park
2025-02-27 1:57 ` [RFC PATCH v2 8/9] mm/damon/paddr: respect ops_filters_default_reject SeongJae Park
2025-02-27 1:57 ` [RFC PATCH v2 9/9] Docs/mm/damon/design: update for changed filter-default behavior SeongJae Park
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).