linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] mm/damon/dbgfs: reduce stack usage in str_to_schemes()
@ 2023-07-16  1:09 Chao Yu
  2023-07-16  1:09 ` [PATCH 2/2] mm/mm/damon/sysfs-schemes: reduce stack usage in damon_sysfs_mk_scheme() Chao Yu
  2023-07-17  3:41 ` [PATCH 1/2] mm/damon/dbgfs: reduce stack usage in str_to_schemes() Chao Yu
  0 siblings, 2 replies; 4+ messages in thread
From: Chao Yu @ 2023-07-16  1:09 UTC (permalink / raw)
  To: sj, akpm, damon; +Cc: linux-mm, linux-kernel, Chao Yu

struct damos_quota quota caused the stack usage of str_to_schemes() to
grow beyond the warning limit on 32-bit architectures w/ gcc.

mm/damon/dbgfs.c: In function ‘str_to_schemes’:
mm/damon/dbgfs.c:292:1: warning: the frame size of 1496 bytes is larger than 1024 bytes [-Wframe-larger-than=]

Allocating dynamic memory in str_to_schemes() to fix this issue.

Signed-off-by: Chao Yu <chao@kernel.org>
---
 mm/damon/dbgfs.c | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/mm/damon/dbgfs.c b/mm/damon/dbgfs.c
