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 01E0BECAAD8 for ; Fri, 16 Sep 2022 08:57:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 805F08D0002; Fri, 16 Sep 2022 04:57:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7B5AC8D0001; Fri, 16 Sep 2022 04:57:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6A4968D0002; Fri, 16 Sep 2022 04:57:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 5C5098D0001 for ; Fri, 16 Sep 2022 04:57:35 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 2F2E71A08F1 for ; Fri, 16 Sep 2022 08:57:35 +0000 (UTC) X-FDA: 79917345270.15.236FE1E Received: from out30-56.freemail.mail.aliyun.com (out30-56.freemail.mail.aliyun.com [115.124.30.56]) by imf29.hostedemail.com (Postfix) with ESMTP id 78A041200EA for ; Fri, 16 Sep 2022 08:57:33 +0000 (UTC) X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R141e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046051;MF=xhao@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0VPwbJYY_1663318648; Received: from 30.240.97.224(mailfrom:xhao@linux.alibaba.com fp:SMTPD_---0VPwbJYY_1663318648) by smtp.aliyun-inc.com; Fri, 16 Sep 2022 16:57:29 +0800 Message-ID: <11a3021e-860b-e00e-8289-45831feed2e4@linux.alibaba.com> Date: Fri, 16 Sep 2022 16:57:27 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 Subject: Re: [PATCH V1 1/2] mm/damon/sysfs: avoid call damon_target_has_pid() repeatedly To: SeongJae Park Cc: akpm@linux-foundation.org, damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20220916084251.105360-1-sj@kernel.org> From: haoxin In-Reply-To: <20220916084251.105360-1-sj@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663318654; a=rsa-sha256; cv=none; b=Bu1u0obkDsPjadLBX8fSyMoIiEnT9K3WSpbCwc/rFbaJOqsWtTWOTL7/BZaI3/VaSBNC3O rYTfKbhH6+msoKVVejQM8deyTOTHpwk0dvQC5oNhJ23VCwapPwG6ykuI2bQaegJmAWzuLi 0HiDmBSNhgkKWT4Y7DmidVvFTifSbrE= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf29.hostedemail.com: domain of xhao@linux.alibaba.com designates 115.124.30.56 as permitted sender) smtp.mailfrom=xhao@linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663318654; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LU+4Piboq++TBvoldA/Nz5mIqVkzq1EC07LFjiSqMVc=; b=jcgy3iYP4yTuyDrGEgjIrq+R01KvmYnizbZy4yEKPBouLdF9BMX74He9a2wYELNPYaJcQQ 9gh0/f372sGs/mUkS53EfRbQvDt7M5YNJgPFpHaKCcK3O+VCU1gweeyt5IMUCKGVgMyRPv J1/2PKmZLu5Vl3tGUpA6LjZdvTi/l94= X-Stat-Signature: btwzuwjokxr93cho3t9kca6hkf6s615a X-Rspamd-Queue-Id: 78A041200EA Authentication-Results: imf29.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf29.hostedemail.com: domain of xhao@linux.alibaba.com designates 115.124.30.56 as permitted sender) smtp.mailfrom=xhao@linux.alibaba.com X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1663318653-972611 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: 在 2022/9/16 下午4:42, SeongJae Park 写道: > On Thu, 15 Sep 2022 22:22:36 +0800 Xin Hao wrote: > >> In damon_sysfs_destroy_targets(), we call damon_target_has_pid() to >> check whether the 'ctx' include a valid pid, but there no need to call >> damon_target_has_pid() to check repeatedly, just need call it once. > Good eyes, nice finding! > >> Signed-off-by: Xin Hao >> --- >> mm/damon/sysfs.c | 6 +++++- >> 1 file changed, 5 insertions(+), 1 deletion(-) >> >> diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c >> index 1fa0023f136e..966ea7892ccf 100644 >> --- a/mm/damon/sysfs.c >> +++ b/mm/damon/sysfs.c >> @@ -2143,9 +2143,13 @@ static int damon_sysfs_set_attrs(struct damon_ctx *ctx, >> static void damon_sysfs_destroy_targets(struct damon_ctx *ctx) >> { >> struct damon_target *t, *next; >> + bool has_pid = false; >> + >> + if (damon_target_has_pid(ctx)) >> + has_pid = true; > How about doing more simple and short like below? > > bool has_pid = damon_target_has_pid(ctx) Yes, Do like this, make code look more clean. but this patch has been merged into,  i send a new one to fix it ? > > Other than this, > > Reviewed-by: SeongJae Park > > > Thanks, > SJ > >> damon_for_each_target_safe(t, next, ctx) { >> - if (damon_target_has_pid(ctx)) >> + if (has_pid) >> put_pid(t->pid); >> damon_destroy_target(t); >> } >> -- >> 2.31.0