← index #10049PR #7963
Related · high · value 1.013
QUERY · ISSUE

When esp32S3 uses microython, it uses too much internal memory

openby Zhengqinze05opened 2022-11-22updated 2024-09-01
bug

I use ESP32S3, which uses 100k of internal memory when using microython. My board has PSRAM, gc_ Init() uses the memory requested by

PSRAM.Theoretically, except for 16k In addition to the mp_task () thread, other memory should be requested from PSRAM. Miraculously, I

didn't apply for memory elsewhere. When I started the microython thread, the system disappeared for no reason

100k of memory. It is not the heap memory consumed during use. I tried to add judgment in the mp_task() thread so that all Python related

code would not run, but the memory did not Reduce. Unless the thread is annotated or the code inside the thread is annotated, the

memory will be reduced by 100k. By comparing the memory size of whether to start microython when compiling, I find that it seems to be

allocated when compiling.But I still don't know where to use the memory. Does anyone know where these memories are consumed and

how to reduce them. Any answer would be highly appreciated.

This is the memory distribution at compile time without the mp_task () annotation
Used static IRAM: 139730 bytes ( 222510 remain, 38.6% used)
.text size: 138703 bytes
.vectors size: 1027 bytes
Used stat D/IRAM: 67137 bytes ( 105791 remain, 38.8% used)
.data size: 30641 bytes
.bss size: 36496 bytes
Used Flash size : 1793666 bytes
.text : 1363395 bytes
.rodata : 430015 bytes
Total image size: 1964037 bytes (.bin may be padded larger)

This is the memory distribution at compile time after the mp_task () annotation:
Used static IRAM: 71138 bytes ( 291102 remain, 19.6% used)
.text size: 70111 bytes
.vectors size: 1027 bytes
Used stat D/IRAM: 35457 bytes ( 137471 remain, 20.5% used)
.data size: 17121 bytes
.bss size: 18336 bytes
Used Flash size : 480211 bytes
.text : 354359 bytes
.rodata : 125596 bytes
Total image size: 568470 bytes (.bin may be padded larger)

CANDIDATE · PULL REQUEST

ESP32: Set maximum heap size in mpconfigport.h.

closedby glenn20opened 2021-11-03updated 2023-05-25
port-esp32

The problem: Too much memory allocated to heap on ESP32S2.

Micropython allocates too much RAM to the microython heap on ESP32S2 leaving insufficient RAM available for other IDF functions (causing panics in networking and espnow code). On the ESP32 101563 bytes is allocated to the heap by default. On the ESP32S2 this is ~120kB.

NOTE: when this this bug is resolved the default heap size on ESP32S2 will increase to ~160kB.

This fix: Set a maximum allowed value for the heap size.

Micropython currently allocates the largest available memory block to the micropython heap. This PR allows the maximum allowed heap size to be #defined as MICROPY_HEAP_SIZE_MAX. The default value is set to 104000 in mpconfigport.h and can be overridden in the board definition files: mpconfigboard.h.

With this default setting the espnow and wireless functions no longer generate panics on the ESP32S2.

Other approaches

https://github.com/micropython/micropython/pull/6785 allows the heap size to be set at run time (from NVS variables) which is a useful and powerful feature.

Nonetheless, it should be possible to deterministically set a reasonable maximum for the heap size"out of the box" in a compiled image that allows normal operation of an ESP32XX chip irregardless of exactly how the memory on the chip is fragmented.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied