Skip to content

Cut the per-thread signal stack to 64 KB - #81

Merged
beetlebugorg merged 1 commit into
mainfrom
fix/small-signal-stack
Sep 23, 2026
Merged

beetlebugorg merged 1 commit into
mainfrom
fix/small-signal-stack

Conversation

@beetlebugorg

Copy link
Copy Markdown
Owner

std.options.signal_stack_size defaults to 256 KiB, and std declares that stack as a threadlocal, so it is static TLS in libtile57.a. glibc places a thread's static TLS inside the stack it allocates for the thread.

The Lookout Marine Linux app links libtile57.a beside its own Zig core, and each has that 256 KiB. With about 90 KiB from the Lua shim's caches, the app had 614,524 bytes of static TLS. pthread_create returned EINVAL for the app's 512 KiB plugin threads, so its plugins could not resolve a host or open an HTTP or WebSocket connection on Linux.

src/lib_root.zig now sets std_options.signal_stack_size to 64 KiB, which leaves Zig's segfault handler an alternate stack.

zig build, zig build test (449 passed, 6 skipped) and zig fmt --check src/ tools/ build.zig pass. With this commit and the same change in the app's core, the app has 221,308 bytes of static TLS, threads with 256 KiB and 512 KiB stacks start, and the app's plugin replay connects to its NMEA feed and raises one CPA alarm.

std's default signal_stack_size is 256 KiB, and it is a threadlocal,
so it is static TLS in libtile57.a. glibc places static TLS inside each
thread's stack. With lookout's own copy and the Lua shim's caches, the
Lookout Marine Linux app had 614,524 bytes of static TLS, and
pthread_create returned EINVAL for its 512 KiB plugin threads. At 64 KiB
here and in lookout's core, the app has 221,308 bytes.
@beetlebugorg
beetlebugorg merged commit 69b3b1a into main Sep 23, 2026
5 checks passed
@beetlebugorg
beetlebugorg deleted the fix/small-signal-stack branch September 23, 2026 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant