kernel: grant: do not pass T::default()#2003
Conversation
This changes how grant allocation is structured in grant.rs so that the allocation function does not take a copy of the data to be written when creating a new grant. This data can be large if the grant region is large, and it can cause a stack overflow when the allocate function is called.
| // We use `ptr::write` to avoid `Drop`ping the uninitialized memory in | ||
| // case `T` implements the `Drop` trait. | ||
| write(ptr.as_ptr(), data); | ||
| write(ptr.as_ptr(), T::default()); |
There was a problem hiding this comment.
I'm pretty uncertain why this change would actually solve the "grants temporarily take up a ton of stack space" problem. T::default() is still going to return a T, which will be its full size and on the stack. Is passing it into the alloc_unowned() function taking double the size of T on the stack or something?
There was a problem hiding this comment.
Per a slack discussion with bradjc, this change greatly increases the possible size of IPC grants before a kernel stack overflow occurs (previously 364 bytes increases to 2364 bytes). I'm guessing some compiler optimizations are making the magic happen here.
There was a problem hiding this comment.
Right, presumably the compiler can better guess to just allocate the space for the default value directly at ptr.as_ptr() as opposed to on the stack first.
|
bors r+ |
2003: kernel: grant: do not pass T::default() r=alevy a=bradjc This changes how grant allocation is structured in grant.rs so that the allocation function does not take a copy of the data to be written when creating a new grant. This data can be large if the grant region is large, and it can cause a stack overflow when the allocate function is called. The change is pretty simple, but I'm not sure if there is some subtle reason to not do it this way. Fixes the IPC stack overflow issue found in tock#1933. Replaces tock#1976. ### Testing Strategy Running the hail app on hail. ### TODO or Help Wanted n/a ### Documentation Updated - [x] Updated the relevant files in `/docs`, or no updates are required. ### Formatting - [x] Ran `make prepush`. Co-authored-by: Brad Campbell <bradjc5@gmail.com>
This changes how grant allocation is structured in grant.rs so that the
allocation function does not take a copy of the data to be written when
creating a new grant. This data can be large if the grant region is
large, and it can cause a stack overflow when the allocate function is
called.
The change is pretty simple, but I'm not sure if there is some subtle reason to not do it this way.
Fixes the IPC stack overflow issue found in #1933. Replaces #1976.
Testing Strategy
Running the hail app on hail.
TODO or Help Wanted
n/a
Documentation Updated
/docs, or no updates are required.Formatting
make prepush.