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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D30DEC54EE9 for ; Fri, 16 Sep 2022 08:57:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230137AbiIPI5h (ORCPT ); Fri, 16 Sep 2022 04:57:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229621AbiIPI5d (ORCPT ); Fri, 16 Sep 2022 04:57:33 -0400 Received: from out30-42.freemail.mail.aliyun.com (out30-42.freemail.mail.aliyun.com [115.124.30.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44349A1D7F for ; Fri, 16 Sep 2022 01:57:32 -0700 (PDT) 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 在 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