diff options
author | Ben Wolsieffer <ben.wolsieffer@hefring.com> | 2023-11-02 11:48:25 -0400 |
---|---|---|
committer | Waldemar Brodkorb <wbx@openadk.org> | 2023-11-09 16:48:33 +0100 |
commit | c303df56d32faa47ef163726357ed3ee5d075b88 (patch) | |
tree | d00ee1101dd14b5c1bfbd712765a26d56b777845 /libpthread/nptl/init.c | |
parent | 8166707a3350ce1fdaf669fb3836810727379342 (diff) |
libpthread/nptl: make default stack size configurable
Threads currently have 2-4 MiB stacks by default (depending on the
platform). This is fine on MMU platforms, where this stack space is not
actually allocated until it is used, but tends to waste a large amount
of memory on no-MMU platforms.
This patch adds a PTHREADS_STACK_DEFAULT_SIZE Kconfig option that allows
the user to override the default stack size at build time. This allows
the user to select a reasonable default stack size for the software that
runs on their system, and avoids the need to patch every package to add
calls to pthread_attr_setstacksize().
An alternative to this patch would be to change the hardcoded default
stack size on no-MMU platforms, but it is difficult to choose an
appropriate value because the minimum required stack depends on the
software in use. This would also be a breaking change.
Signed-off-by: Ben Wolsieffer <ben.wolsieffer@hefring.com>
Diffstat (limited to 'libpthread/nptl/init.c')
-rw-r--r-- | libpthread/nptl/init.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/libpthread/nptl/init.c b/libpthread/nptl/init.c index 5d25ded7d..ddc552f2e 100644 --- a/libpthread/nptl/init.c +++ b/libpthread/nptl/init.c @@ -278,17 +278,17 @@ __pthread_initialize_minimal_internal (void) struct rlimit limit; if (getrlimit (RLIMIT_STACK, &limit) != 0 || limit.rlim_cur == RLIM_INFINITY) - /* The system limit is not usable. Use an architecture-specific - default. */ - limit.rlim_cur = ARCH_STACK_DEFAULT_SIZE; - else if (limit.rlim_cur < PTHREAD_STACK_MIN) + /* The system limit is not usable. Use a user-specified or + architecture-specific default. */ + limit.rlim_cur = __PTHREADS_STACK_DEFAULT_SIZE__; + if (limit.rlim_cur < PTHREAD_STACK_MIN) /* The system limit is unusably small. Use the minimal size acceptable. */ limit.rlim_cur = PTHREAD_STACK_MIN; - /* Do not exceed architecture specific default */ - if (limit.rlim_cur > ARCH_STACK_DEFAULT_SIZE) - limit.rlim_cur = ARCH_STACK_DEFAULT_SIZE; + /* Do not exceed the user-specified or architecture-specific default */ + if (limit.rlim_cur > __PTHREADS_STACK_DEFAULT_SIZE__) + limit.rlim_cur = __PTHREADS_STACK_DEFAULT_SIZE__; /* Make sure it meets the minimum size that allocate_stack (allocatestack.c) will demand, which depends on the page size. */ |