Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mm/damon/core: add trace point for damos stat per apply interval

DAMON users can read DAMOS stats via DAMON sysfs interface. It enables
efficient, simple and flexible usages of the stats. Especially for
systems not having advanced tools like perf or bpftrace, that can be
useful. But if the advanced tools are available, exposing the stats via
tracepoint can reduce unnecessary reimplementation of the wheels. Add a
new tracepoint for DAMOS stats, namely damos_stat_after_apply_interval.
The tracepoint is triggered for each scheme's apply interval and exposes
the whole stat values. If the user needs sub-apply interval information
for any chance, damos_before_apply tracepoint could be used.

Link: https://lkml.kernel.org/r/20251216080128.42991-13-sj@kernel.org
Signed-off-by: SeongJae Park <sj@kernel.org>
Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

SeongJae Park and committed by
Andrew Morton
804c26b9 dcecf9e5

+58
+41
include/trace/events/damon.h
··· 9 9 #include <linux/types.h> 10 10 #include <linux/tracepoint.h> 11 11 12 + TRACE_EVENT(damos_stat_after_apply_interval, 13 + 14 + TP_PROTO(unsigned int context_idx, unsigned int scheme_idx, 15 + struct damos_stat *stat), 16 + 17 + TP_ARGS(context_idx, scheme_idx, stat), 18 + 19 + TP_STRUCT__entry( 20 + __field(unsigned int, context_idx) 21 + __field(unsigned int, scheme_idx) 22 + __field(unsigned long, nr_tried) 23 + __field(unsigned long, sz_tried) 24 + __field(unsigned long, nr_applied) 25 + __field(unsigned long, sz_applied) 26 + __field(unsigned long, sz_ops_filter_passed) 27 + __field(unsigned long, qt_exceeds) 28 + __field(unsigned long, nr_snapshots) 29 + ), 30 + 31 + TP_fast_assign( 32 + __entry->context_idx = context_idx; 33 + __entry->scheme_idx = scheme_idx; 34 + __entry->nr_tried = stat->nr_tried; 35 + __entry->sz_tried = stat->sz_tried; 36 + __entry->nr_applied = stat->nr_applied; 37 + __entry->sz_applied = stat->sz_applied; 38 + __entry->sz_ops_filter_passed = stat->sz_ops_filter_passed; 39 + __entry->qt_exceeds = stat->qt_exceeds; 40 + __entry->nr_snapshots = stat->nr_snapshots; 41 + ), 42 + 43 + TP_printk("ctx_idx=%u scheme_idx=%u nr_tried=%lu sz_tried=%lu " 44 + "nr_applied=%lu sz_tried=%lu sz_ops_filter_passed=%lu " 45 + "qt_exceeds=%lu nr_snapshots=%lu", 46 + __entry->context_idx, __entry->scheme_idx, 47 + __entry->nr_tried, __entry->sz_tried, 48 + __entry->nr_applied, __entry->sz_applied, 49 + __entry->sz_ops_filter_passed, __entry->qt_exceeds, 50 + __entry->nr_snapshots) 51 + ); 52 + 12 53 TRACE_EVENT(damos_esz, 13 54 14 55 TP_PROTO(unsigned int context_idx, unsigned int scheme_idx,
+17
mm/damon/core.c
··· 2289 2289 quota->min_score = score; 2290 2290 } 2291 2291 2292 + static void damos_trace_stat(struct damon_ctx *c, struct damos *s) 2293 + { 2294 + unsigned int cidx = 0, sidx = 0; 2295 + struct damos *siter; 2296 + 2297 + if (!trace_damos_stat_after_apply_interval_enabled()) 2298 + return; 2299 + 2300 + damon_for_each_scheme(siter, c) { 2301 + if (siter == s) 2302 + break; 2303 + sidx++; 2304 + } 2305 + trace_damos_stat_after_apply_interval(cidx, sidx, &s->stat); 2306 + } 2307 + 2292 2308 static void kdamond_apply_schemes(struct damon_ctx *c) 2293 2309 { 2294 2310 struct damon_target *t; ··· 2346 2330 (s->apply_interval_us ? s->apply_interval_us : 2347 2331 c->attrs.aggr_interval) / sample_interval; 2348 2332 s->last_applied = NULL; 2333 + damos_trace_stat(c, s); 2349 2334 } 2350 2335 mutex_unlock(&c->walk_control_lock); 2351 2336 }