memorysafety / memorysafety/rav1d

Restore thread stack size setting

Open
#889 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

performance
Dominant language
Assembly
Stars
643
Forks
81
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Trace the worker-thread creation and the construction of Rav1dTaskContext, paying attention to the move from pthread_create to thread::spawn and the decision described alongside #887. Determine how the former dav1d stack-size behavior can be restored without putting this large context on the stack; done means worker stacks accommodate Rav1dTaskContext while preserving thread lifetime and memory goals.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
performance
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.