Partitioning heap size vs static ram

themadsens
Posts: 17
Joined: Wed Sep 05, 2018 6:49 pm

Partitioning heap size vs static ram

Postby themadsens » Fri Sep 21, 2018 1:45 pm

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)

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: Partitioning heap size vs static ram

Postby ESP_Angus » Mon Sep 24, 2018 5:24 am

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

themadsens
Posts: 17
Joined: Wed Sep 05, 2018 6:49 pm

Re: Partitioning heap size vs static ram

Postby themadsens » Mon Oct 01, 2018 6:41 pm

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

Xavi92
Posts: 45
Joined: Thu Mar 28, 2019 2:26 pm

Re: Partitioning heap size vs static ram

Postby Xavi92 » Thu Apr 23, 2020 9:39 am

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?

Xavi92
Posts: 45
Joined: Thu Mar 28, 2019 2:26 pm

Re: Partitioning heap size vs static ram

Postby Xavi92 » Mon May 04, 2020 7:37 am

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.

Xavi92
Posts: 45
Joined: Thu Mar 28, 2019 2:26 pm

Re: Partitioning heap size vs static ram

Postby Xavi92 » Thu Oct 08, 2020 12:17 pm

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?

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: Partitioning heap size vs static ram

Postby ESP_Angus » Fri Oct 09, 2020 4:21 am

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

Who is online

Users browsing this forum: No registered users and 138 guests