From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 920BEC433EF for ; Mon, 6 Dec 2021 12:48:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0184A6B007B; Mon, 6 Dec 2021 07:48:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EE37D6B007D; Mon, 6 Dec 2021 07:48:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D846D6B007E; Mon, 6 Dec 2021 07:48:36 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0032.hostedemail.com [216.40.44.32]) by kanga.kvack.org (Postfix) with ESMTP id C9C256B007B for ; Mon, 6 Dec 2021 07:48:36 -0500 (EST) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 7A981181327CF for ; Mon, 6 Dec 2021 12:48:26 +0000 (UTC) X-FDA: 78887347812.21.37ACA4D Received: from out30-133.freemail.mail.aliyun.com (out30-133.freemail.mail.aliyun.com [115.124.30.133]) by imf26.hostedemail.com (Postfix) with ESMTP id 37DB620019D7 for ; Mon, 6 Dec 2021 12:48:24 +0000 (UTC) X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R431e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04423;MF=xhao@linux.alibaba.com;NM=1;PH=DS;RN=4;SR=0;TI=SMTPD_---0UzdP5yc_1638794898; Received: from B-X3VXMD6M-2058.local(mailfrom:xhao@linux.alibaba.com fp:SMTPD_---0UzdP5yc_1638794898) by smtp.aliyun-inc.com(127.0.0.1); Mon, 06 Dec 2021 20:48:20 +0800 From: Xin Hao Reply-To: xhao@linux.alibaba.com Subject: Re: [PATCH V1] mm/damon: Modify damon_rand() macro to static inline function To: SeongJae Park Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20211206124523.6259-1-sj@kernel.org> Message-ID: <08a13269-e3eb-219f-79bb-8d0153714c69@linux.alibaba.com> Date: Mon, 6 Dec 2021 20:48:18 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: <20211206124523.6259-1-sj@kernel.org> Content-Type: text/plain; charset=utf-8; format=flowed X-Rspamd-Queue-Id: 37DB620019D7 Authentication-Results: imf26.hostedemail.com; dkim=none; spf=pass (imf26.hostedemail.com: domain of xhao@linux.alibaba.com designates 115.124.30.133 as permitted sender) smtp.mailfrom=xhao@linux.alibaba.com; dmarc=pass (policy=none) header.from=alibaba.com X-Rspamd-Server: rspam04 X-Stat-Signature: s6cpd4r9opiq7r5c6m1jq5bp74ojkh5o X-HE-Tag: 1638794904-542532 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 12/6/21 8:45 PM, SeongJae Park wrote: > On Mon, 6 Dec 2021 20:41:29 +0800 Xin Hao wrot= e: > >> The damon_rand() func can not be implemented as a macro. >> Example: >> damon_rand(a++, b); >> The value of 'a' will be incremented twice, This is obviously >> unreasonable, So there fix it. >> >> Fixes: b9a6ac4e4ede ("mm/damon: adaptively adjust regions") >> Reported-by: Andrew Morton >> Signed-off-by: Xin Hao >> --- >> include/linux/damon.h | 5 ++++- >> 1 file changed, 4 insertions(+), 1 deletion(-) >> >> diff --git a/include/linux/damon.h b/include/linux/damon.h >> index c6df025d8704..bc9c8932b1e8 100644 >> --- a/include/linux/damon.h >> +++ b/include/linux/damon.h >> @@ -19,7 +19,10 @@ >> #define DAMOS_MAX_SCORE (99) >> >> /* Get a random number in [l, r) */ >> -#define damon_rand(l, r) (l + prandom_u32_max(r - l)) >> +static inline unsigned long damon_rand(unsigned long l, unsigned long= r) >> +{ >> + return l + (r - l); > Seems prandom_u32_max() is missed? Sorry, my fault, i write a simple test case like this, but i forgot to=20 correct in patch, i will send a new one. #include #define damon_rand(l, r) (l + (r - l)) static inline long damon_rand1(int l, int r) { =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return l + (r - l); } int main(void) { =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 int a =3D 0; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 int b =3D 0; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 damon_rand(a++, 4); =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 damon_rand1(b++, 4); =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 printf("a is %d \n", a); =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 printf("b is %d \n", b); =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return 0; } > > > Thanks, > SJ > >> +} >> >> /** >> * struct damon_addr_range - Represents an address region of [@start= , @end). >> -- >> 2.31.0 --=20 Best Regards! Xin Hao