From patchwork Mon Dec 6 12:52:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: haoxin X-Patchwork-Id: 12658271 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 DF6FEC433EF for ; Mon, 6 Dec 2021 12:53:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6F1596B007B; Mon, 6 Dec 2021 07:53:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6A14D6B007D; Mon, 6 Dec 2021 07:53:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 590B86B007E; Mon, 6 Dec 2021 07:53:02 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0008.hostedemail.com [216.40.44.8]) by kanga.kvack.org (Postfix) with ESMTP id 49D846B007B for ; Mon, 6 Dec 2021 07:53:02 -0500 (EST) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 0DC14183084A0 for ; Mon, 6 Dec 2021 12:52:52 +0000 (UTC) X-FDA: 78887358984.18.B233BB9 Received: from out30-43.freemail.mail.aliyun.com (out30-43.freemail.mail.aliyun.com [115.124.30.43]) by imf01.hostedemail.com (Postfix) with ESMTP id 274FF40005 for ; Mon, 6 Dec 2021 12:52:49 +0000 (UTC) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R131e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04394;MF=xhao@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0UzdP6MJ_1638795164; Received: from localhost.localdomain(mailfrom:xhao@linux.alibaba.com fp:SMTPD_---0UzdP6MJ_1638795164) by smtp.aliyun-inc.com(127.0.0.1); Mon, 06 Dec 2021 20:52:45 +0800 From: Xin Hao To: sj@kernel.org Cc: xhao@linux.alibaba.com, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH V2] mm/damon: Modify damon_rand() macro to static inline function Date: Mon, 6 Dec 2021 20:52:43 +0800 Message-Id: <110ffcd4e420c86c42b41ce2bc9f0fe6a4f32cd3.1638795127.git.xhao@linux.alibaba.com> X-Mailer: git-send-email 2.31.0 MIME-Version: 1.0 Authentication-Results: imf01.hostedemail.com; dkim=none; spf=pass (imf01.hostedemail.com: domain of xhao@linux.alibaba.com designates 115.124.30.43 as permitted sender) smtp.mailfrom=xhao@linux.alibaba.com; dmarc=pass (policy=none) header.from=alibaba.com X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 274FF40005 X-Stat-Signature: 6crxxi9g3wfjes6z4osxfc15dh3k45xu X-HE-Tag: 1638795169-758576 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: 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 Reviewed-by: SeongJae Park --- include/linux/damon.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) -- 2.31.0 diff --git a/include/linux/damon.h b/include/linux/damon.h index c6df025d8704..a58046cd45e6 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 + prandom_u32_max(r - l); +} /** * struct damon_addr_range - Represents an address region of [@start, @end).