Page 1 of 1
Partitioning heap size vs static ram
Posted: Fri Sep 21, 2018 1:45 pm
by themadsens
Hello
It looks like the available ram space is a roundly even split between heap and static allocations.
Is there a way to increase one of these (at the cost of the other of course). Specifically, we do not need 187 KB heap space, but could do with a bit more than 180kB static allocations
Cheers /Flemming
Code: Select all
<BOOT>
I (0) cpu_start: Starting scheduler on APP CPU.
PREAMBLE: This is an ESP32 chip with 2 CPU cores, WiFi/BT/BLE, Heap: 187328
<MAKE SIZE>
Used static DRAM: 119256 bytes ( 61480 available, 66.0% used) (ca 180 kb total. How to increase this for heap)
Re: Partitioning heap size vs static ram
Posted: Mon Sep 24, 2018 5:24 am
by ESP_Angus
Hi flemming,
The situation is similar to what you describe, but not quite that.
Memory used for heap will always be the total of all DRAM and IRAM in the chip, minus any which is used for static allocations (static variables - .data & .bss - for DRAM and instruction code for IRAM).
However, there is a 176KB limit on maximum static DRAM allocation. This is because of some dis-continuities in the ESP32's available DRAM (linker requires all memory which is statically allocated to a single section - ie .bss or .data - to be one contiguous block, and the largest contiguous block of available DRAM is currently 176KB).
Some progress was made to remove this limit a while back, but unfortunately it hasn't been completed yet.
Right now the best thing to do is to refactor your code so some large buffers/etc are allocated from heap when the app first starts up, instead of being static.
Angus
Re: Partitioning heap size vs static ram
Posted: Mon Oct 01, 2018 6:41 pm
by themadsens
Thanks for the reply.
The plan was to set aside a big chunk of static ram for use with a custom allocator for Lua. As it turns out it is easier to just add this static chunk to the heap like so:
Code: Select all
uint8_t APPLuaHeapBuf[50 * 1024];
...
heap_caps_add_region((intptr_t) APPLuaHeapBuf, (intptr_t) (APPLuaHeapBuf + sizeof(APPLuaHeapBuf)));
However, it seems that BSS data like this is rolled into the flash image and takes up space in the APP partition. Is there a way to avoid this? maybe with something like SOC_RESERVE_MEMORY_REGION() ??
TIA /Flemming
Re: Partitioning heap size vs static ram
Posted: Thu Apr 23, 2020 9:39 am
by Xavi92
ESP_Angus wrote: ↑Mon Sep 24, 2018 5:24 am
Some progress was made to remove this limit a while back, but unfortunately it hasn't been completed yet.
Sorry for reviving such an old topic, but I am interested in this. Do you know if any progress has been made on this so far?
Re: Partitioning heap size vs static ram
Posted: Mon May 04, 2020 7:37 am
by Xavi92
ESP_Angus wrote: ↑Mon Sep 24, 2018 5:24 am
Some progress was made to remove this limit a while back, but unfortunately it hasn't been completed yet.
Is there any progress on this? I'm interested in this limitation to be removed.
Re: Partitioning heap size vs static ram
Posted: Thu Oct 08, 2020 12:17 pm
by Xavi92
ESP_Angus wrote: ↑Mon Sep 24, 2018 5:24 am
Some progress was made to remove this limit a while back, but unfortunately it hasn't been completed yet.
Hi, are there any news about this topic? Is there any way I could help removing this limitation?
Re: Partitioning heap size vs static ram
Posted: Fri Oct 09, 2020 4:21 am
by ESP_Angus
Hi Xavi92,
No progress I'm afraid, there's still an upper limit on static RAM size. Fixing it is unfortunately also very fiddly as there are some ROM code functions that need to be replaced.
Can you tell us anything about what your goal is that needs this to be fixed? There might another option.
Angus