mm/damon/core: copy struct-to-struct instead of field-to-field in damon_new_scheme()
authorSeongJae Park <sj@kernel.org>
Tue, 13 Sep 2022 17:44:30 +0000 (17:44 +0000)
committerAndrew Morton <akpm@linux-foundation.org>
Mon, 3 Oct 2022 21:03:10 +0000 (14:03 -0700)
The function for new 'struct damos' creation, 'damon_new_scheme()', copies
each field of the struct one by one, though it could simply copied via
struct to struct.  This commit replaces the unnecessarily verbose
field-to-field copies with struct-to-struct copies to make code simple and
short.

Link: https://lkml.kernel.org/r/20220913174449.50645-4-sj@kernel.org
Signed-off-by: SeongJae Park <sj@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/damon/core.c

index c9ec2de..a564f83 100644 (file)
@@ -272,22 +272,13 @@ struct damos *damon_new_scheme(struct damos_access_pattern *pattern,
        scheme = kmalloc(sizeof(*scheme), GFP_KERNEL);
        if (!scheme)
                return NULL;
-       scheme->pattern.min_sz_region = pattern->min_sz_region;
-       scheme->pattern.max_sz_region = pattern->max_sz_region;
-       scheme->pattern.min_nr_accesses = pattern->min_nr_accesses;
-       scheme->pattern.max_nr_accesses = pattern->max_nr_accesses;
-       scheme->pattern.min_age_region = pattern->min_age_region;
-       scheme->pattern.max_age_region = pattern->max_age_region;
+       scheme->pattern = *pattern;
        scheme->action = action;
        scheme->stat = (struct damos_stat){};
        INIT_LIST_HEAD(&scheme->list);
 
-       scheme->quota.ms = quota->ms;
-       scheme->quota.sz = quota->sz;
-       scheme->quota.reset_interval = quota->reset_interval;
-       scheme->quota.weight_sz = quota->weight_sz;
-       scheme->quota.weight_nr_accesses = quota->weight_nr_accesses;
-       scheme->quota.weight_age = quota->weight_age;
+       scheme->quota = *quota;
+       /* caller might not zero-initialized the private fileds */
        scheme->quota.total_charged_sz = 0;
        scheme->quota.total_charged_ns = 0;
        scheme->quota.esz = 0;
@@ -296,11 +287,7 @@ struct damos *damon_new_scheme(struct damos_access_pattern *pattern,
        scheme->quota.charge_target_from = NULL;
        scheme->quota.charge_addr_from = 0;
 
-       scheme->wmarks.metric = wmarks->metric;
-       scheme->wmarks.interval = wmarks->interval;
-       scheme->wmarks.high = wmarks->high;
-       scheme->wmarks.mid = wmarks->mid;
-       scheme->wmarks.low = wmarks->low;
+       scheme->wmarks = *wmarks;
        scheme->wmarks.activated = true;
 
        return scheme;