From: SeongJae Park <sj@kernel.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: SeongJae Park <sj@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
damon@lists.linux.dev, linux-mm@kvack.org,
linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] mm/damon/core: add a tracepoint for damos apply target regions
Date: Mon, 11 Sep 2023 19:05:04 +0000 [thread overview]
Message-ID: <20230911190504.102317-1-sj@kernel.org> (raw)
In-Reply-To: <20230911141955.245d1397@gandalf.local.home>
Hi Steven,
On Mon, 11 Sep 2023 14:19:55 -0400 Steven Rostedt <rostedt@goodmis.org> wrote:
> On Mon, 11 Sep 2023 04:59:07 +0000
> SeongJae Park <sj@kernel.org> wrote:
>
> > --- a/mm/damon/core.c
> > +++ b/mm/damon/core.c
> > @@ -950,6 +950,28 @@ 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;
> > +
>
> If this loop is only for passing sidx and tidx to the trace point,
You're correct.
> you can add around it:
>
> 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++;
> > + }
>
> }
>
>
> And then this loop will only be done if that trace event is enabled.
Today I learned yet another great feature of the tracing framework. Thank you
Steven, I will add that to the next spin of this patchset!
>
> To prevent races, you may also want to add a third parameter, or initialize
> them to -1:
>
> sidx = -1;
>
> if (trace_damo_before_apply_enabled()) {
> sidx = 0;
> [..]
> }
>
> And you can change the TRACE_EVENT() TO TRACE_EVENT_CONDITION():
>
> TRACE_EVENT_CONDITION(damos_before_apply,
>
> TP_PROTO(...),
>
> TP_ARGS(...),
>
> TP_CONDITION(sidx >= 0),
>
> and the trace event will not be called if sidx is less than zero.
>
> Also, this if statement is only done when the trace event is enabled, so
> it's equivalent to:
>
> if (trace_damos_before_apply_enabled()) {
> if (sdx >= 0)
> trace_damos_before_apply(cidx, sidx, tidx, r,
> damon_nr_regions(t));
> }
Again, thank you very much for letting me know this awesome feature. However,
sidx is supposed to be always >=0 here, since kdamond is running in single
thread and hence no race is expected. If it exists, it's a bug. So, I
wouldn't make this change. Appreciate again for letting me know this very
useful feature, and please let me know if I'm missing something, though!
Thanks,
SJ
>
> -- Steve
>
>
>
> >
> > if (c->ops.apply_scheme) {
> > if (quota->esz && quota->charged_sz + sz > quota->esz) {
> > @@ -964,8 +986,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));
> > 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);
> > --
>
next prev parent reply other threads:[~2023-09-11 22:43 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-11 4:59 [PATCH 0/2] mm/damon: add a tracepoint for damos apply target regions SeongJae Park
2023-09-11 4:59 ` [PATCH 1/2] mm/damon/core: " SeongJae Park
2023-09-11 18:19 ` Steven Rostedt
2023-09-11 19:05 ` SeongJae Park [this message]
2023-09-11 20:31 ` Steven Rostedt
2023-09-11 20:36 ` SeongJae Park
2023-09-11 20:51 ` Steven Rostedt
2023-09-12 1:43 ` SeongJae Park
2023-09-12 1:56 ` Steven Rostedt
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=20230911190504.102317-1-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 \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=rostedt@goodmis.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).