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
26572657 kdamonds->kdamonds_arr = NULL;
26582658 }
26592659
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,
26612661 int nr_kdamonds)
26622662 {
2663− int nr_running_ctxs = 0;
26642663 int i;
26652664
26662665 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;
26752669 }
2676− return nr_running_ctxs;
2670+
2671+ return false;
26772672 }
26782673
26792674 static 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
26822677 struct damon_sysfs_kdamond **kdamonds_arr, *kdamond;
26832678 int err, i;
26842679
2685− if (damon_sysfs_nr_running_ctxs(kdamonds->kdamonds_arr, kdamonds->nr))
2680+ if (damon_sysfs_kdamonds_busy(kdamonds->kdamonds_arr, kdamonds->nr))
26862681 return -EBUSY;
26872682
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−
26942683 damon_sysfs_kdamonds_rm_dirs(kdamonds);
26952684 if (!nr_kdamonds)
26962685 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