Skip to content

Commit e035c28

Browse files
sjp38akpm00
authored andcommitted
mm/damon/reclaim: support online inputs update
DAMON_RECLAIM reads the user input parameters only when it starts. To allow more efficient online tuning, this commit implements a new input parameter called 'commit_inputs'. Writing true to the parameter makes DAMON_RECLAIM reads the input parameters again. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: SeongJae Park <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent adc286e commit e035c28

File tree

1 file changed

+62
-33
lines changed

1 file changed

+62
-33
lines changed

mm/damon/reclaim.c

Lines changed: 62 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@
2929
*/
3030
static bool enabled __read_mostly;
3131

32+
/*
33+
* Make DAMON_RECLAIM reads the input parameters again, except ``enabled``.
34+
*
35+
* Input parameters that updated while DAMON_RECLAIM is running are not applied
36+
* by default. Once this parameter is set as ``Y``, DAMON_RECLAIM reads values
37+
* of parametrs except ``enabled`` again. Once the re-reading is done, this
38+
* parameter is set as ``N``. If invalid parameters are found while the
39+
* re-reading, DAMON_RECLAIM will be disabled.
40+
*/
41+
static bool commit_inputs __read_mostly;
42+
module_param(commit_inputs, bool, 0600);
43+
3244
/*
3345
* Time threshold for cold memory regions identification in microseconds.
3446
*
@@ -289,57 +301,56 @@ static struct damos *damon_reclaim_new_scheme(void)
289301
return scheme;
290302
}
291303

292-
static int damon_reclaim_turn(bool on)
304+
static int damon_reclaim_apply_parameters(void)
293305
{
294-
struct damon_region *region;
295306
struct damos *scheme;
296-
int err;
297-
298-
if (!on) {
299-
err = damon_stop(&ctx, 1);
300-
if (!err)
301-
kdamond_pid = -1;
302-
return err;
303-
}
307+
struct damon_addr_range addr_range;
308+
int err = 0;
304309

305310
err = damon_set_attrs(ctx, sample_interval, aggr_interval, 0,
306311
min_nr_regions, max_nr_regions);
307312
if (err)
308313
return err;
309314

315+
/* Will be freed by next 'damon_set_schemes()' below */
316+
scheme = damon_reclaim_new_scheme();
317+
if (!scheme)
318+
return -ENOMEM;
319+
err = damon_set_schemes(ctx, &scheme, 1);
320+
if (err)
321+
return err;
322+
310323
if (monitor_region_start > monitor_region_end)
311324
return -EINVAL;
312325
if (!monitor_region_start && !monitor_region_end &&
313326
!get_monitoring_region(&monitor_region_start,
314327
&monitor_region_end))
315328
return -EINVAL;
316-
/* DAMON will free this on its own when finish monitoring */
317-
region = damon_new_region(monitor_region_start, monitor_region_end);
318-
if (!region)
319-
return -ENOMEM;
320-
damon_add_region(region, target);
329+
addr_range.start = monitor_region_start;
330+
addr_range.end = monitor_region_end;
331+
return damon_set_regions(target, &addr_range, 1);
332+
}
321333

322-
/* Will be freed by 'damon_set_schemes()' below */
323-
scheme = damon_reclaim_new_scheme();
324-
if (!scheme) {
325-
err = -ENOMEM;
326-
goto free_region_out;
334+
static int damon_reclaim_turn(bool on)
335+
{
336+
int err;
337+
338+
if (!on) {
339+
err = damon_stop(&ctx, 1);
340+
if (!err)
341+
kdamond_pid = -1;
342+
return err;
327343
}
328-
err = damon_set_schemes(ctx, &scheme, 1);
344+
345+
err = damon_reclaim_apply_parameters();
329346
if (err)
330-
goto free_scheme_out;
347+
return err;
331348

332349
err = damon_start(&ctx, 1, true);
333-
if (!err) {
334-
kdamond_pid = ctx->kdamond->pid;
335-
return 0;
336-
}
337-
338-
free_scheme_out:
339-
damon_destroy_scheme(scheme);
340-
free_region_out:
341-
damon_destroy_region(region, target);
342-
return err;
350+
if (err)
351+
return err;
352+
kdamond_pid = ctx->kdamond->pid;
353+
return 0;
343354
}
344355

345356
#define ENABLE_CHECK_INTERVAL_MS 1000
@@ -389,6 +400,7 @@ MODULE_PARM_DESC(enabled,
389400
static int damon_reclaim_after_aggregation(struct damon_ctx *c)
390401
{
391402
struct damos *s;
403+
int err = 0;
392404

393405
/* update the stats parameter */
394406
damon_for_each_scheme(s, c) {
@@ -398,7 +410,23 @@ static int damon_reclaim_after_aggregation(struct damon_ctx *c)
398410
bytes_reclaimed_regions = s->stat.sz_applied;
399411
nr_quota_exceeds = s->stat.qt_exceeds;
400412
}
401-
return 0;
413+
414+
if (commit_inputs) {
415+
err = damon_reclaim_apply_parameters();
416+
commit_inputs = false;
417+
}
418+
return err;
419+
}
420+
421+
static int damon_reclaim_after_wmarks_check(struct damon_ctx *c)
422+
{
423+
int err = 0;
424+
425+
if (commit_inputs) {
426+
err = damon_reclaim_apply_parameters();
427+
commit_inputs = false;
428+
}
429+
return err;
402430
}
403431

404432
static int __init damon_reclaim_init(void)
@@ -410,6 +438,7 @@ static int __init damon_reclaim_init(void)
410438
if (damon_select_ops(ctx, DAMON_OPS_PADDR))
411439
return -EINVAL;
412440

441+
ctx->callback.after_wmarks_check = damon_reclaim_after_wmarks_check;
413442
ctx->callback.after_aggregation = damon_reclaim_after_aggregation;
414443

415444
target = damon_new_target();

0 commit comments

Comments
 (0)