Skip to content

Commit 9732336

Browse files
sjp38akpm00
authored andcommitted
mm/damon/sysfs: update monitoring target regions for online input commit
When user input is committed online, DAMON sysfs interface is ignoring the user input for the monitoring target regions. Such request is valid and useful for fixed monitoring target regions-based monitoring ops like 'paddr' or 'fvaddr'. Update the region boundaries as user specified, too. Note that the monitoring results of the regions that overlap between the latest monitoring target regions and the new target regions are preserved. Treat empty monitoring target regions user request as a request to just make no change to the monitoring target regions. Otherwise, users should set the monitoring target regions same to current one for every online input commit, and it could be challenging for dynamic monitoring target regions update DAMON ops like 'vaddr'. If the user really need to remove all monitoring target regions, they can simply remove the target and then create the target again with empty target regions. Link: https://lkml.kernel.org/r/20231031170131.46972-1-sj@kernel.org Fixes: da87878 ("mm/damon/sysfs: support online inputs update") Signed-off-by: SeongJae Park <sj@kernel.org> Cc: <stable@vger.kernel.org> [5.19+] Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 19467a9 commit 9732336

File tree

1 file changed

+30
-17
lines changed

1 file changed

+30
-17
lines changed

mm/damon/sysfs.c

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,34 +1150,47 @@ static int damon_sysfs_add_target(struct damon_sysfs_target *sys_target,
11501150
return err;
11511151
}
11521152

1153-
static int damon_sysfs_update_target(struct damon_target *target,
1154-
struct damon_ctx *ctx,
1155-
struct damon_sysfs_target *sys_target)
1153+
static int damon_sysfs_update_target_pid(struct damon_target *target, int pid)
11561154
{
1157-
struct pid *pid;
1158-
struct damon_region *r, *next;
1159-
1160-
if (!damon_target_has_pid(ctx))
1161-
return 0;
1155+
struct pid *pid_new;
11621156

1163-
pid = find_get_pid(sys_target->pid);
1164-
if (!pid)
1157+
pid_new = find_get_pid(pid);
1158+
if (!pid_new)
11651159
return -EINVAL;
11661160

1167-
/* no change to the target */
1168-
if (pid == target->pid) {
1169-
put_pid(pid);
1161+
if (pid_new == target->pid) {
1162+
put_pid(pid_new);
11701163
return 0;
11711164
}
11721165

1173-
/* remove old monitoring results and update the target's pid */
1174-
damon_for_each_region_safe(r, next, target)
1175-
damon_destroy_region(r, target);
11761166
put_pid(target->pid);
1177-
target->pid = pid;
1167+
target->pid = pid_new;
11781168
return 0;
11791169
}
11801170

1171+
static int damon_sysfs_update_target(struct damon_target *target,
1172+
struct damon_ctx *ctx,
1173+
struct damon_sysfs_target *sys_target)
1174+
{
1175+
int err;
1176+
1177+
if (damon_target_has_pid(ctx)) {
1178+
err = damon_sysfs_update_target_pid(target, sys_target->pid);
1179+
if (err)
1180+
return err;
1181+
}
1182+
1183+
/*
1184+
* Do monitoring target region boundary update only if one or more
1185+
* regions are set by the user. This is for keeping current monitoring
1186+
* target results and range easier, especially for dynamic monitoring
1187+
* target regions update ops like 'vaddr'.
1188+
*/
1189+
if (sys_target->regions->nr)
1190+
err = damon_sysfs_set_regions(target, sys_target->regions);
1191+
return err;
1192+
}
1193+
11811194
static int damon_sysfs_set_targets(struct damon_ctx *ctx,
11821195
struct damon_sysfs_targets *sysfs_targets)
11831196
{

0 commit comments

Comments
 (0)