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

parisc: Make user stack size configurable

On parisc we need to initialize the memory layout for the user stack at
process start time to a fixed size, which up until now was limited to
the size as given by CONFIG_MAX_STACK_SIZE_MB at compile time.

This hard limit was too small and showed problems when compiling
ruby2.7, qmlcachegen and some Qt packages.

This patch changes two things:
a) It increases the default maximum stack size to 100MB.
b) Users can modify the stack hard limit size with ulimit and then newly
forked processes will use the given stack size which can even be bigger
than the default 100MB.

Reported-by: John David Anglin <dave.anglin@bell.net>
Signed-off-by: Helge Deller <deller@gmx.de>

+30 -16
+2 -5
arch/parisc/include/asm/processor.h
··· 45 45 #define STACK_TOP TASK_SIZE 46 46 #define STACK_TOP_MAX DEFAULT_TASK_SIZE 47 47 48 - /* Allow bigger stacks for 64-bit processes */ 49 - #define STACK_SIZE_MAX (USER_WIDE_MODE \ 50 - ? (1 << 30) /* 1 GB */ \ 51 - : (CONFIG_MAX_STACK_SIZE_MB*1024*1024)) 52 - 53 48 #endif 54 49 55 50 #ifndef __ASSEMBLY__ 51 + 52 + unsigned long calc_max_stack_size(unsigned long stack_max); 56 53 57 54 /* 58 55 * Data detected about CPUs at boot time which is the same for all CPU's.
+21 -2
arch/parisc/kernel/sys_parisc.c
··· 53 53 return base + off; 54 54 } 55 55 56 + 57 + #define STACK_SIZE_DEFAULT (USER_WIDE_MODE \ 58 + ? (1 << 30) /* 1 GB */ \ 59 + : (CONFIG_STACK_MAX_DEFAULT_SIZE_MB*1024*1024)) 60 + 61 + unsigned long calc_max_stack_size(unsigned long stack_max) 62 + { 63 + #ifdef CONFIG_COMPAT 64 + if (!USER_WIDE_MODE && (stack_max == COMPAT_RLIM_INFINITY)) 65 + stack_max = STACK_SIZE_DEFAULT; 66 + else 67 + #endif 68 + if (stack_max == RLIM_INFINITY) 69 + stack_max = STACK_SIZE_DEFAULT; 70 + 71 + return stack_max; 72 + } 73 + 74 + 56 75 /* 57 76 * Top of mmap area (just below the process stack). 58 77 */ ··· 88 69 /* Limit stack size - see setup_arg_pages() in fs/exec.c */ 89 70 stack_base = rlim_stack ? rlim_stack->rlim_max 90 71 : rlimit_max(RLIMIT_STACK); 91 - if (stack_base > STACK_SIZE_MAX) 92 - stack_base = STACK_SIZE_MAX; 72 + 73 + stack_base = calc_max_stack_size(stack_base); 93 74 94 75 /* Add space for stack randomization. */ 95 76 if (current->flags & PF_RANDOMIZE)
+2 -2
fs/exec.c
··· 756 756 #ifdef CONFIG_STACK_GROWSUP 757 757 /* Limit stack size */ 758 758 stack_base = bprm->rlim_stack.rlim_max; 759 - if (stack_base > STACK_SIZE_MAX) 760 - stack_base = STACK_SIZE_MAX; 759 + 760 + stack_base = calc_max_stack_size(stack_base); 761 761 762 762 /* Add space for stack randomization. */ 763 763 stack_base += (STACK_RND_MASK << PAGE_SHIFT);
+5 -7
mm/Kconfig
··· 733 733 config GENERIC_EARLY_IOREMAP 734 734 bool 735 735 736 - config MAX_STACK_SIZE_MB 737 - int "Maximum user stack size for 32-bit processes (MB)" 738 - default 80 736 + config STACK_MAX_DEFAULT_SIZE_MB 737 + int "Default maximum user stack size for 32-bit processes (MB)" 738 + default 100 739 739 range 8 2048 740 740 depends on STACK_GROWSUP && (!64BIT || COMPAT) 741 741 help 742 742 This is the maximum stack size in Megabytes in the VM layout of 32-bit 743 743 user processes when the stack grows upwards (currently only on parisc 744 - arch). The stack will be located at the highest memory address minus 745 - the given value, unless the RLIMIT_STACK hard limit is changed to a 746 - smaller value in which case that is used. 744 + arch) when the RLIMIT_STACK hard limit is unlimited. 747 745 748 - A sane initial value is 80 MB. 746 + A sane initial value is 100 MB. 749 747 750 748 config DEFERRED_STRUCT_PAGE_INIT 751 749 bool "Defer initialisation of struct pages to kthreads"