[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230716010927.3010606-2-chao@kernel.org>
Date: Sun, 16 Jul 2023 09:09:27 +0800
From: Chao Yu <chao@...nel.org>
To: sj@...nel.org, akpm@...ux-foundation.org, damon@...ts.linux.dev
Cc: linux-mm@...ck.org, linux-kernel@...r.kernel.org,
Chao Yu <chao@...nel.org>
Subject: [PATCH 2/2] mm/mm/damon/sysfs-schemes: reduce stack usage in damon_sysfs_mk_scheme()
struct damos_quota quota caused the stack usage of damon_sysfs_mk_scheme()
to grow beyond the warning limit on 32-bit architectures w/ gcc.
mm/damon/sysfs-schemes.c: In function ‘damon_sysfs_mk_scheme’:
mm/damon/sysfs-schemes.c:1526:1: warning: the frame size of 1280 bytes is larger than 1024 bytes [-Wframe-larger-than=]
Allocating dynamic memory in damon_sysfs_mk_scheme() to fix this issue.
Signed-off-by: Chao Yu <chao@...nel.org>
---
mm/damon/sysfs-schemes.c | 29 +++++++++++++++++++----------
1 file changed, 19 insertions(+), 10 deletions(-)
diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c
index 50cf89dcd898..35fa1b421c26 100644
--- a/mm/damon/sysfs-schemes.c
+++ b/mm/damon/sysfs-schemes.c
@@ -1486,6 +1486,7 @@ static struct damos *damon_sysfs_mk_scheme(
struct damon_sysfs_scheme_filters *sysfs_filters =
sysfs_scheme->filters;
struct damos *scheme;
+ struct damos_quota *quota;
int err;
struct damos_access_pattern pattern = {
@@ -1496,14 +1497,6 @@ static struct damos *damon_sysfs_mk_scheme(
.min_age_region = access_pattern->age->min,
.max_age_region = access_pattern->age->max,
};
- struct damos_quota quota = {
- .ms = sysfs_quotas->ms,
- .sz = sysfs_quotas->sz,
- .reset_interval = sysfs_quotas->reset_interval_ms,
- .weight_sz = sysfs_weights->sz,
- .weight_nr_accesses = sysfs_weights->nr_accesses,
- .weight_age = sysfs_weights->age,
- };
struct damos_watermarks wmarks = {
.metric = sysfs_wmarks->metric,
.interval = sysfs_wmarks->interval_us,
@@ -1512,16 +1505,32 @@ static struct damos *damon_sysfs_mk_scheme(
.low = sysfs_wmarks->low,
};
- scheme = damon_new_scheme(&pattern, sysfs_scheme->action, "a,
+ quota = kmalloc(sizeof(struct damos_quota), GFP_KERNEL);
+ if (!quota)
+ return NULL;
+
+ quota->ms = sysfs_quotas->ms;
+ quota->sz = sysfs_quotas->sz;
+ quota->reset_interval = sysfs_quotas->reset_interval_ms;
+ quota->weight_sz = sysfs_weights->sz;
+ quota->weight_nr_accesses = sysfs_weights->nr_accesses;
+ quota->weight_age = sysfs_weights->age;
+
+ scheme = damon_new_scheme(&pattern, sysfs_scheme->action, quota,
&wmarks);
- if (!scheme)
+ if (!scheme) {
+ kfree(quota);
return NULL;
+ }
err = damon_sysfs_set_scheme_filters(scheme, sysfs_filters);
if (err) {
+ kfree(quota);
damon_destroy_scheme(scheme);
return NULL;
}
+
+ kfree(quota);
return scheme;
}
--
2.40.1
Powered by blists - more mailing lists