Repository navigation
Conversation
5cb9aa0 to
e272f26
Compare
|
Cool, like it. |
The max size is what you get today and continues to be the same if you do not set any NVS variable. This PR only allows you to reduce the heap from the default. It does not allow you to grab more memory. (MP already grabs the max it can...) |
|
If you follow this code path starting from here: micropython/ports/esp32/main.c Line 82 in 1f800ca Here malloc is not used but the whole spiram assigned to mp. using malloc results in a much smaller amount of heap assigned to mp (at least in my expirience). That was the reason asking. |
The trick is |
|
Can you please rebase this on latest master? All prerequisites are now merged. |
6d145b8 to
c17912d
Compare
This commit allows the user to limit the micropython heap size by setting NVS variables. This supports: - ensuring that esp-idf has enough memory for multiple TLS connections, TLS plus BLE, etc. - leaving some SPIRAM memory for native modules, such as camera framebuffers - reducing the SPIRAM memory to limit GC sweep times See the docs changes for more details.
|
Rebased against current master and manually tested with the provided test script and examples from the docs against esp-idf v4.2 for the GENERIC and TINYPICO board variants. |
| } | ||
| void *mp_task_heap = heap_caps_malloc(mp_task_heap_size, MALLOC_CAP_8BIT); | ||
| if (avail_heap_size != mp_task_heap_size) { | ||
| printf("Heap limited: avail=%d, actual=%d, left to idf=%d\n", |
There was a problem hiding this comment.
IMO it should not print anything here. The user can programatically inspect the heap sizes and print their own message if needed.
| { MP_ROM_QSTR(MP_QSTR_Partition), MP_ROM_PTR(&esp32_partition_type) }, | ||
| { MP_ROM_QSTR(MP_QSTR_RMT), MP_ROM_PTR(&esp32_rmt_type) }, | ||
| { MP_ROM_QSTR(MP_QSTR_ULP), MP_ROM_PTR(&esp32_ulp_type) }, | ||
| { MP_ROM_QSTR(MP_QSTR_NVS), MP_ROM_PTR(&esp32_nvs_type) }, |
| extern const mp_obj_type_t esp32_partition_type; | ||
| extern const mp_obj_type_t esp32_rmt_type; | ||
| extern const mp_obj_type_t esp32_ulp_type; | ||
| extern const mp_obj_type_t esp32_nvs_type; |
|
This is a useful feature. But I'm wondering if it could be done using normal Python function calls rather than NVS settings, which would then be generalisable to other ports that may want this feature. The reason stm32 had boot.py and main.py split from the beginning was to configure things like this (USB settings, enable certain hardware features) which affect the system in a significant way. For example we could add something like: micropython.resize_heap(lower_bound, upper_bound)which restarts the whole system with a resized heap if its size is not already within the given bounds. (And maybe eventually this function could be used it increase heap size on the fly, eg on unix where it can ask the OS for more memory.) In the end, both NVS settings and Python function calls scale well to many configuration settings. It's just that Python function calls are more Pythonic and could be used on other ports. |
…n-main Translations update from Hosted Weblate
|
We'd like to solve this using an approach similar to described above with boot.py. In particular we now support split heap, so the heap can grow at runtime. |
|
For reference: split heap PR #8526 |
This PR builds on top of #6780 and #6782.
This commit allows the user to limit the micropython heap size by setting NVS variables. This supports:
See the docs changes for more rationale and details.
A test script is included, but not usable with run-tests due to the resets required.