From: "Liam R. Howlett" <Liam.Howlett@oracle.com>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Steven Rostedt <rostedt@goodmis.org>,
Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
Valentin Schneider <vschneid@redhat.com>,
Kees Cook <kees@kernel.org>, David Hildenbrand <david@redhat.com>,
Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
Vlastimil Babka <vbabka@suse.cz>, Mike Rapoport <rppt@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>,
Pasha Tatashin <pasha.tatashin@soleen.com>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [PATCH 2/2] task_stack.h: Clean-up stack_not_used() implementation
Date: Fri, 29 Aug 2025 11:41:28 -0400 [thread overview]
Message-ID: <zllb6trx6rbheykxoj44bztbxzumseiedwwvyemv2y5vch2w6l@igkejk5b7qb3> (raw)
In-Reply-To: <20250829-fork-cleanups-for-dynstack-v1-2-3bbaadce1f00@linaro.org>
* Linus Walleij <linus.walleij@linaro.org> [250829 07:44]:
> From: Pasha Tatashin <pasha.tatashin@soleen.com>
>
> Inside the small stack_not_used() function there are several ifdefs for
> stack growing-up vs. regular versions. Instead just implement this
> function two times, one for growing-up and another regular.
>
> Add comments like /* !CONFIG_DEBUG_STACK_USAGE */ to clarify what the
> ifdefs are doing.
>
> [linus.walleij@linaro.org: Rebased, function moved elsewhere in the kernel]
> Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
> Link: https://lore.kernel.org/20240311164638.2015063-13-pasha.tatashin@soleen.com
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Thanks for this.
Reviewed-by: Liam R. Howlett <Liam.Howlett@oracle.com>
> ---
> kernel/exit.c | 23 ++++++++++++++---------
> 1 file changed, 14 insertions(+), 9 deletions(-)
>
> diff --git a/kernel/exit.c b/kernel/exit.c
> index 343eb97543d568baeb23142edcc9050a8b8be8bf..9f74e8f1c431b6aa6e391ff71aadf9895a3857ae 100644
> --- a/kernel/exit.c
> +++ b/kernel/exit.c
> @@ -780,24 +780,29 @@ static void exit_notify(struct task_struct *tsk, int group_dead)
> }
>
> #ifdef CONFIG_DEBUG_STACK_USAGE
> +#ifdef CONFIG_STACK_GROWSUP
> unsigned long stack_not_used(struct task_struct *p)
> {
> unsigned long *n = end_of_stack(p);
>
> do { /* Skip over canary */
> -# ifdef CONFIG_STACK_GROWSUP
> n--;
> -# else
> - n++;
> -# endif
> } while (!*n);
>
> -# ifdef CONFIG_STACK_GROWSUP
> return (unsigned long)end_of_stack(p) - (unsigned long)n;
> -# else
> +}
> +#else /* !CONFIG_STACK_GROWSUP */
> +unsigned long stack_not_used(struct task_struct *p)
> +{
> + unsigned long *n = end_of_stack(p);
> +
> + do { /* Skip over canary */
> + n++;
> + } while (!*n);
> +
> return (unsigned long)n - (unsigned long)end_of_stack(p);
> -# endif
> }
> +#endif /* CONFIG_STACK_GROWSUP */
>
> /* Count the maximum pages reached in kernel stacks */
> static inline void kstack_histogram(unsigned long used_stack)
> @@ -856,9 +861,9 @@ static void check_stack_usage(void)
> }
> spin_unlock(&low_water_lock);
> }
> -#else
> +#else /* !CONFIG_DEBUG_STACK_USAGE */
> static inline void check_stack_usage(void) {}
> -#endif
> +#endif /* CONFIG_DEBUG_STACK_USAGE */
>
> static void synchronize_group_exit(struct task_struct *tsk, long code)
> {
>
> --
> 2.50.1
>
next prev parent reply other threads:[~2025-08-29 15:41 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-29 11:44 [PATCH 0/2] mm: task_stack: Stack handling cleanups Linus Walleij
2025-08-29 11:44 ` [PATCH 1/2] fork: check charging success before zeroing stack Linus Walleij
2025-08-29 15:39 ` Liam R. Howlett
2025-09-01 11:58 ` Lorenzo Stoakes
2025-08-29 11:44 ` [PATCH 2/2] task_stack.h: Clean-up stack_not_used() implementation Linus Walleij
2025-08-29 15:41 ` Liam R. Howlett [this message]
2025-09-01 11:58 ` Lorenzo Stoakes
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=zllb6trx6rbheykxoj44bztbxzumseiedwwvyemv2y5vch2w6l@igkejk5b7qb3 \
--to=liam.howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=bsegall@google.com \
--cc=david@redhat.com \
--cc=dietmar.eggemann@arm.com \
--cc=juri.lelli@redhat.com \
--cc=kees@kernel.org \
--cc=linus.walleij@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=mgorman@suse.de \
--cc=mhocko@suse.com \
--cc=mingo@redhat.com \
--cc=pasha.tatashin@soleen.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=rppt@kernel.org \
--cc=surenb@google.com \
--cc=vbabka@suse.cz \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
/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