Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp927812rwn; Thu, 15 Sep 2022 08:14:36 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5OFHbfotk/B/UAya5K8lTKatKc+Yd8ljB83V2j8SsYHE9nGkFj6SXRtoXSiklvtNDQLy4y X-Received: by 2002:a17:902:bb95:b0:16e:e3f4:8195 with SMTP id m21-20020a170902bb9500b0016ee3f48195mr68161pls.130.1663254876607; Thu, 15 Sep 2022 08:14:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663254876; cv=none; d=google.com; s=arc-20160816; b=v62q8FJCECKMxspElXtznatoC0OV0KcfubRLXII06IszA9fSI5qOrSuS7KOuqsGscU lmylgImDlMULKUG2JUzWvGIHtAa2qqbNOldMrIiU+imQxB+kvtlzUzF3drET6x2PTnuy rxMzc2lp7BpBYy6ZEds6rjTVlTxtO9nFExUVCpQkQse07qrMerKd0HA2EGnSVgb12BY9 J8sdWNT5HtCWfRhIZyYvmmN3tUzL1gPA33lFP4PRJoWP2K2uBqBKvnze2206PY5JWCKF OdVjt98dZRGi76L3WKqUFCheYfNsAdbIJ311jtVkiH+GYF6ydMCI/1Tcj1unmcBy/WDO mp7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=YGX0qqHINZSvQn/Aynq7haqpeyNmGTocKK3IOmDyAVE=; b=0KC+mManSNvypJ5htIsrdRX4MgWohbj+5SCsfUa33E4KUUNOrKlV/gdbzv+c+OEJdr VVXIQ9gb07G+HECHBd8ofTchF69JO+GSL8raFJ52p7Gg/wVtFn9ivmkANAMn+OYb9LlQ 0m/hJbQ9/kGCaDMXYPE669HF0vcvmuseMh6bwQqsuYrox2FlrcFqS/2wDyNeE3vTLMRg acmqJNiTXJKnxRh9aOE1hfY+KQwDX4E3CnaHaYkcYjUDRu9bGmdZRP0t5mChdSwYHkt+ siydNUagtKJ067Xl6Zhn52KEcEw2otJgFOSsOS0ytz8Ou7Wmv91qfy9o7dKzfXSC1BRE ljAA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k2-20020a056a00134200b0051873a68dd2si19648956pfu.252.2022.09.15.08.14.23; Thu, 15 Sep 2022 08:14:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229658AbiIOOWs (ORCPT + 99 others); Thu, 15 Sep 2022 10:22:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229820AbiIOOWr (ORCPT ); Thu, 15 Sep 2022 10:22:47 -0400 Received: from out30-133.freemail.mail.aliyun.com (out30-133.freemail.mail.aliyun.com [115.124.30.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BA5933360 for ; Thu, 15 Sep 2022 07:22:44 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R201e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046060;MF=xhao@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0VPtLfjQ_1663251759; Received: from localhost.localdomain(mailfrom:xhao@linux.alibaba.com fp:SMTPD_---0VPtLfjQ_1663251759) by smtp.aliyun-inc.com; Thu, 15 Sep 2022 22:22:40 +0800 From: Xin Hao To: sj@kernel.org Cc: akpm@linux-foundation.org, damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, xhao@linux.alibaba.com Subject: [PATCH V1 1/2] mm/damon/sysfs: avoid call damon_target_has_pid() repeatedly Date: Thu, 15 Sep 2022 22:22:36 +0800 Message-Id: <20220915142237.92529-1-xhao@linux.alibaba.com> X-Mailer: git-send-email 2.31.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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; 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