Skip to content

Commit 95bc35f

Browse files
sjp38akpm00
authored andcommitted
mm/damon/sysfs: fix wrong empty schemes assumption under online tuning in damon_sysfs_set_schemes()
Commit da87878 ("mm/damon/sysfs: support online inputs update") made 'damon_sysfs_set_schemes()' to be called for running DAMON context, which could have schemes. In the case, DAMON sysfs interface is supposed to update, remove, or add schemes to reflect the sysfs files. However, the code is assuming the DAMON context wouldn't have schemes at all, and therefore creates and adds new schemes. As a result, the code doesn't work as intended for online schemes tuning and could have more than expected memory footprint. The schemes are all in the DAMON context, so it doesn't leak the memory, though. Remove the wrong asssumption (the DAMON context wouldn't have schemes) in 'damon_sysfs_set_schemes()' to fix the bug. Link: https://lkml.kernel.org/r/[email protected] Fixes: da87878 ("mm/damon/sysfs: support online inputs update") Signed-off-by: SeongJae Park <[email protected]> Cc: <[email protected]> [5.19+] Signed-off-by: Andrew Morton <[email protected]>
1 parent a435874 commit 95bc35f

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

mm/damon/sysfs.c

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2283,12 +2283,54 @@ static struct damos *damon_sysfs_mk_scheme(
22832283
&wmarks);
22842284
}
22852285

2286+
static void damon_sysfs_update_scheme(struct damos *scheme,
2287+
struct damon_sysfs_scheme *sysfs_scheme)
2288+
{
2289+
struct damon_sysfs_access_pattern *access_pattern =
2290+
sysfs_scheme->access_pattern;
2291+
struct damon_sysfs_quotas *sysfs_quotas = sysfs_scheme->quotas;
2292+
struct damon_sysfs_weights *sysfs_weights = sysfs_quotas->weights;
2293+
struct damon_sysfs_watermarks *sysfs_wmarks = sysfs_scheme->watermarks;
2294+
2295+
scheme->pattern.min_sz_region = access_pattern->sz->min;
2296+
scheme->pattern.max_sz_region = access_pattern->sz->max;
2297+
scheme->pattern.min_nr_accesses = access_pattern->nr_accesses->min;
2298+
scheme->pattern.max_nr_accesses = access_pattern->nr_accesses->max;
2299+
scheme->pattern.min_age_region = access_pattern->age->min;
2300+
scheme->pattern.max_age_region = access_pattern->age->max;
2301+
2302+
scheme->action = sysfs_scheme->action;
2303+
2304+
scheme->quota.ms = sysfs_quotas->ms;
2305+
scheme->quota.sz = sysfs_quotas->sz;
2306+
scheme->quota.reset_interval = sysfs_quotas->reset_interval_ms;
2307+
scheme->quota.weight_sz = sysfs_weights->sz;
2308+
scheme->quota.weight_nr_accesses = sysfs_weights->nr_accesses;
2309+
scheme->quota.weight_age = sysfs_weights->age;
2310+
2311+
scheme->wmarks.metric = sysfs_wmarks->metric;
2312+
scheme->wmarks.interval = sysfs_wmarks->interval_us;
2313+
scheme->wmarks.high = sysfs_wmarks->high;
2314+
scheme->wmarks.mid = sysfs_wmarks->mid;
2315+
scheme->wmarks.low = sysfs_wmarks->low;
2316+
}
2317+
22862318
static int damon_sysfs_set_schemes(struct damon_ctx *ctx,
22872319
struct damon_sysfs_schemes *sysfs_schemes)
22882320
{
2289-
int i;
2321+
struct damos *scheme, *next;
2322+
int i = 0;
2323+
2324+
damon_for_each_scheme_safe(scheme, next, ctx) {
2325+
if (i < sysfs_schemes->nr)
2326+
damon_sysfs_update_scheme(scheme,
2327+
sysfs_schemes->schemes_arr[i]);
2328+
else
2329+
damon_destroy_scheme(scheme);
2330+
i++;
2331+
}
22902332

2291-
for (i = 0; i < sysfs_schemes->nr; i++) {
2333+
for (; i < sysfs_schemes->nr; i++) {
22922334
struct damos *scheme, *next;
22932335

22942336
scheme = damon_sysfs_mk_scheme(sysfs_schemes->schemes_arr[i]);

0 commit comments

Comments
 (0)