tosc-rs / mnemos

An Operating System for Building Small Computers
https://mnemos.dev
Apache License 2.0
259 stars 18 forks source link

platform(esp32c3): embiggen heap #206

Open hawkw opened 1 year ago

hawkw commented 1 year ago

we currently have the heap hardcoded to 32KB. this is quite small, especially for async, because each async task is essentially moving a bit of stack into the heap.

@jamesmunns looked at the esp32c3-hal crate's linker script and determined that the memory region used for the stack and heap is 300KB.

we could probably get away with at least a 64KB heap before we have a significant danger of getting clobbered by a rogue stack frame. even 100KB is probably fine...

jamesmunns commented 1 year ago

the memory region used for the stack and heap is 300KB.

That's for now.

The region is also used for statics, and I have no idea if code size factors into it. Since heap + stack is "whatever you didn't use for other stuff", that size is likely to decrease as time goes on.

Something we COULD do is figure out how to modify/extend the esp32c3 linker scripts, in particular to:

Until we have something like cargo-call-stack, the minimum stack size is going to be a best estimate, but that is better than the current "lol cross your fingers" approach.

hawkw commented 1 year ago

Where are statics placed in this region? Does more statics bring the heap start towards the stack start, or the stack start towards the heap start?

jamesmunns commented 1 year ago

All links from chat yesterday:

The full layout is here (if we are using mb mode?):

https://github.com/esp-rs/esp-hal/blob/main/esp32c3-hal/ld/mb-riscv-link.x#L41-L204

But tl;dr: