Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore thread stack size setting #889

Open
kkysen opened this issue Mar 22, 2024 · 0 comments
Open

Restore thread stack size setting #889

kkysen opened this issue Mar 22, 2024 · 0 comments

Comments

@kkysen
Copy link
Collaborator

kkysen commented Mar 22, 2024

dav1d sets the stack size of new worker threads, and initially rav1d did, too. But in order to switch to thread::spawn from the unsafe pthread_create, the creation of Rav1dTaskContexts was moved from a Box<[_]> on the main thread's heap to on the stack in each worker thread. This was done to satisfy the borrow checker and ensure the Rav1dTaskContext's lifetime lasted as long as the thread, which aren't scoped. However, Rav1dTaskContext is huge (258,624 bytes), which is larger than a thread's min stack size, which dav1d sometimes set. Moving it to the heap with Box::new doesn't work since Box::new still takes it as an argument on the stack, and the way to directly create it on the heap through Box::new_uninit or Box::new_zeroed is unstable. Low-level alloc APIs could be used directly as well, but they're not ideal either. But since Rust uses a default stack size of 2 MB usually, there's more than enough stack space for Rav1dTaskContext if we don't set it lower. Thus, that's what we'll do for now (in #887). If memory usage of thread stacks proves to be an issue, we can restore the previous/dav1d behavior, perhaps by setting at least mem::size_of::<Rav1dTaskContext>() of stack size, which would be a net equal in memory usage overall.

kkysen added a commit that referenced this issue Mar 26, 2024
* Fixes #864.

See #889 for why stack size setting was fully removed instead of ported.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant