Building the Linux kernel with Clang and LLVM
 help / color / mirror / Atom feed
* [PATCH] mm/damon/core: reduce kernel stack usage
@ 2026-06-11 12:56 Arnd Bergmann
  2026-06-11 13:56 ` SeongJae Park
  2026-06-11 18:50 ` David Laight
  0 siblings, 2 replies; 3+ messages in thread
From: Arnd Bergmann @ 2026-06-11 12:56 UTC (permalink / raw)
  To: SeongJae Park, Andrew Morton, Nathan Chancellor
  Cc: Arnd Bergmann, Nick Desaulniers, Bill Wendling, Justin Stitt,
	Ravi Jonnalagadda, Quanmin Yan, damon, linux-mm, linux-kernel,
	llvm

From: Arnd Bergmann <arnd@arndb.de>

The main thread function has recently grown to the point of
exceeding stack frame size warning limits in some configurations.
This is what I hit on s390 with clang and CONFIG_KASAN:

mm/damon/core.c:3440:31: error: stack frame size (1352) exceeds limit (1280) in 'kdamond_fn' [-Werror,-Wframe-larger-than]
 3440 | static int kdamond_fn(struct damon_ctx *ctx)

The largest stack usage here is inside of the kdamond_tune_intervals(),
so by marking that one as noinline_for_stack, the functions individually
stay below the warning limit, though kdamond_fn() itself still uses
hundreds of kilobytes for some reason.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 mm/damon/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/damon/core.c b/mm/damon/core.c
index 265d51ade25b..69f38c48ac08 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -2002,7 +2002,7 @@ static unsigned long damon_get_intervals_adaptation_bp(struct damon_ctx *c)
 	return adaptation_bp;
 }
 
-static void kdamond_tune_intervals(struct damon_ctx *c)
+static noinline_for_stack void kdamond_tune_intervals(struct damon_ctx *c)
 {
 	unsigned long adaptation_bp;
 	struct damon_attrs new_attrs;
-- 
2.39.5


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

* Re: [PATCH] mm/damon/core: reduce kernel stack usage
  2026-06-11 12:56 [PATCH] mm/damon/core: reduce kernel stack usage Arnd Bergmann
@ 2026-06-11 13:56 ` SeongJae Park
  2026-06-11 18:50 ` David Laight
  1 sibling, 0 replies; 3+ messages in thread
From: SeongJae Park @ 2026-06-11 13:56 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: SeongJae Park, Andrew Morton, Nathan Chancellor, Arnd Bergmann,
	Nick Desaulniers, Bill Wendling, Justin Stitt, Ravi Jonnalagadda,
	Quanmin Yan, damon, linux-mm, linux-kernel, llvm

On Thu, 11 Jun 2026 14:56:57 +0200 Arnd Bergmann <arnd@kernel.org> wrote:

> From: Arnd Bergmann <arnd@arndb.de>
> 
> The main thread function has recently grown to the point of
> exceeding stack frame size warning limits in some configurations.
> This is what I hit on s390 with clang and CONFIG_KASAN:
> 
> mm/damon/core.c:3440:31: error: stack frame size (1352) exceeds limit (1280) in 'kdamond_fn' [-Werror,-Wframe-larger-than]
>  3440 | static int kdamond_fn(struct damon_ctx *ctx)
> 
> The largest stack usage here is inside of the kdamond_tune_intervals(),
> so by marking that one as noinline_for_stack, the functions individually
> stay below the warning limit, though kdamond_fn() itself still uses
> hundreds of kilobytes for some reason.

Thank you for this fix, Arnd!  I will also take a look in kdamond_fn() to see
if there are more things to reduce.

> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Reviewed-by: SeongJae Park <sj@kernel.org>

Should we add Fixes: and Cc: stable@ too?  This function was introduced by
commit f04b0fedbe71 ("mm/damon/core: implement intervals auto-tuning") which
was merged into 6.15.


Thanks,
SJ

[...]

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

* Re: [PATCH] mm/damon/core: reduce kernel stack usage
  2026-06-11 12:56 [PATCH] mm/damon/core: reduce kernel stack usage Arnd Bergmann
  2026-06-11 13:56 ` SeongJae Park
@ 2026-06-11 18:50 ` David Laight
  1 sibling, 0 replies; 3+ messages in thread
From: David Laight @ 2026-06-11 18:50 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: SeongJae Park, Andrew Morton, Nathan Chancellor, Arnd Bergmann,
	Nick Desaulniers, Bill Wendling, Justin Stitt, Ravi Jonnalagadda,
	Quanmin Yan, damon, linux-mm, linux-kernel, llvm

On Thu, 11 Jun 2026 14:56:57 +0200
Arnd Bergmann <arnd@kernel.org> wrote:

> From: Arnd Bergmann <arnd@arndb.de>
> 
> The main thread function has recently grown to the point of
> exceeding stack frame size warning limits in some configurations.
> This is what I hit on s390 with clang and CONFIG_KASAN:
> 
> mm/damon/core.c:3440:31: error: stack frame size (1352) exceeds limit (1280) in 'kdamond_fn' [-Werror,-Wframe-larger-than]
>  3440 | static int kdamond_fn(struct damon_ctx *ctx)
> 
> The largest stack usage here is inside of the kdamond_tune_intervals(),
> so by marking that one as noinline_for_stack, the functions individually
> stay below the warning limit, though kdamond_fn() itself still uses
> hundreds of kilobytes for some reason.

Does that actually reduce the stack use if the functions are called?
Or just stop the compiler bleating and running the code is still likely
to overflow the stack.

I keep thinking it should be possible to get (say) objtool to output
the stack offsets of every call.
With (I think it is) fine-ibt the hashes can be used so separate all the
indirect calls (although you might need a 'salt' to separate the different
'void (*)(void *)' functions - that probably ought to be done anyway).
Then it is a SMOP to generate a maximal stack depth for each function and
to detect the recursive loops.

I did that many many years ago for an embedded system (no indirect calls),
the outcome was that we didn't have enough memory to allow for the worst
case stack use!
The deep places were all (the equivalent of) printk() in pretty
impossible error paths.

-- David


> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  mm/damon/core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mm/damon/core.c b/mm/damon/core.c
> index 265d51ade25b..69f38c48ac08 100644
> --- a/mm/damon/core.c
> +++ b/mm/damon/core.c
> @@ -2002,7 +2002,7 @@ static unsigned long damon_get_intervals_adaptation_bp(struct damon_ctx *c)
>  	return adaptation_bp;
>  }
>  
> -static void kdamond_tune_intervals(struct damon_ctx *c)
> +static noinline_for_stack void kdamond_tune_intervals(struct damon_ctx *c)
>  {
>  	unsigned long adaptation_bp;
>  	struct damon_attrs new_attrs;


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

end of thread, other threads:[~2026-06-11 18:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-11 12:56 [PATCH] mm/damon/core: reduce kernel stack usage Arnd Bergmann
2026-06-11 13:56 ` SeongJae Park
2026-06-11 18:50 ` David Laight

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox