From patchwork Thu Nov 2 15:48:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ben Wolsieffer X-Patchwork-Id: 1858604 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=hefring-com.20230601.gappssmtp.com header.i=@hefring-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=aYh2kmKM; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=uclibc-ng.org (client-ip=2a00:1828:2000:679::23; helo=helium.openadk.org; envelope-from=devel-bounces@uclibc-ng.org; receiver=patchwork.ozlabs.org) Received: from helium.openadk.org (helium.openadk.org [IPv6:2a00:1828:2000:679::23]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SLpss53dLz1yQ4 for ; Fri, 3 Nov 2023 03:16:47 +1100 (AEDT) Received: from helium.openadk.org (localhost [IPv6:::1]) by helium.openadk.org (Postfix) with ESMTP id 1ED493520EA8; Thu, 2 Nov 2023 17:16:37 +0100 (CET) Authentication-Results: helium.openadk.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=hefring-com.20230601.gappssmtp.com header.i=@hefring-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=aYh2kmKM; dkim-atps=neutral Received: from mail-qt1-f179.google.com (mail-qt1-f179.google.com [209.85.160.179]) by helium.openadk.org (Postfix) with ESMTPS id A8FE2352076F for ; Thu, 2 Nov 2023 17:12:11 +0100 (CET) Received: by mail-qt1-f179.google.com with SMTP id d75a77b69052e-41cd97d7272so5771481cf.0 for ; Thu, 02 Nov 2023 09:12:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hefring-com.20230601.gappssmtp.com; s=20230601; t=1698941529; x=1699546329; darn=uclibc-ng.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=iC7u2pOyWwZLDbpQfybs76Am969V5UCm8TQ11gy8DkY=; b=aYh2kmKMoFIfNmPLkLld0XiSfktCrpGEd8/5sJkgG1gvLBmrtj1YSzRYbloNibXFmS JQGqBgBFux+rFb+jHWGjvlpJgtjQdlkyUW6bBSDlqN7PjeZyiH/E6sgDu63/d0CFWLLa Bef4FBY+O58s+7+T+IxGm4gEKKBYVDuUdRBizIn0NUen2kxSAEToQrrGI7LyE0vznw6A HVq5Tf10f8ROiqgijd35pkU2eEZHa00Ey2jebGznbVNve6z3fGHzrQS9LY7Mciq1WpHx cIs+BwSPosjhswO3gok9Ampna7juAWpFVM8rtXkQfSZd2iyYJxhoIZR9SV6wHfLNTNBm 7K3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698941529; x=1699546329; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=iC7u2pOyWwZLDbpQfybs76Am969V5UCm8TQ11gy8DkY=; b=A483ckljFyU7Kznk9aK3hp0sTFiaLYcyLWqWh+vfZxyYy7MnyNqaPsUVqltZMpF3FE ayljoYb8Ee30DxY1SUnBfEPwmaw9UmxvZIEg7Yl4+JPHpMHONKVVGFcZQoec+GHthh2/ Bb0/xdFNbA8vckeOJLUyH4khUWNabHGlPAKNo5/A4PNxaV2J1QGtbCj9z01FE5J+frDe bwjeeoJI3qyPuGIc9sGwRpC8EbsENqLRCilfA9skAH3T7oly7yzoNBhWVikMKl7Id7mi txUYUhKbCq2Y5FsneRoY1FvN6VVG5kjzXA64kySh/h1AUZ/di2sPh+56GobwC1O20H+5 to7Q== X-Gm-Message-State: AOJu0YwEpQvf9HIu6j5JAG0H9e9WtYssrzob8G2Lmo+XEVeNnHd7QD9i zj6EXs9Mg7D9eNXTGcikWh8oi2ab+cvPTj1DojI= X-Google-Smtp-Source: AGHT+IH4Q9v7VBbdHSonIcsIqzSFVyIhSmtIVyBCLMoqDiiByqiZ9H0x/0ca9IM9Nm6ZHPw25jRw/Q== X-Received: by 2002:a05:622a:4d3:b0:41c:e9b9:5e10 with SMTP id q19-20020a05622a04d300b0041ce9b95e10mr21832385qtx.35.1698941528640; Thu, 02 Nov 2023 09:12:08 -0700 (PDT) Received: from localhost.localdomain ([50.212.55.89]) by smtp.gmail.com with ESMTPSA id x1-20020ac85381000000b0041977932fc6sm61920qtp.18.2023.11.02.09.12.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 09:12:08 -0700 (PDT) From: Ben Wolsieffer To: devel@uclibc-ng.org Date: Thu, 2 Nov 2023 11:48:25 -0400 Message-ID: <20231102154929.2975973-2-ben.wolsieffer@hefring.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 Message-ID-Hash: WO2U2LGDUPJIHJHQAISZQLBSUJJW5QOX X-Message-ID-Hash: WO2U2LGDUPJIHJHQAISZQLBSUJJW5QOX X-MailFrom: ben.wolsieffer@hefring.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Ben Wolsieffer X-Mailman-Version: 3.3.3 Precedence: list Subject: [uclibc-ng-devel] [PATCH v2] libpthread/nptl: make default stack size configurable List-Id: uClibc-ng Development Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- Changes in v2: * Entirely move default stack size configuration to Kconfig extra/Configs/Config.in | 9 +++++++++ libpthread/nptl/init.c | 14 +++++++------- libpthread/nptl/sysdeps/aarch64/pthreaddef.h | 3 --- libpthread/nptl/sysdeps/alpha/pthreaddef.h | 3 --- libpthread/nptl/sysdeps/arc/pthreaddef.h | 3 --- libpthread/nptl/sysdeps/arm/pthreaddef.h | 3 --- libpthread/nptl/sysdeps/csky/pthreaddef.h | 3 --- libpthread/nptl/sysdeps/i386/pthreaddef.h | 3 --- libpthread/nptl/sysdeps/kvx/pthreaddef.h | 3 --- libpthread/nptl/sysdeps/m68k/pthreaddef.h | 3 --- libpthread/nptl/sysdeps/metag/pthreaddef.h | 3 --- libpthread/nptl/sysdeps/microblaze/pthreaddef.h | 3 --- libpthread/nptl/sysdeps/mips/pthreaddef.h | 3 --- libpthread/nptl/sysdeps/nds32/pthreaddef.h | 3 --- libpthread/nptl/sysdeps/nios2/pthreaddef.h | 3 --- libpthread/nptl/sysdeps/or1k/pthreaddef.h | 3 --- libpthread/nptl/sysdeps/powerpc/pthreaddef.h | 3 --- libpthread/nptl/sysdeps/riscv64/pthreaddef.h | 3 --- libpthread/nptl/sysdeps/sh/pthreaddef.h | 3 --- libpthread/nptl/sysdeps/sparc/pthreaddef.h | 3 --- libpthread/nptl/sysdeps/x86_64/pthreaddef.h | 3 --- libpthread/nptl/sysdeps/xtensa/pthreaddef.h | 3 --- 22 files changed, 16 insertions(+), 67 deletions(-) diff --git a/extra/Configs/Config.in b/extra/Configs/Config.in index 6bbb6f572..c2834f5ec 100644 --- a/extra/Configs/Config.in +++ b/extra/Configs/Config.in @@ -628,6 +628,15 @@ config PTHREADS_DEBUG_SUPPORT If you are doing development and want to debug applications using uClibc's pthread library, answer Y. Otherwise, answer N. +config PTHREADS_STACK_DEFAULT_SIZE + int "Default thread stack size" + default 4194304 if TARGET_alpha # 4 MiB + default 4194304 if TARGET_powerpc # 4 MiB + default 2097152 # 2 MiB + help + Set the default thread stack size. This option is useful on MMU-less + systems where the stack size is fixed and the default stack size may + be excessively large and waste memory. config UCLIBC_HAS_SYSLOG bool "Syslog support" 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. */ diff --git a/libpthread/nptl/sysdeps/aarch64/pthreaddef.h b/libpthread/nptl/sysdeps/aarch64/pthreaddef.h index d9495f9cb..7172f406b 100644 --- a/libpthread/nptl/sysdeps/aarch64/pthreaddef.h +++ b/libpthread/nptl/sysdeps/aarch64/pthreaddef.h @@ -14,9 +14,6 @@ License along with the GNU C Library; if not, see . */ -/* Default stack size. */ -#define ARCH_STACK_DEFAULT_SIZE (2 * 1024 * 1024) - /* Required stack pointer alignment at beginning. */ #define STACK_ALIGN 16 diff --git a/libpthread/nptl/sysdeps/alpha/pthreaddef.h b/libpthread/nptl/sysdeps/alpha/pthreaddef.h index 72a311c33..6b99f3b4f 100644 --- a/libpthread/nptl/sysdeps/alpha/pthreaddef.h +++ b/libpthread/nptl/sysdeps/alpha/pthreaddef.h @@ -15,9 +15,6 @@ License along with the GNU C Library; if not, see . */ -/* Default stack size. */ -#define ARCH_STACK_DEFAULT_SIZE (4 * 1024 * 1024) - /* Required stack pointer alignment at beginning. The ABI requires 16. */ #define STACK_ALIGN 16 diff --git a/libpthread/nptl/sysdeps/arc/pthreaddef.h b/libpthread/nptl/sysdeps/arc/pthreaddef.h index bf4f0f29a..0fb28dc48 100644 --- a/libpthread/nptl/sysdeps/arc/pthreaddef.h +++ b/libpthread/nptl/sysdeps/arc/pthreaddef.h @@ -17,9 +17,6 @@ #include -/* Default stack size. */ -#define ARCH_STACK_DEFAULT_SIZE (2 * 1024 * 1024) - /* Required stack pointer alignment at beginning. */ #define STACK_ALIGN 8 diff --git a/libpthread/nptl/sysdeps/arm/pthreaddef.h b/libpthread/nptl/sysdeps/arm/pthreaddef.h index a05ac879d..f790a6dca 100644 --- a/libpthread/nptl/sysdeps/arm/pthreaddef.h +++ b/libpthread/nptl/sysdeps/arm/pthreaddef.h @@ -15,9 +15,6 @@ License along with the GNU C Library; if not, see . */ -/* Default stack size. */ -#define ARCH_STACK_DEFAULT_SIZE (2 * 1024 * 1024) - /* Required stack pointer alignment at beginning. SSE requires 16 bytes. */ #define STACK_ALIGN 16 diff --git a/libpthread/nptl/sysdeps/csky/pthreaddef.h b/libpthread/nptl/sysdeps/csky/pthreaddef.h index 992fced01..4aa97ee27 100644 --- a/libpthread/nptl/sysdeps/csky/pthreaddef.h +++ b/libpthread/nptl/sysdeps/csky/pthreaddef.h @@ -5,9 +5,6 @@ * in this tarball. */ -/* Default stack size. */ -#define ARCH_STACK_DEFAULT_SIZE (2 * 1024 * 1024) - /* Required stack pointer alignment at beginning. SSE requires 16 bytes. */ #define STACK_ALIGN 16 diff --git a/libpthread/nptl/sysdeps/i386/pthreaddef.h b/libpthread/nptl/sysdeps/i386/pthreaddef.h index a0659039d..2fd27113c 100644 --- a/libpthread/nptl/sysdeps/i386/pthreaddef.h +++ b/libpthread/nptl/sysdeps/i386/pthreaddef.h @@ -16,9 +16,6 @@ License along with the GNU C Library; if not, see . */ -/* Default stack size. */ -#define ARCH_STACK_DEFAULT_SIZE (2 * 1024 * 1024) - /* Required stack pointer alignment at beginning. SSE requires 16 bytes. */ #define STACK_ALIGN 16 diff --git a/libpthread/nptl/sysdeps/kvx/pthreaddef.h b/libpthread/nptl/sysdeps/kvx/pthreaddef.h index 6e1485998..03945bc5f 100644 --- a/libpthread/nptl/sysdeps/kvx/pthreaddef.h +++ b/libpthread/nptl/sysdeps/kvx/pthreaddef.h @@ -6,9 +6,6 @@ * Copyright (C) 2019 Kalray Inc. */ -/* Default stack size. */ -#define ARCH_STACK_DEFAULT_SIZE (2 * 1024 * 1024) - /* Required stack pointer alignment at beginning. */ #define STACK_ALIGN 32 diff --git a/libpthread/nptl/sysdeps/m68k/pthreaddef.h b/libpthread/nptl/sysdeps/m68k/pthreaddef.h index 1651b3d5f..04d565191 100644 --- a/libpthread/nptl/sysdeps/m68k/pthreaddef.h +++ b/libpthread/nptl/sysdeps/m68k/pthreaddef.h @@ -15,9 +15,6 @@ License along with the GNU C Library. If not, see . */ -/* Default stack size. */ -#define ARCH_STACK_DEFAULT_SIZE (2 * 1024 * 1024) - /* Required stack pointer alignment at beginning. */ #define STACK_ALIGN 16 diff --git a/libpthread/nptl/sysdeps/metag/pthreaddef.h b/libpthread/nptl/sysdeps/metag/pthreaddef.h index bf4f0f29a..0fb28dc48 100644 --- a/libpthread/nptl/sysdeps/metag/pthreaddef.h +++ b/libpthread/nptl/sysdeps/metag/pthreaddef.h @@ -17,9 +17,6 @@ #include -/* Default stack size. */ -#define ARCH_STACK_DEFAULT_SIZE (2 * 1024 * 1024) - /* Required stack pointer alignment at beginning. */ #define STACK_ALIGN 8 diff --git a/libpthread/nptl/sysdeps/microblaze/pthreaddef.h b/libpthread/nptl/sysdeps/microblaze/pthreaddef.h index 47e87dd71..a01b59fab 100644 --- a/libpthread/nptl/sysdeps/microblaze/pthreaddef.h +++ b/libpthread/nptl/sysdeps/microblaze/pthreaddef.h @@ -19,9 +19,6 @@ #include #include -/* Default stack size. */ -#define ARCH_STACK_DEFAULT_SIZE (2 * 1024 * 1024) - /* Required stack pointer alignment at beginning. */ #define STACK_ALIGN 16 diff --git a/libpthread/nptl/sysdeps/mips/pthreaddef.h b/libpthread/nptl/sysdeps/mips/pthreaddef.h index 692988205..adedd7715 100644 --- a/libpthread/nptl/sysdeps/mips/pthreaddef.h +++ b/libpthread/nptl/sysdeps/mips/pthreaddef.h @@ -15,9 +15,6 @@ License along with the GNU C Library; if not, see . */ -/* Default stack size. */ -#define ARCH_STACK_DEFAULT_SIZE (2 * 1024 * 1024) - /* Required stack pointer alignment at beginning. */ #define STACK_ALIGN 16 diff --git a/libpthread/nptl/sysdeps/nds32/pthreaddef.h b/libpthread/nptl/sysdeps/nds32/pthreaddef.h index c9d3f7781..0dca16c34 100644 --- a/libpthread/nptl/sysdeps/nds32/pthreaddef.h +++ b/libpthread/nptl/sysdeps/nds32/pthreaddef.h @@ -14,9 +14,6 @@ License along with the GNU C Library; if not, see . */ -/* Default stack size. */ -#define ARCH_STACK_DEFAULT_SIZE (2 * 1024 * 1024) - /* Required stack pointer alignment at beginning. SSE requires 16 bytes. */ #define STACK_ALIGN 16 diff --git a/libpthread/nptl/sysdeps/nios2/pthreaddef.h b/libpthread/nptl/sysdeps/nios2/pthreaddef.h index 4268252dd..5be435237 100644 --- a/libpthread/nptl/sysdeps/nios2/pthreaddef.h +++ b/libpthread/nptl/sysdeps/nios2/pthreaddef.h @@ -16,9 +16,6 @@ License along with the GNU C Library. If not, see . */ -/* Default stack size. */ -#define ARCH_STACK_DEFAULT_SIZE (2 * 1024 * 1024) - /* Required stack pointer alignment at beginning. */ #define STACK_ALIGN 4 diff --git a/libpthread/nptl/sysdeps/or1k/pthreaddef.h b/libpthread/nptl/sysdeps/or1k/pthreaddef.h index e8da3d965..394962172 100644 --- a/libpthread/nptl/sysdeps/or1k/pthreaddef.h +++ b/libpthread/nptl/sysdeps/or1k/pthreaddef.h @@ -16,9 +16,6 @@ License along with the GNU C Library; if not, see . */ -/* Default stack size. */ -#define ARCH_STACK_DEFAULT_SIZE (2 * 1024 * 1024) - /* Required stack pointer alignment at beginning. */ #define STACK_ALIGN 16 diff --git a/libpthread/nptl/sysdeps/powerpc/pthreaddef.h b/libpthread/nptl/sysdeps/powerpc/pthreaddef.h index 36bf76404..a46c094b6 100644 --- a/libpthread/nptl/sysdeps/powerpc/pthreaddef.h +++ b/libpthread/nptl/sysdeps/powerpc/pthreaddef.h @@ -15,9 +15,6 @@ License along with the GNU C Library; if not, see . */ -/* Default stack size. */ -#define ARCH_STACK_DEFAULT_SIZE (4 * 1024 * 1024) - /* Required stack pointer alignment at beginning. The ABI requires 16 bytes (for both 32-bit and 64-bit PowerPC). */ #define STACK_ALIGN 16 diff --git a/libpthread/nptl/sysdeps/riscv64/pthreaddef.h b/libpthread/nptl/sysdeps/riscv64/pthreaddef.h index fbd40a74f..5a929bc77 100644 --- a/libpthread/nptl/sysdeps/riscv64/pthreaddef.h +++ b/libpthread/nptl/sysdeps/riscv64/pthreaddef.h @@ -14,9 +14,6 @@ License along with the GNU C Library; if not, see . */ -/* Default stack size. */ -#define ARCH_STACK_DEFAULT_SIZE (2 * 1024 * 1024) - /* Required stack pointer alignment at beginning. */ #define STACK_ALIGN 16 diff --git a/libpthread/nptl/sysdeps/sh/pthreaddef.h b/libpthread/nptl/sysdeps/sh/pthreaddef.h index fc3ae6029..918aaf54f 100644 --- a/libpthread/nptl/sysdeps/sh/pthreaddef.h +++ b/libpthread/nptl/sysdeps/sh/pthreaddef.h @@ -17,9 +17,6 @@ #include -/* Default stack size. */ -#define ARCH_STACK_DEFAULT_SIZE (2 * 1024 * 1024) - /* Required stack pointer alignment at beginning. */ #define STACK_ALIGN 8 diff --git a/libpthread/nptl/sysdeps/sparc/pthreaddef.h b/libpthread/nptl/sysdeps/sparc/pthreaddef.h index 435fedcf3..65f6655a4 100644 --- a/libpthread/nptl/sysdeps/sparc/pthreaddef.h +++ b/libpthread/nptl/sysdeps/sparc/pthreaddef.h @@ -15,9 +15,6 @@ License along with the GNU C Library; if not, see . */ -/* Default stack size. */ -#define ARCH_STACK_DEFAULT_SIZE (2 * 1024 * 1024) - /* Required stack pointer alignment at beginning. */ #define STACK_ALIGN 16 diff --git a/libpthread/nptl/sysdeps/x86_64/pthreaddef.h b/libpthread/nptl/sysdeps/x86_64/pthreaddef.h index 2b2285285..98ab8cfb1 100644 --- a/libpthread/nptl/sysdeps/x86_64/pthreaddef.h +++ b/libpthread/nptl/sysdeps/x86_64/pthreaddef.h @@ -16,9 +16,6 @@ License along with the GNU C Library; if not, see . */ -/* Default stack size. */ -#define ARCH_STACK_DEFAULT_SIZE (2 * 1024 * 1024) - /* Required stack pointer alignment at beginning. SSE requires 16 bytes. */ #define STACK_ALIGN 16 diff --git a/libpthread/nptl/sysdeps/xtensa/pthreaddef.h b/libpthread/nptl/sysdeps/xtensa/pthreaddef.h index 34c1851c3..13d8fef4c 100644 --- a/libpthread/nptl/sysdeps/xtensa/pthreaddef.h +++ b/libpthread/nptl/sysdeps/xtensa/pthreaddef.h @@ -15,9 +15,6 @@ License along with the GNU C Library; see the file COPYING.LIB. If not, see .  */ -/* Default stack size. */ -#define ARCH_STACK_DEFAULT_SIZE (2 * 1024 * 1024) - /* Required stack pointer alignment at beginning. */ #define STACK_ALIGN 16