]> git.baikalelectronics.ru Git - kernel.git/commitdiff
mm/damon/sysfs: avoid call damon_target_has_pid() repeatedly
authorXin Hao <xhao@linux.alibaba.com>
Thu, 15 Sep 2022 14:22:36 +0000 (22:22 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Mon, 3 Oct 2022 21:03:26 +0000 (14:03 -0700)
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.

[xhao@linux.alibaba.com: more simplified code calls damon_target_has_pid()]
Link: https://lkml.kernel.org/r/20220916133535.7428-1-xhao@linux.alibaba.com
Link: https://lkml.kernel.org/r/20220915142237.92529-1-xhao@linux.alibaba.com
Signed-off-by: Xin Hao <xhao@linux.alibaba.com>
Reviewed-by: SeongJae Park <sj@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/damon/sysfs.c

index 1fa0023f136eb7b9b1b949fa67302166004ab682..0cca1909bf67bc56b8f47d59062bfbcaf2ccf2ee 100644 (file)
@@ -2143,9 +2143,10 @@ 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 = damon_target_has_pid(ctx);
 
        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);
        }