Page 1 of 1

Permanently mmap-ed partition?

Posted: Tue Jul 19, 2022 3:16 pm
by porkmenudo
Every example usage of esp_partition_mmap I see is followed by a spi_flash_munmap a few lines later. However,
is there any harm in mmap-ing a partition at the beginning of app_main, using a global variable for out_ptr, and not munmap-ing it for the lifetime of the app?

Re: Permanently mmap-ed partition?

Posted: Wed Jul 20, 2022 4:05 am
by ESP_Sprite
No, not at all. The only thing to keep in mind is that you only have a limited amount of address space to mmap flash in, so if your program does lots of other mmap/munmapping, you need to make sure the maps fit in the available address space at all times.

Re: Permanently mmap-ed partition?

Posted: Thu Jul 21, 2022 2:19 am
by porkmenudo
How about if the size of the mmap-ed region is big, say 1MB? Does it have any effect?

Re: Permanently mmap-ed partition?

Posted: Thu Jul 21, 2022 5:52 am
by ESP_Sprite
Nope.

The ESP32 has 4MiB of address space for this. Some of this space is used for mapping your application code into (size depends on your application; it's always smaller than the size of the application binary, though). The rest is available for you to mmap() into.
The ESP32-S3 (and I think S2 as well) has 32MiB of address space for this, and it's used both for mapping PSRAM and flash. I think we only have PSRAM chips up to 8MiB, which leaves 24MiB of address space for both mapping your app code itself as well as whatever your app decides to map.

Disregarding fragmentation, as long as all maps active at the same time fit within the remaining space, there's absolutely no bad effect from keeping them mapped.

Re: Permanently mmap-ed partition?

Posted: Thu Jul 21, 2022 6:58 am
by WiFive
ESP_Sprite wrote:
Thu Jul 21, 2022 5:52 am
Nope.

The ESP32 has 4MiB of address space for this. Some of this space is used for mapping your application code into (size depends on your application; it's always smaller than the size of the application binary, though). The rest is available for you to mmap() into.
Was this issue of 3mb limit ever resolved in software or in silicon? https://github.com/espressif/esp-idf/issues/1184

Re: Permanently mmap-ed partition?

Posted: Fri Jul 22, 2022 1:49 am
by ESP_Sprite
That's not a bug? As I said, the original ESP32 has 4MiB of address space for mmap()ping things, but as the rodata and non-iram instructions are also mapped using that space, you're left with less actual space free for user mappings.

Re: Permanently mmap-ed partition?

Posted: Sat Jul 23, 2022 12:17 pm
by porkmenudo
Ok, thanks for the clarification!

Re: Permanently mmap-ed partition?

Posted: Sun Jul 24, 2022 7:12 am
by WiFive
ESP_Sprite wrote:
Fri Jul 22, 2022 1:49 am
That's not a bug? As I said, the original ESP32 has 4MiB of address space for mmap()ping things, but as the rodata and non-iram instructions are also mapped using that space, you're left with less actual space free for user mappings.
Esp32 is supposed to have 12mb of irom mapping plus 4mb of drom mapping though.

Re: Permanently mmap-ed partition?

Posted: Mon Jul 25, 2022 9:10 am
by porkmenudo
Ok, thanks for the clarification!