All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V1 1/2] mm/damon/sysfs: avoid call damon_target_has_pid() repeatedly
@ 2022-09-15 14:22 Xin Hao
  2022-09-15 14:22 ` [PATCH V1 2/2] mm/damon/core: remove duplicate check about THP Xin Hao
  2022-09-16  8:42 ` [PATCH V1 1/2] mm/damon/sysfs: avoid call damon_target_has_pid() repeatedly SeongJae Park
  0 siblings, 2 replies; 10+ messages in thread
From: Xin Hao @ 2022-09-15 14:22 UTC (permalink / raw)
  To: sj; +Cc: akpm, damon, linux-mm, linux-kernel, xhao

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 <xhao@linux.alibaba.com>
---
 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

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-09-16  8:57 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-15 14:22 [PATCH V1 1/2] mm/damon/sysfs: avoid call damon_target_has_pid() repeatedly Xin Hao
2022-09-15 14:22 ` [PATCH V1 2/2] mm/damon/core: remove duplicate check about THP Xin Hao
2022-09-15 21:54   ` kernel test robot
2022-09-15 22:26     ` Andrew Morton
2022-09-15 22:26       ` Andrew Morton
2022-09-16  1:37       ` haoxin
2022-09-16  1:37         ` haoxin
2022-09-15 22:16   ` kernel test robot
2022-09-16  8:42 ` [PATCH V1 1/2] mm/damon/sysfs: avoid call damon_target_has_pid() repeatedly SeongJae Park
2022-09-16  8:57   ` haoxin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.