Skip to content

Commit 22ee3ea

Browse files
committed
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 <[email protected]> Signed-off-by: Helge Deller <[email protected]>
1 parent c984baa commit 22ee3ea

File tree

4 files changed

+30
-16
lines changed

4 files changed

+30
-16
lines changed

arch/parisc/include/asm/processor.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,12 @@
4545
#define STACK_TOP TASK_SIZE
4646
#define STACK_TOP_MAX DEFAULT_TASK_SIZE
4747

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-
5348
#endif
5449

5550
#ifndef __ASSEMBLY__
5651

52+
unsigned long calc_max_stack_size(unsigned long stack_max);
53+
5754
/*
5855
* Data detected about CPUs at boot time which is the same for all CPU's.
5956
* HP boxes are SMP - ie identical processors.

arch/parisc/kernel/sys_parisc.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,25 @@ static inline unsigned long COLOR_ALIGN(unsigned long addr,
5353
return base + off;
5454
}
5555

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+
5675
/*
5776
* Top of mmap area (just below the process stack).
5877
*/
@@ -69,8 +88,8 @@ static unsigned long mmap_upper_limit(struct rlimit *rlim_stack)
6988
/* Limit stack size - see setup_arg_pages() in fs/exec.c */
7089
stack_base = rlim_stack ? rlim_stack->rlim_max
7190
: rlimit_max(RLIMIT_STACK);
72-
if (stack_base > STACK_SIZE_MAX)
73-
stack_base = STACK_SIZE_MAX;
91+
92+
stack_base = calc_max_stack_size(stack_base);
7493

7594
/* Add space for stack randomization. */
7695
if (current->flags & PF_RANDOMIZE)

fs/exec.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -756,8 +756,8 @@ int setup_arg_pages(struct linux_binprm *bprm,
756756
#ifdef CONFIG_STACK_GROWSUP
757757
/* Limit stack size */
758758
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);
761761

762762
/* Add space for stack randomization. */
763763
stack_base += (STACK_RND_MASK << PAGE_SHIFT);

mm/Kconfig

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -733,19 +733,17 @@ config ZSMALLOC_STAT
733733
config GENERIC_EARLY_IOREMAP
734734
bool
735735

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
739739
range 8 2048
740740
depends on STACK_GROWSUP && (!64BIT || COMPAT)
741741
help
742742
This is the maximum stack size in Megabytes in the VM layout of 32-bit
743743
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.
747745

748-
A sane initial value is 80 MB.
746+
A sane initial value is 100 MB.
749747

750748
config DEFERRED_STRUCT_PAGE_INIT
751749
bool "Defer initialisation of struct pages to kthreads"

0 commit comments

Comments
 (0)