* (no subject)
@ 2023-09-12 18:35 SeongJae Park
2023-09-12 18:35 ` [PATCH v2 1/2] mm/damon/core: add a tracepoint for damos apply target regions SeongJae Park
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: SeongJae Park @ 2023-09-12 18:35 UTC (permalink / raw)
To: Andrew Morton
Cc: SeongJae Park, Jonathan Corbet, Steven Rostedt, damon, linux-mm,
linux-doc, linux-trace-kernel, linux-kernel
Date: Tue, 12 Sep 2023 02:24:11 +0000
Subject: [PATCH v2 0/2] mm/damon: add a tracepoint for damos apply target regions
Changlog
--------
From v1
(https://lore.kernel.org/damon/20230911045908.97649-1-sj@kernel.org/)
- Get scheme/target indices only when the trace is enabled (Steven Rostedt)
From RFC
(https://lore.kernel.org/damon/20230827004045.49516-1-sj@kernel.org/)
- Fix the 4 byte hole (Steven Rostedt)
- Add documentation
Description
-----------
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.
SeongJae Park (2):
mm/damon/core: add a tracepoint for damos apply target regions
Docs/admin-guide/mm/damon/usage: document damos_before_apply
tracepoint
Documentation/admin-guide/mm/damon/usage.rst | 37 +++++++++++++++----
include/trace/events/damon.h | 39 ++++++++++++++++++++
mm/damon/core.c | 32 +++++++++++++++-
3 files changed, 100 insertions(+), 8 deletions(-)
base-commit: b67dc18d1406be3598248d2cc78904a81176fa13
--
2.25.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 1/2] mm/damon/core: add a tracepoint for damos apply target regions
2023-09-12 18:35 SeongJae Park
@ 2023-09-12 18:35 ` SeongJae Park
2023-09-12 18:35 ` [PATCH v2 2/2] Docs/admin-guide/mm/damon/usage: document damos_before_apply tracepoint SeongJae Park
2023-09-13 2:19 ` (no title) SeongJae Park
2 siblings, 0 replies; 4+ messages in thread
From: SeongJae Park @ 2023-09-12 18:35 UTC (permalink / raw)
To: Andrew Morton
Cc: SeongJae Park, Steven Rostedt, damon, linux-mm,
linux-trace-kernel, linux-kernel
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.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
include/trace/events/damon.h | 39 ++++++++++++++++++++++++++++++++++++
mm/damon/core.c | 32 ++++++++++++++++++++++++++++-
2 files changed, 70 insertions(+), 1 deletion(-)
diff --git a/include/trace/events/damon.h b/include/trace/events/damon.h
index 0b8d13bde17a..19930bb7af9a 100644
--- a/include/trace/events/damon.h
+++ b/include/trace/events/damon.h
@@ -9,6 +9,45 @@
#include <linux/types.h>
#include <linux/tracepoint.h>
+TRACE_EVENT_CONDITION(damos_before_apply,
+
+ TP_PROTO(unsigned int context_idx, unsigned int scheme_idx,
+ unsigned int target_idx, struct damon_region *r,
+ unsigned int nr_regions, bool do_trace),
+
+ TP_ARGS(context_idx, target_idx, scheme_idx, r, nr_regions, do_trace),
+
+ TP_CONDITION(do_trace),
+
+ TP_STRUCT__entry(
+ __field(unsigned int, context_idx)
+ __field(unsigned int, scheme_idx)
+ __field(unsigned long, target_idx)
+ __field(unsigned long, start)
+ __field(unsigned long, end)
+ __field(unsigned int, nr_accesses)
+ __field(unsigned int, age)
+ __field(unsigned int, nr_regions)
+ ),
+
+ TP_fast_assign(
+ __entry->context_idx = context_idx;
+ __entry->scheme_idx = scheme_idx;
+ __entry->target_idx = target_idx;
+ __entry->start = r->ar.start;
+ __entry->end = r->ar.end;
+ __entry->nr_accesses = r->nr_accesses;
+ __entry->age = r->age;
+ __entry->nr_regions = nr_regions;
+ ),
+
+ TP_printk("ctx_idx=%u scheme_idx=%u target_idx=%lu nr_regions=%u %lu-%lu: %u %u",
+ __entry->context_idx, __entry->scheme_idx,
+ __entry->target_idx, __entry->nr_regions,
+ __entry->start, __entry->end,
+ __entry->nr_accesses, __entry->age)
+);
+
TRACE_EVENT(damon_aggregated,
TP_PROTO(unsigned int target_id, struct damon_region *r,
diff --git a/mm/damon/core.c b/mm/damon/core.c
index ca631dd88b33..3ca34a252a3c 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -950,6 +950,33 @@ static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t,
struct timespec64 begin, end;
unsigned long sz_applied = 0;
int err = 0;
+ /*
+ * We plan to support multiple context per kdamond, as DAMON sysfs
+ * implies with 'nr_contexts' file. Nevertheless, only single context
+ * per kdamond is supported for now. So, we can simply use '0' context
+ * index here.
+ */
+ unsigned int cidx = 0;
+ struct damos *siter; /* schemes iterator */
+ unsigned int sidx = 0;
+ struct damon_target *titer; /* targets iterator */
+ unsigned int tidx = 0;
+ bool do_trace = false;
+
+ /* get indices for trace_damos_before_apply() */
+ if (trace_damos_before_apply_enabled()) {
+ damon_for_each_scheme(siter, c) {
+ if (siter == s)
+ break;
+ sidx++;
+ }
+ damon_for_each_target(titer, c) {
+ if (titer == t)
+ break;
+ tidx++;
+ }
+ do_trace = true;
+ }
if (c->ops.apply_scheme) {
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,
ktime_get_coarse_ts64(&begin);
if (c->callback.before_damos_apply)
err = c->callback.before_damos_apply(c, t, r, s);
- if (!err)
+ if (!err) {
+ trace_damos_before_apply(cidx, sidx, tidx, r,
+ damon_nr_regions(t), do_trace);
sz_applied = c->ops.apply_scheme(c, t, r, s);
+ }
ktime_get_coarse_ts64(&end);
quota->total_charged_ns += timespec64_to_ns(&end) -
timespec64_to_ns(&begin);
--
2.25.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 2/2] Docs/admin-guide/mm/damon/usage: document damos_before_apply tracepoint
2023-09-12 18:35 SeongJae Park
2023-09-12 18:35 ` [PATCH v2 1/2] mm/damon/core: add a tracepoint for damos apply target regions SeongJae Park
@ 2023-09-12 18:35 ` SeongJae Park
2023-09-13 2:19 ` (no title) SeongJae Park
2 siblings, 0 replies; 4+ messages in thread
From: SeongJae Park @ 2023-09-12 18:35 UTC (permalink / raw)
To: Andrew Morton
Cc: SeongJae Park, Jonathan Corbet, damon, linux-mm, linux-doc, linux-kernel
Document damos_before_apply tracepoint on the usage document.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
Documentation/admin-guide/mm/damon/usage.rst | 37 ++++++++++++++++----
1 file changed, 30 insertions(+), 7 deletions(-)
diff --git a/Documentation/admin-guide/mm/damon/usage.rst b/Documentation/admin-guide/mm/damon/usage.rst
index 282062b6f134..6272cd36590a 100644
--- a/Documentation/admin-guide/mm/damon/usage.rst
+++ b/Documentation/admin-guide/mm/damon/usage.rst
@@ -496,15 +496,24 @@ the files as above. Above is only for an example.
.. _tracepoint:
-Tracepoint for Monitoring Results
-=================================
+Tracepoints for Monitoring Results
+==================================
Users can get the monitoring results via the :ref:`tried_regions
-<sysfs_schemes_tried_regions>` or a tracepoint, ``damon:damon_aggregated``.
-While the tried regions directory is useful for getting a snapshot, the
-tracepoint is useful for getting a full record of the results. While the
-monitoring is turned on, you could record the tracepoint events and show
-results using tracepoint supporting tools like ``perf``. For example::
+<sysfs_schemes_tried_regions>`. The interface is useful for getting a
+snapshot, but it could be inefficient for fully recording all the monitoring
+results. For the purpose, two trace points, namely ``damon:damon_aggregated``
+and ``damon:damos_before_apply``, are provided. ``damon:damon_aggregated``
+provides the whole monitoring results, while ``damon:damos_before_apply``
+provides the monitoring results for regions that each DAMON-based Operation
+Scheme (:ref:`DAMOS <damon_design_damos>`) is gonna be applied. Hence,
+``damon:damos_before_apply`` is more useful for recording internal behavior of
+DAMOS, or DAMOS target access
+:ref:`pattern <damon_design_damos_access_pattern>` based query-like efficient
+monitoring results recording.
+
+While the monitoring is turned on, you could record the tracepoint events and
+show results using tracepoint supporting tools like ``perf``. For example::
# echo on > monitor_on
# perf record -e damon:damon_aggregated &
@@ -527,6 +536,20 @@ counter). Finally the tenth field (``X``) shows the ``age`` of the region
(refer to :ref:`design <damon_design_age_tracking>` for more details of the
counter).
+If the event was ``damon:damos_beofre_apply``, the ``perf script`` output would
+be somewhat like below::
+
+ kdamond.0 47293 [000] 80801.060214: damon:damos_before_apply: ctx_idx=0 scheme_idx=0 target_idx=0 nr_regions=11 121932607488-135128711168: 0 136
+ [...]
+
+Each line of the output represents each monitoring region that each DAMON-based
+Operation Scheme was about to be applied at the traced time. The first five
+fields are as usual. It shows the index of the DAMON context (``ctx_idx=X``)
+of the scheme in the list of the contexts of the context's kdamond, the index
+of the scheme (``scheme_idx=X``) in the list of the schemes of the context, in
+addition to the output of ``damon_aggregated`` tracepoint.
+
+
.. _debugfs_interface:
debugfs Interface (DEPRECATED!)
--
2.25.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: (no title)
2023-09-12 18:35 SeongJae Park
2023-09-12 18:35 ` [PATCH v2 1/2] mm/damon/core: add a tracepoint for damos apply target regions SeongJae Park
2023-09-12 18:35 ` [PATCH v2 2/2] Docs/admin-guide/mm/damon/usage: document damos_before_apply tracepoint SeongJae Park
@ 2023-09-13 2:19 ` SeongJae Park
2 siblings, 0 replies; 4+ messages in thread
From: SeongJae Park @ 2023-09-13 2:19 UTC (permalink / raw)
To: SeongJae Park
Cc: Andrew Morton, Jonathan Corbet, Steven Rostedt, damon, linux-mm,
linux-doc, linux-trace-kernel, linux-kernel
Hello,
On Tue, 12 Sep 2023 18:35:57 +0000 SeongJae Park <sj@kernel.org> wrote:
> Date: Tue, 12 Sep 2023 02:24:11 +0000
> Subject: [PATCH v2 0/2] mm/damon: add a tracepoint for damos apply target regions
I added a blank line in the header of the original patch, and it resulted in
this weird no-title mail, sorry. I will rebase this on latest mm-unstable and
resend.
Thanks,
SJ
>
> Changlog
> --------
>
> From v1
> (https://lore.kernel.org/damon/20230911045908.97649-1-sj@kernel.org/)
> - Get scheme/target indices only when the trace is enabled (Steven Rostedt)
>
> From RFC
> (https://lore.kernel.org/damon/20230827004045.49516-1-sj@kernel.org/)
> - Fix the 4 byte hole (Steven Rostedt)
> - Add documentation
>
> Description
> -----------
>
> 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.
>
>
> SeongJae Park (2):
> mm/damon/core: add a tracepoint for damos apply target regions
> Docs/admin-guide/mm/damon/usage: document damos_before_apply
> tracepoint
>
> Documentation/admin-guide/mm/damon/usage.rst | 37 +++++++++++++++----
> include/trace/events/damon.h | 39 ++++++++++++++++++++
> mm/damon/core.c | 32 +++++++++++++++-
> 3 files changed, 100 insertions(+), 8 deletions(-)
>
>
> base-commit: b67dc18d1406be3598248d2cc78904a81176fa13
> --
> 2.25.1
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-09-13 2:19 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-12 18:35 SeongJae Park
2023-09-12 18:35 ` [PATCH v2 1/2] mm/damon/core: add a tracepoint for damos apply target regions SeongJae Park
2023-09-12 18:35 ` [PATCH v2 2/2] Docs/admin-guide/mm/damon/usage: document damos_before_apply tracepoint SeongJae Park
2023-09-13 2:19 ` (no title) SeongJae Park
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox