Skip to content

Commit c603c63

Browse files
sjp38akpm00
authored andcommitted
mm/damon/core: add a tracepoint for damos apply target regions
Patch series "mm/damon: add a tracepoint for damos apply target regions", v2. DAMON provides damon_aggregated tracepoint to let users record full monitoring results. Sometimes, users need to record monitoring results of specific pattern. DAMOS tried regions directory of DAMON sysfs interface allows it, but the interface is mainly designed for snapshots and therefore would be inefficient for such recording. Implement yet another tracepoint for efficient support of the usecase. This patch (of 2): DAMON provides damon_aggregated tracepoint, which exposes details of each region and its access monitoring results. It is useful for getting whole monitoring results, e.g., for recording purposes. For investigations of DAMOS, DAMON Sysfs interface provides DAMOS statistics and tried_regions directory. But, those provides only statistics and snapshots. If the scheme is frequently applied and if the user needs to know every detail of DAMOS behavior, the snapshot-based interface could be insufficient and expensive. As a last resort, userspace users need to record the all monitoring results via damon_aggregated tracepoint and simulate how DAMOS would worked. It is unnecessarily complicated. DAMON kernel API users, meanwhile, can do that easily via before_damos_apply() callback field of 'struct damon_callback', though. Add a tracepoint that will be called just after before_damos_apply() callback for more convenient investigations of DAMOS. The tracepoint exposes all details about each regions, similar to damon_aggregated tracepoint. Please note that DAMOS is currently not only for memory management but also for query-like efficient monitoring results retrievals (when 'stat' action is used). Until now, only statistics or snapshots were supported. Addition of this tracepoint allows efficient full recording of DAMOS-based filtered monitoring results. Link: https://lkml.kernel.org/r/20230913022050.2109-1-sj@kernel.org Link: https://lkml.kernel.org/r/20230913022050.2109-2-sj@kernel.org Signed-off-by: SeongJae Park <sj@kernel.org> Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org> [tracing] Cc: Jonathan Corbet <corbet@lwn.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent fa1df3f commit c603c63

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

include/trace/events/damon.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,45 @@
99
#include <linux/types.h>
1010
#include <linux/tracepoint.h>
1111

12+
TRACE_EVENT_CONDITION(damos_before_apply,
13+
14+
TP_PROTO(unsigned int context_idx, unsigned int scheme_idx,
15+
unsigned int target_idx, struct damon_region *r,
16+
unsigned int nr_regions, bool do_trace),
17+
18+
TP_ARGS(context_idx, target_idx, scheme_idx, r, nr_regions, do_trace),
19+
20+
TP_CONDITION(do_trace),
21+
22+
TP_STRUCT__entry(
23+
__field(unsigned int, context_idx)
24+
__field(unsigned int, scheme_idx)
25+
__field(unsigned long, target_idx)
26+
__field(unsigned long, start)
27+
__field(unsigned long, end)
28+
__field(unsigned int, nr_accesses)
29+
__field(unsigned int, age)
30+
__field(unsigned int, nr_regions)
31+
),
32+
33+
TP_fast_assign(
34+
__entry->context_idx = context_idx;
35+
__entry->scheme_idx = scheme_idx;
36+
__entry->target_idx = target_idx;
37+
__entry->start = r->ar.start;
38+
__entry->end = r->ar.end;
39+
__entry->nr_accesses = r->nr_accesses;
40+
__entry->age = r->age;
41+
__entry->nr_regions = nr_regions;
42+
),
43+
44+
TP_printk("ctx_idx=%u scheme_idx=%u target_idx=%lu nr_regions=%u %lu-%lu: %u %u",
45+
__entry->context_idx, __entry->scheme_idx,
46+
__entry->target_idx, __entry->nr_regions,
47+
__entry->start, __entry->end,
48+
__entry->nr_accesses, __entry->age)
49+
);
50+
1251
TRACE_EVENT(damon_aggregated,
1352

1453
TP_PROTO(unsigned int target_id, struct damon_region *r,

mm/damon/core.c

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,33 @@ static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t,
950950
struct timespec64 begin, end;
951951
unsigned long sz_applied = 0;
952952
int err = 0;
953+
/*
954+
* We plan to support multiple context per kdamond, as DAMON sysfs
955+
* implies with 'nr_contexts' file. Nevertheless, only single context
956+
* per kdamond is supported for now. So, we can simply use '0' context
957+
* index here.
958+
*/
959+
unsigned int cidx = 0;
960+
struct damos *siter; /* schemes iterator */
961+
unsigned int sidx = 0;
962+
struct damon_target *titer; /* targets iterator */
963+
unsigned int tidx = 0;
964+
bool do_trace = false;
965+
966+
/* get indices for trace_damos_before_apply() */
967+
if (trace_damos_before_apply_enabled()) {
968+
damon_for_each_scheme(siter, c) {
969+
if (siter == s)
970+
break;
971+
sidx++;
972+
}
973+
damon_for_each_target(titer, c) {
974+
if (titer == t)
975+
break;
976+
tidx++;
977+
}
978+
do_trace = true;
979+
}
953980

954981
if (c->ops.apply_scheme) {
955982
if (quota->esz && quota->charged_sz + sz > quota->esz) {
@@ -964,8 +991,11 @@ static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t,
964991
ktime_get_coarse_ts64(&begin);
965992
if (c->callback.before_damos_apply)
966993
err = c->callback.before_damos_apply(c, t, r, s);
967-
if (!err)
994+
if (!err) {
995+
trace_damos_before_apply(cidx, sidx, tidx, r,
996+
damon_nr_regions(t), do_trace);
968997
sz_applied = c->ops.apply_scheme(c, t, r, s);
998+
}
969999
ktime_get_coarse_ts64(&end);
9701000
quota->total_charged_ns += timespec64_to_ns(&end) -
9711001
timespec64_to_ns(&begin);

0 commit comments

Comments
 (0)