The patch titled Subject: mm/damon/sysfs: avoid call damon_target_has_pid() repeatedly has been added to the -mm mm-unstable branch. Its filename is mm-damon-sysfs-avoid-call-damon_target_has_pid-repeatedly.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-damon-sysfs-avoid-call-damon_target_has_pid-repeatedly.patch This patch will later appear in the mm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: Xin Hao <xhao@xxxxxxxxxxxxxxxxx> Subject: mm/damon/sysfs: avoid call damon_target_has_pid() repeatedly Date: Thu, 15 Sep 2022 22:22:36 +0800 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. Link: https://lkml.kernel.org/r/20220915142237.92529-1-xhao@xxxxxxxxxxxxxxxxx Signed-off-by: Xin Hao <xhao@xxxxxxxxxxxxxxxxx> Cc: SeongJae Park <sj@xxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- mm/damon/sysfs.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) --- a/mm/damon/sysfs.c~mm-damon-sysfs-avoid-call-damon_target_has_pid-repeatedly +++ a/mm/damon/sysfs.c @@ -2143,9 +2143,13 @@ static int damon_sysfs_set_attrs(struct 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); } _ Patches currently in -mm which might be from xhao@xxxxxxxxxxxxxxxxx are mm-damon-simply-damon_ctx-check-in-damon_sysfs_before_terminate.patch mm-damon-remove-duplicate-get_monitoring_region-definitions.patch mm-damon-sysfs-change-few-functions-execute-order.patch mm-damon-simplify-scheme-create-in-damon_lru_sort_apply_parameters.patch mm-damon-sysfs-avoid-call-damon_target_has_pid-repeatedly.patch mm-damon-core-remove-duplicate-check-about-thp.patch