linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: SeongJae Park <sj@kernel.org>
To: SeongJae Park <sj@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	damon@lists.linux.dev, kernel-team@meta.com,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [RFC PATCH v2 7/9] mm/damon/core: set damos_filter default allowance behavior based on installed filters
Date: Wed, 26 Feb 2025 21:50:54 -0800	[thread overview]
Message-ID: <20250227055054.22813-1-sj@kernel.org> (raw)
In-Reply-To: <20250227015754.38789-8-sj@kernel.org>

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;


  reply	other threads:[~2025-02-27  5:51 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

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=20250227055054.22813-1-sj@kernel.org \
    --to=sj@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=damon@lists.linux.dev \
    --cc=kernel-team@meta.com \
    --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 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).