Page 1 of 1

Reducing RAM usage

Posted: Mon Feb 14, 2022 12:20 pm
by william.ferguson.au
OK, I've spent 2 days now reading through the docs on reducing RAM usage and applying various tweaks.
I have managed to reduce the used D/IRAM from 137,323 to 110,855 leaving me 77,561 (on an ESP32-S2 ESP-IDFv4).

I need to reduce the RAM because soft app provisioning is now failing irregularly because it cannot allocate the memory for the httpd_server task when setting up soft app provisioning.

The thing is, my code is using very little memory, but a bunch of the ESP components grab huge chunks.
Looking for help on what to trim and how.
This is what the size-components looks like.

https://docs.google.com/spreadsheets/d/ ... sp=sharing

And when I start soft app provisioning this is what happens:

Code: Select all

E (16068) wt_wifi_prov: About to start provisioning
Heap summary for capabilities 0x0000180E:
  At 0x3ffcd110 len 192240 free 48404 allocated 137388 min_free 20148
    largest_free_block 24564 alloc_blocks 390 free_blocks 13 total_blocks 403
  At 0x3fffc000 len 14864 free 13096 allocated 0 min_free 13096
    largest_free_block 13044 alloc_blocks 0 free_blocks 1 total_blocks 1
  Totals:
    free 61500 allocated 137388 min_free 33244 largest_free_block 24564

I (16108) wifi:state: run -> init (0)
I (16108) wifi:pm stop, total sleep time: 10462756 us / 13473309 us
W (16118) wifi:<ba-del>idx
I (16118) wifi:new:<9,0>, old:<9,0>, ap:<255,255>, sta:<9,0>, prof:1

E (16168) osal.h: Requesting httpd_server task with stackSize=4096 bytes

Heap summary for capabilities 0x0000180E:
  At 0x3ffcd110 len 192240 free 19528 allocated 165904 min_free 19528
    largest_free_block 12276 alloc_blocks 420 free_blocks 12 total_blocks 432
  At 0x3fffc000 len 14864 free 13096 allocated 0 min_free 13096
    largest_free_block 13044 alloc_blocks 0 free_blocks 1 total_blocks 1
  Totals:
    free 9880 allocated 188528 min_free 9552 largest_free_block 4084

E (16238) osal.h: Could not return Task ret=-1


William

Re: Reducing RAM usage

Posted: Tue Feb 15, 2022 1:39 am
by ESP_Sprite
Be aware that the only proper answer may be 'move to a S3, the S2 doesn't have the ram for the application you need'... but with that being said, we do have a page in our docs for ram optimization; perhaps there's something useful in there?

Re: Reducing RAM usage

Posted: Tue Feb 15, 2022 2:04 am
by william.ferguson.au
Thanks, but that's the page I have been working from the last few days.

This memory issue didn't used to occur. We might have to rollback from v4.4 to an earlier version of v4.3 but I'd rather not.

We have several hundred deployed devices, so switching out the S2 is not an option at this point.

The top 8 consume 91K of static - that's enormous!
Is there any way to reduce the amount of static RAM allocated to the hungriest components?

Code: Select all

Archive File	    DRAM .data	DRAM .bss	IRAM0 .text	ram_st_total
libpp.a	                  2404	          313	 14925		   18642
libfreertos.a	          1564	         1000	  3467	           16456
libnet80211.a	           923	         6085	  4656	           11664
libphy.a	          1418	          560	  9406	           11384
libspi_flash.a	          1976	          416	  8253	           10645
libesp_hw_support.a	   481	           36	  8475	            9035
libheap.a	          2709	            8	  4599	            7316
libhal.a	            16	            0	  6081	            6097
				
Total	                11,491	         9418	69,862		  91,239

Re: Reducing RAM usage

Posted: Tue Feb 15, 2022 2:24 am
by william.ferguson.au
Where can I find a description for what each of these components is and where they are getting included from?
Some are obvious - eg freeRTOS, but libpp ??

Re: Reducing RAM usage

Posted: Tue Feb 15, 2022 4:50 am
by WiFive
Libpp is part of the closed source wifi libraries

Re: Reducing RAM usage

Posted: Sat Mar 16, 2024 8:51 am
by dzungpv
william.ferguson.au wrote:
Mon Feb 14, 2022 12:20 pm
OK, I've spent 2 days now reading through the docs on reducing RAM usage and applying various tweaks.
I have managed to reduce the used D/IRAM from 137,323 to 110,855 leaving me 77,561 (on an ESP32-S2 ESP-IDFv4).

I need to reduce the RAM because soft app provisioning is now failing irregularly because it cannot allocate the memory for the httpd_server task when setting up soft app provisioning.

The thing is, my code is using very little memory, but a bunch of the ESP components grab huge chunks.
Looking for help on what to trim and how.
This is what the size-components looks like.

https://docs.google.com/spreadsheets/d/ ... sp=sharing

And when I start soft app provisioning this is what happens:

Code: Select all

E (16068) wt_wifi_prov: About to start provisioning
Heap summary for capabilities 0x0000180E:
  At 0x3ffcd110 len 192240 free 48404 allocated 137388 min_free 20148
    largest_free_block 24564 alloc_blocks 390 free_blocks 13 total_blocks 403
  At 0x3fffc000 len 14864 free 13096 allocated 0 min_free 13096
    largest_free_block 13044 alloc_blocks 0 free_blocks 1 total_blocks 1
  Totals:
    free 61500 allocated 137388 min_free 33244 largest_free_block 24564

I (16108) wifi:state: run -> init (0)
I (16108) wifi:pm stop, total sleep time: 10462756 us / 13473309 us
W (16118) wifi:<ba-del>idx
I (16118) wifi:new:<9,0>, old:<9,0>, ap:<255,255>, sta:<9,0>, prof:1

E (16168) osal.h: Requesting httpd_server task with stackSize=4096 bytes

Heap summary for capabilities 0x0000180E:
  At 0x3ffcd110 len 192240 free 19528 allocated 165904 min_free 19528
    largest_free_block 12276 alloc_blocks 420 free_blocks 12 total_blocks 432
  At 0x3fffc000 len 14864 free 13096 allocated 0 min_free 13096
    largest_free_block 13044 alloc_blocks 0 free_blocks 1 total_blocks 1
  Totals:
    free 9880 allocated 188528 min_free 9552 largest_free_block 4084

E (16238) osal.h: Could not return Task ret=-1


William
Do you solve your problem? Same project of mine on S3 it only take 90KB but on the S2 it take 130KB ram, I don't know why and the provision frequently failed. I have S2 with 2MB PSRAM on IDF 4.4

Re: Reducing RAM usage

Posted: Sun Mar 17, 2024 11:09 pm
by william.ferguson.au
I can't recall, sorry.

What does the static allocation for the various libraries look like on the 2 SOCs?
Is there an obvious extra library or jump in library size?