From: SeongJae Park <sj@kernel.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: SeongJae Park <sj@kernel.org>,
damon@lists.linux.dev, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Subject: [RFC PATCH 08/13] mm/damon/core: implement target type damos filter
Date: Fri, 28 Jul 2023 20:34:39 +0000 [thread overview]
Message-ID: <20230728203444.70703-9-sj@kernel.org> (raw)
In-Reply-To: <20230728203444.70703-1-sj@kernel.org>
One DAMON context can have multiple monitoring targets, and DAMOS
schemes are applied to all targets. In some cases, users need to apply
different scheme to different targets. Retrieving monitoring results
via DAMON sysfs interface' 'tried_regions' directory could be one good
example. Also, there could be cases that cgroup DAMOS filter is not
enough. All such use cases can be worked around by having multiple
DAMON contexts having only single target, but it is inefficient in terms
of resource usage, thogh the overhead is not estimated to be huge.
Implement DAMON monitoring target based DAMOS filter for the case. Like
address range target DAMOS filter, handle these filters in the DAMON
core layer, since it is more efficient than doing in operations set
layer. This also means that regions that filtered out by monitoring
target type DAMOS filters are counted as not tried by the scheme.
Hence, target granularity monitoring results retrieval via DAMON sysfs
interface becomes available.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
include/linux/damon.h | 6 ++++++
mm/damon/core.c | 22 ++++++++++++++++------
2 files changed, 22 insertions(+), 6 deletions(-)
diff --git a/include/linux/damon.h b/include/linux/damon.h
index 476f37a883a4..ae2664d1d5f1 100644
--- a/include/linux/damon.h
+++ b/include/linux/damon.h
@@ -227,6 +227,7 @@ struct damos_stat {
* @DAMOS_FILTER_TYPE_ANON: Anonymous pages.
* @DAMOS_FILTER_TYPE_MEMCG: Specific memcg's pages.
* @DAMOS_FILTER_TYPE_ADDR: Address range.
+ * @DAMOS_FILTER_TYPE_TARGET: Data Access Monitoring target.
* @NR_DAMOS_FILTER_TYPES: Number of filter types.
*
* The anon pages type and memcg type filters are handled by underlying
@@ -244,6 +245,7 @@ enum damos_filter_type {
DAMOS_FILTER_TYPE_ANON,
DAMOS_FILTER_TYPE_MEMCG,
DAMOS_FILTER_TYPE_ADDR,
+ DAMOS_FILTER_TYPE_TARGET,
NR_DAMOS_FILTER_TYPES,
};
@@ -253,6 +255,9 @@ enum damos_filter_type {
* @matching: If the matching page should filtered out or in.
* @memcg_id: Memcg id of the question if @type is DAMOS_FILTER_MEMCG.
* @addr_range: Address range if @type is DAMOS_FILTER_TYPE_ADDR.
+ * @target_idx: Index of the &struct damon_target of
+ * &damon_ctx->adaptive_targets if @type is
+ * DAMOS_FILTER_TYPE_TARGET.
* @list: List head for siblings.
*
* Before applying the &damos->action to a memory region, DAMOS checks if each
@@ -266,6 +271,7 @@ struct damos_filter {
union {
unsigned short memcg_id;
struct damon_addr_range addr_range;
+ int target_idx;
};
struct list_head list;
};
diff --git a/mm/damon/core.c b/mm/damon/core.c
index c061d289c832..334bc5823d83 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -906,13 +906,23 @@ static void damos_update_stat(struct damos *s,
s->stat.sz_applied += sz_applied;
}
-static bool __damos_filter_out(struct damon_target *t, struct damon_region *r,
- struct damos_filter *filter)
+static bool __damos_filter_out(struct damon_ctx *ctx, struct damon_target *t,
+ struct damon_region *r, struct damos_filter *filter)
{
bool matched = false;
+ struct damon_target *ti;
+ int target_idx = 0;
unsigned long start, end;
switch (filter->type) {
+ case DAMOS_FILTER_TYPE_TARGET:
+ damon_for_each_target(ti, ctx) {
+ if (ti == t)
+ break;
+ target_idx++;
+ }
+ matched = target_idx == filter->target_idx;
+ break;
case DAMOS_FILTER_TYPE_ADDR:
start = ALIGN_DOWN(filter->addr_range.start, DAMON_MIN_REGION);
end = ALIGN_DOWN(filter->addr_range.end, DAMON_MIN_REGION);
@@ -944,13 +954,13 @@ static bool __damos_filter_out(struct damon_target *t, struct damon_region *r,
return matched == filter->matching;
}
-static bool damos_filter_out(struct damon_target *t, struct damon_region *r,
- struct damos *s)
+static bool damos_filter_out(struct damon_ctx *ctx, struct damon_target *t,
+ struct damon_region *r, struct damos *s)
{
struct damos_filter *filter;
damos_for_each_filter(filter, s) {
- if (__damos_filter_out(t, r, filter))
+ if (__damos_filter_out(ctx, t, r, filter))
return true;
}
return false;
@@ -982,7 +992,7 @@ static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t,
}
damon_split_region_at(t, r, sz);
}
- if (damos_filter_out(t, r, s))
+ if (damos_filter_out(c, t, r, s))
return;
ktime_get_coarse_ts64(&begin);
if (c->callback.before_damos_apply)
--
2.25.1
next prev parent reply other threads:[~2023-07-28 20:35 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-28 20:34 [RFC PATCH 00/13] Extedn DAMOS filters for address ranges and SeongJae Park
2023-07-28 20:34 ` [RFC PATCH 01/13] mm/damon/core: introduce address range type damos filter SeongJae Park
2023-07-28 20:34 ` [RFC PATCH 02/13] mm/damon/sysfs-schemes: support address range type DAMOS filter SeongJae Park
2023-07-28 20:34 ` SeongJae Park
2023-07-28 20:34 ` [RFC PATCH 04/13] selftests/damon/sysfs: test address range damos filter SeongJae Park
2023-07-28 20:34 ` [RFC PATCH 05/13] Docs/mm/damon/design: update for address range filters SeongJae Park
2023-07-28 20:34 ` [RFC PATCH 06/13] Docs/ABI/damon: update for address range DAMOS filter SeongJae Park
2023-07-28 20:34 ` [RFC PATCH 07/13] Docs/admin-guide/mm/damon/usage: update for address range type " SeongJae Park
2023-07-28 20:34 ` SeongJae Park [this message]
2023-07-28 20:34 ` [RFC PATCH 09/13] mm/damon/sysfs-schemes: support target damos filter SeongJae Park
2023-07-28 20:34 ` [RFC PATCH 10/13] selftests/damon/sysfs: test damon_target filter SeongJae Park
2023-07-28 20:34 ` [RFC PATCH 11/13] Docs/mm/damon/design: update for DAMON monitoring target type DAMOS filter SeongJae Park
2023-07-28 20:34 ` [RFC PATCH 12/13] Docs/ABI/damon: " SeongJae Park
2023-07-28 20:34 ` [RFC PATCH 13/13] Docs/admin-guide/mm/damon/usage: " 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=20230728203444.70703-9-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox