Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mm/damon/sysfs: simplify the judgement whether kdamonds are busy

It is unnecessary to get the number of the running kdamond to judge
whether kdamonds are busy. Here we can use the
damon_sysfs_kdamond_running() helper and return -EBUSY directly when
finding a running kdamond. Meanwhile, merging with the judgement that a
kdamond has current sysfs command callback request to make the code more
clear.

Link: https://lkml.kernel.org/r/1662302166-13216-1-git-send-email-kaixuxia@tencent.com
Signed-off-by: Kaixu Xia <kaixuxia@tencent.com>
Reviewed-by: SeongJae Park <sj@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Kaixu Xia and committed by
Andrew Morton
c274cd5c 8eeda55f

+7 -18
+7 -18
mm/damon/sysfs.c
··· 2657 2657 kdamonds->kdamonds_arr = NULL; 2658 2658 } 2659 2659 2660 - static int damon_sysfs_nr_running_ctxs(struct damon_sysfs_kdamond **kdamonds, 2660 + static bool damon_sysfs_kdamonds_busy(struct damon_sysfs_kdamond **kdamonds, 2661 2661 int nr_kdamonds) 2662 2662 { 2663 - int nr_running_ctxs = 0; 2664 2663 int i; 2665 2664 2666 2665 for (i = 0; i < nr_kdamonds; i++) { 2667 - struct damon_ctx *ctx = kdamonds[i]->damon_ctx; 2668 - 2669 - if (!ctx) 2670 - continue; 2671 - mutex_lock(&ctx->kdamond_lock); 2672 - if (ctx->kdamond) 2673 - nr_running_ctxs++; 2674 - mutex_unlock(&ctx->kdamond_lock); 2666 + if (damon_sysfs_kdamond_running(kdamonds[i]) || 2667 + damon_sysfs_cmd_request.kdamond == kdamonds[i]) 2668 + return true; 2675 2669 } 2676 - return nr_running_ctxs; 2670 + 2671 + return false; 2677 2672 } 2678 2673 2679 2674 static int damon_sysfs_kdamonds_add_dirs(struct damon_sysfs_kdamonds *kdamonds, ··· 2677 2682 struct damon_sysfs_kdamond **kdamonds_arr, *kdamond; 2678 2683 int err, i; 2679 2684 2680 - if (damon_sysfs_nr_running_ctxs(kdamonds->kdamonds_arr, kdamonds->nr)) 2685 + if (damon_sysfs_kdamonds_busy(kdamonds->kdamonds_arr, kdamonds->nr)) 2681 2686 return -EBUSY; 2682 - 2683 - for (i = 0; i < kdamonds->nr; i++) { 2684 - if (damon_sysfs_cmd_request.kdamond == 2685 - kdamonds->kdamonds_arr[i]) 2686 - return -EBUSY; 2687 - } 2688 2687 2689 2688 damon_sysfs_kdamonds_rm_dirs(kdamonds); 2690 2689 if (!nr_kdamonds)