Repository navigation
thread: running out of kernel stacks fails clone and fork with -EAGAIN - #399
Merged
Merged
Conversation
daniel-rossier
force-pushed
the
fix/thread-limit
branch
3 times, most recently
from
December 2, 2026 09:02
614313b to
7b01c66
Compare
Every thread takes one of the CONFIG_MAX_THREADS kernel stack slots, a system-wide pool. When it was empty, thread_create() panicked, so any user program creating threads or forking in a loop brought the whole kernel down after about 30 of them. thread_create() now returns NULL when no slot is free. clone() of a thread then returns -EAGAIN, which musl's pthread_create reports, and fork() checks for a free slot before it duplicates anything, so it fails with -EAGAIN instead of leaving a half-built child. A kernel thread still panics: the kernel has no way to do without it.
daniel-rossier
force-pushed
the
fix/thread-limit
branch
from
December 2, 2026 09:24
7b01c66 to
e420dc4
Compare
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.
Tested on QEMU virt64: a program creating sleeping pthreads in a loop now prints
failed at 28: 11and a following fork() returns -1, and the shell keeps working; before, the kernel panicked at the 29th thread.