index 124f0f8c97b7..78acc7366895 100644
--- a/mm/damon/dbgfs.c
+++ b/mm/damon/dbgfs.c
@@ -237,18 +237,26 @@ static struct damos **str_to_schemes(const char *str, ssize_t len,
 	int pos = 0, parsed, ret;
 	unsigned int action_input;
 	enum damos_action action;
+	struct damos_quota *quota;
 
 	schemes = kmalloc_array(max_nr_schemes, sizeof(scheme),
 			GFP_KERNEL);
 	if (!schemes)
 		return NULL;
 
+	quota = kmalloc(sizeof(struct damos_quota), GFP_KERNEL);
+	if (!quota) {
+		kfree(schemes);
+		return NULL;
+	}
+
 	*nr_schemes = 0;
 	while (pos < len && *nr_schemes < max_nr_schemes) {
 		struct damos_access_pattern pattern = {};
-		struct damos_quota quota = {};
 		struct damos_watermarks wmarks;
 
+		memset(quota, 0, sizeof(struct damos_quota));
+
 		ret = sscanf(&str[pos],
 				"%lu %lu %u %u %u %u %u %lu %lu %lu %u %u %u %u %lu %lu %lu %lu%n",
 				&pattern.min_sz_region, &pattern.max_sz_region,
@@ -256,10 +264,10 @@ static struct damos **str_to_schemes(const char *str, ssize_t len,
 				&pattern.max_nr_accesses,
 				&pattern.min_age_region,
 				&pattern.max_age_region,
-				&action_input, &quota.ms,
-				&quota.sz, &quota.reset_interval,
-				&quota.weight_sz, &quota.weight_nr_accesses,
-				&quota.weight_age, &wmarks.metric,
+				&action_input, &quota->ms,
+				&quota->sz, &quota->reset_interval,
+				&quota->weight_sz, &quota->weight_nr_accesses,
+				&quota->weight_age, &wmarks.metric,
 				&wmarks.interval, &wmarks.high, &wmarks.mid,
 				&wmarks.low, &parsed);
 		if (ret != 18)
@@ -278,15 +286,17 @@ static struct damos **str_to_schemes(const char *str, ssize_t len,
 			goto fail;
 
 		pos += parsed;
-		scheme = damon_new_scheme(&pattern, action, &quota, &wmarks);
+		scheme = damon_new_scheme(&pattern, action, quota, &wmarks);
 		if (!scheme)
 			goto fail;
 
 		schemes[*nr_schemes] = scheme;
 		*nr_schemes += 1;
 	}
+	kfree(quota);
 	return schemes;
 fail:
+	kfree(quota);
 	free_schemes_arr(schemes, *nr_schemes);
 	return NULL;
 }
-- 
2.40.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] mm/mm/damon/sysfs-schemes: reduce stack usage in damon_sysfs_mk_scheme()
  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
  2023-07-17  3:41 ` [PATCH 1/2] mm/damon/dbgfs: reduce stack usage in str_to_schemes() Chao Yu
  1 sibling, 0 replies; 4+ messages in thread
From: Chao Yu @ 2023-07-16  1:09 UTC (permalink / raw)
  To: sj, akpm, damon; +Cc: linux-mm, linux-kernel, Chao Yu

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



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] mm/damon/dbgfs: reduce stack usage in str_to_schemes()
  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 ` [PATCH 2/2] mm/mm/damon/sysfs-schemes: reduce stack usage in damon_sysfs_mk_scheme() Chao Yu
@ 2023-07-17  3:41 ` Chao Yu
  2023-07-17 19:12   ` SeongJae Park
  1 sibling, 1 reply; 4+ messages in thread
From: Chao Yu @ 2023-07-17  3:41 UTC (permalink / raw)
  To: sj, akpm, damon; +Cc: linux-mm, linux-kernel

Hi all,

It warned because my config is wrong, sorry for the mistake, please
ignore the patchset. :-P

Thanks,

On 2023/7/16 9:09, Chao Yu wrote:
> struct damos_quota quota caused the stack usage of str_to_schemes() to
> grow beyond the warning limit on 32-bit architectures w/ gcc.
> 
> mm/damon/dbgfs.c: In function ‘str_to_schemes’:
> mm/damon/dbgfs.c:292:1: warning: the frame size of 1496 bytes is larger than 1024 bytes [-Wframe-larger-than=]
> 
> Allocating dynamic memory in str_to_schemes() to fix this issue.
> 
> Signed-off-by: Chao Yu <chao@kernel.org>
> ---
>   mm/damon/dbgfs.c | 22 ++++++++++++++++------
>   1 file changed, 16 insertions(+), 6 deletions(-)
> 
> diff --git a/mm/damon/dbgfs.c b/mm/damon/dbgfs.c
> index 124f0f8c97b7..78acc7366895 100644
> --- a/mm/damon/dbgfs.c
> +++ b/mm/damon/dbgfs.c
> @@ -237,18 +237,26 @@ static struct damos **str_to_schemes(const char *str, ssize_t len,
>   	int pos = 0, parsed, ret;
>   	unsigned int action_input;
>   	enum damos_action action;
> +	struct damos_quota *quota;
>   
>   	schemes = kmalloc_array(max_nr_schemes, sizeof(scheme),
>   			GFP_KERNEL);
>   	if (!schemes)
>   		return NULL;
>   
> +	quota = kmalloc(sizeof(struct damos_quota), GFP_KERNEL);
> +	if (!quota) {
> +		kfree(schemes);
> +		return NULL;
> +	}
> +
>   	*nr_schemes = 0;
>   	while (pos < len && *nr_schemes < max_nr_schemes) {
>   		struct damos_access_pattern pattern = {};
> -		struct damos_quota quota = {};
>   		struct damos_watermarks wmarks;
>   
> +		memset(quota, 0, sizeof(struct damos_quota));
> +
>   		ret = sscanf(&str[pos],
>   				"%lu %lu %u %u %u %u %u %lu %lu %lu %u %u %u %u %lu %lu %lu %lu%n",
>   				&pattern.min_sz_region, &pattern.max_sz_region,
> @@ -256,10 +264,10 @@ static struct damos **str_to_schemes(const char *str, ssize_t len,
>   				&pattern.max_nr_accesses,
>   				&pattern.min_age_region,
>   				&pattern.max_age_region,
> -				&action_input, &quota.ms,
> -				&quota.sz, &quota.reset_interval,
> -				&quota.weight_sz, &quota.weight_nr_accesses,
> -				&quota.weight_age, &wmarks.metric,
> +				&action_input, &quota->ms,
> +				&quota->sz, &quota->reset_interval,
> +				&quota->weight_sz, &quota->weight_nr_accesses,
> +				&quota->weight_age, &wmarks.metric,
>   				&wmarks.interval, &wmarks.high, &wmarks.mid,
>   				&wmarks.low, &parsed);
>   		if (ret != 18)
> @@ -278,15 +286,17 @@ static struct damos **str_to_schemes(const char *str, ssize_t len,
>   			goto fail;
>   
>   		pos += parsed;
> -		scheme = damon_new_scheme(&pattern, action, &quota, &wmarks);
> +		scheme = damon_new_scheme(&pattern, action, quota, &wmarks);
>   		if (!scheme)
>   			goto fail;
>   
>   		schemes[*nr_schemes] = scheme;
>   		*nr_schemes += 1;
>   	}
> +	kfree(quota);
>   	return schemes;
>   fail:
> +	kfree(quota);
>   	free_schemes_arr(schemes, *nr_schemes);
>   	return NULL;
>   }


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] mm/damon/dbgfs: reduce stack usage in str_to_schemes()
  2023-07-17  3:41 ` [PATCH 1/2] mm/damon/dbgfs: reduce stack usage in str_to_schemes() Chao Yu
@ 2023-07-17 19:12   ` SeongJae Park
  0 siblings, 0 replies; 4+ messages in thread
From: SeongJae Park @ 2023-07-17 19:12 UTC (permalink / raw)
  To: Chao Yu; +Cc: sj, akpm, damon, linux-mm, linux-kernel

Hi Chao,

On Mon, 17 Jul 2023 11:41:01 +0800 Chao Yu <chao@kernel.org> wrote:

> Hi all,
> 
> It warned because my config is wrong, sorry for the mistake, please
> ignore the patchset. :-P

No problem at all, appreciate for taking a look into DAMON :)


Thanks,
SJ

[...]


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-07-17 19:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH 2/2] mm/mm/damon/sysfs-schemes: reduce stack usage in damon_sysfs_mk_scheme() Chao Yu
2023-07-17  3:41 ` [PATCH 1/2] mm/damon/dbgfs: reduce stack usage in str_to_schemes() Chao Yu
2023-07-17 19:12   ` SeongJae Park

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).