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

platform(esp32c3): embiggen heap #206

Open
hawkw opened this issue Jul 31, 2023 · 3 comments
Open

platform(esp32c3): embiggen heap #206

hawkw opened this issue Jul 31, 2023 · 3 comments
Labels
kind: enhancement New feature or request platform: esp32c3 Specific to the ESP32-C3 hardware platform

Comments

@hawkw
Copy link
Contributor

hawkw commented Jul 31, 2023

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...

@hawkw hawkw added kind: enhancement New feature or request platform: esp32c3 Specific to the ESP32-C3 hardware platform labels Jul 31, 2023
@jamesmunns
Copy link
Contributor

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:

  • Set the size of heap, so it becomes a "stronger" reservation
  • Set a MINIMUM stack size reservation
  • Assert at link time that the heap size + min stack size don't overflow the memory region, giving us a link-time error if these assertions fail.

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
Copy link
Contributor Author

hawkw commented Jul 31, 2023

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
Copy link
Contributor

jamesmunns commented Jul 31, 2023

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:

  • "rwtext" (I dunno what this is)
  • statics (.data and .bss)
  • then heap (grows upward)
  • then stack (starts at the end of ram, grows downward)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: enhancement New feature or request platform: esp32c3 Specific to the ESP32-C3 hardware platform
Projects
None yet
Development

No branches or pull requests

2 participants