linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Chao Yu <chao@kernel.org>
To: sj@kernel.org, akpm@linux-foundation.org, damon@lists.linux.dev
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	Chao Yu <chao@kernel.org>
Subject: [PATCH 2/2] mm/mm/damon/sysfs-schemes: reduce stack usage in damon_sysfs_mk_scheme()
Date: Sun, 16 Jul 2023 09:09:27 +0800	[thread overview]
Message-ID: <20230716010927.3010606-2-chao@kernel.org> (raw)
In-Reply-To: <20230716010927.3010606-1-chao@kernel.org>

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@kernel.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, &quota,
+	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



  reply	other threads:[~2023-07-16  1:09 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-16  1:09 [PATCH 1/2] mm/damon/dbgfs: reduce stack usage in str_to_schemes() Chao Yu
2023-07-16  1:09 ` Chao Yu [this message]
2023-07-17  3:41 ` Chao Yu
2023-07-17 19:12   ` SeongJae Park

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230716010927.3010606-2-chao@kernel.org \
    --to=chao@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=damon@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=sj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).