Cut the per-thread signal stack to 64 KB - #81
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
std.options.signal_stack_sizedefaults 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_createreturned 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.zignow setsstd_options.signal_stack_sizeto 64 KiB, which leaves Zig's segfault handler an alternate stack.zig build,zig build test(449 passed, 6 skipped) andzig fmt --check src/ tools/ build.zigpass. 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.