Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

task_stack.h: clean-up stack_not_used() implementation

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]
Link: https://lkml.kernel.org/r/20250829-fork-cleanups-for-dynstack-v1-2-3bbaadce1f00@linaro.org
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>
Reviewed-by: Liam R. Howlett <Liam.Howlett@oracle.com>
Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Ben Segall <bsegall@google.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Juri Lelli <juri.lelli@redhat.com>
Cc: Kees Cook <kees@kernel.org>
Cc: Mel Gorman <mgorman <mgorman@suse.de>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Valentin Schneider <vschneid@redhat.com>
Cc: Vincent Guittot <vincent.guittot@linaro.org>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Pasha Tatashin and committed by
Andrew Morton
783dbe47 1bca7359

+15 -10
+15 -10
kernel/exit.c
··· 780 780 } 781 781 782 782 #ifdef CONFIG_DEBUG_STACK_USAGE 783 + #ifdef CONFIG_STACK_GROWSUP 783 784 unsigned long stack_not_used(struct task_struct *p) 784 785 { 785 786 unsigned long *n = end_of_stack(p); 786 787 787 788 do { /* Skip over canary */ 788 - # ifdef CONFIG_STACK_GROWSUP 789 789 n--; 790 - # else 791 - n++; 792 - # endif 793 790 } while (!*n); 794 791 795 - # ifdef CONFIG_STACK_GROWSUP 796 792 return (unsigned long)end_of_stack(p) - (unsigned long)n; 797 - # else 798 - return (unsigned long)n - (unsigned long)end_of_stack(p); 799 - # endif 800 793 } 794 + #else /* !CONFIG_STACK_GROWSUP */ 795 + unsigned long stack_not_used(struct task_struct *p) 796 + { 797 + unsigned long *n = end_of_stack(p); 798 + 799 + do { /* Skip over canary */ 800 + n++; 801 + } while (!*n); 802 + 803 + return (unsigned long)n - (unsigned long)end_of_stack(p); 804 + } 805 + #endif /* CONFIG_STACK_GROWSUP */ 801 806 802 807 /* Count the maximum pages reached in kernel stacks */ 803 808 static inline void kstack_histogram(unsigned long used_stack) ··· 861 856 } 862 857 spin_unlock(&low_water_lock); 863 858 } 864 - #else 859 + #else /* !CONFIG_DEBUG_STACK_USAGE */ 865 860 static inline void check_stack_usage(void) {} 866 - #endif 861 + #endif /* CONFIG_DEBUG_STACK_USAGE */ 867 862 868 863 static void synchronize_group_exit(struct task_struct *tsk, long code) 869 864 {