From: SeongJae Park <sj@kernel.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Xin Hao <xhao@linux.alibaba.com>,
sj@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH RESEND MERGE REQUEST] mm/damon: move damon_rand() definition into damon.h
Date: Fri, 3 Dec 2021 09:19:36 +0000 [thread overview]
Message-ID: <20211203091936.19804-1-sj@kernel.org> (raw)
In-Reply-To: <20211202151213.6ec830863342220da4141bc5@linux-foundation.org>
On Thu, 2 Dec 2021 15:12:13 -0800 Andrew Morton <akpm@linux-foundation.org> wrote:
> On Thu, 2 Dec 2021 15:58:59 +0800 Xin Hao <xhao@linux.alibaba.com> wrote:
>
> > damon_rand() is called in three files:damon/core.c, damon/
> > paddr.c, damon/vaddr.c, i think there is no need to redefine
> > this twice, So move it to damon.h will be a good choice.
>
> Fair enough.
>
> > +/* Get a random number in [l, r) */
> > +#define damon_rand(l, r) (l + prandom_u32_max(r - l))
>
> This shouldn't be implemented as a macro, for all the usual reasons
> (typechecking, side-effects, ugliness, code-documentation site, etc).
Yes, agreed.
>
> In particular, this expression references `l' twice, so calling
>
> damon_rand(a++, b);
>
> will increment `a' twice, surprise surprise.
Thank you for this nice explanation.
>
> Can someone please send a followup patch to convert this (and any
> similar damon macros) into (probably static inlined) C functions?
Sure, I will do, unless someone shows interest here.
Thanks,
SJ
next prev parent reply other threads:[~2021-12-03 9:20 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-02 7:58 Xin Hao
2021-12-02 23:12 ` Andrew Morton
2021-12-03 9:19 ` SeongJae Park [this message]
2021-12-06 5:20 ` Xin Hao
2021-12-06 6:28 ` SeongJae Park
2021-12-06 7:44 ` Xin Hao
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=20211203091936.19804-1-sj@kernel.org \
--to=sj@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=xhao@linux.alibaba.com \
/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