Permanently mmap-ed partition?

porkmenudo
Posts: 4
Joined: Tue Jul 19, 2022 2:59 pm

Permanently mmap-ed partition?

Postby porkmenudo » Tue Jul 19, 2022 3:16 pm

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?

ESP_Sprite
Posts: 9708
Joined: Thu Nov 26, 2015 4:08 am

Re: Permanently mmap-ed partition?

Postby ESP_Sprite » Wed Jul 20, 2022 4:05 am

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.

porkmenudo
Posts: 4
Joined: Tue Jul 19, 2022 2:59 pm

Re: Permanently mmap-ed partition?

Postby porkmenudo » Thu Jul 21, 2022 2:19 am

How about if the size of the mmap-ed region is big, say 1MB? Does it have any effect?

ESP_Sprite
Posts: 9708
Joined: Thu Nov 26, 2015 4:08 am

Re: Permanently mmap-ed partition?

Postby ESP_Sprite » 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.
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.

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: Permanently mmap-ed partition?

Postby WiFive » Thu Jul 21, 2022 6:58 am

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

ESP_Sprite
Posts: 9708
Joined: Thu Nov 26, 2015 4:08 am

Re: Permanently mmap-ed partition?

Postby ESP_Sprite » 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.

porkmenudo
Posts: 4
Joined: Tue Jul 19, 2022 2:59 pm

Re: Permanently mmap-ed partition?

Postby porkmenudo » Sat Jul 23, 2022 12:17 pm

Ok, thanks for the clarification!

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: Permanently mmap-ed partition?

Postby WiFive » Sun Jul 24, 2022 7:12 am

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.

porkmenudo
Posts: 4
Joined: Tue Jul 19, 2022 2:59 pm

Re: Permanently mmap-ed partition?

Postby porkmenudo » Mon Jul 25, 2022 9:10 am

Ok, thanks for the clarification!

Who is online

Users browsing this forum: No registered users and 83 guests