History

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.

Kaixu Xia committed 4 years ago

Commit c274cd51 parent 8eeda551 file · +7 −18Browse files

Unified · Split

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

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t