Large heap usage from nvs flash init

glrtheil
Posts: 40
Joined: Tue Dec 07, 2021 2:48 pm

Large heap usage from nvs flash init

Postby glrtheil » Thu Jan 27, 2022 4:26 am

ESP32-WROOM32UE on esp-idf 4.3.2

I'm seeing a massive chunk taken from heap when initializing the "storage" nvs partition, but I'm not sure why.

Partition table:

Code: Select all

# Name,   Type, SubType,  Offset,   Size,  Flags
nvs,      data, nvs,      ,         0x6000
phy_init, data, phy,      ,         0x1000
otadata,  data, ota,      ,         0x2000
ota0,     app,  ota_0,    ,         2M
ota1,     app,  ota_1,    ,         2M
storage,  data, nvs,      ,         0x3DF000
Init code

Code: Select all

    // Initialize NVS
    esp_err_t err = nvs_flash_init();
    if (err == ESP_ERR_NVS_NO_FREE_PAGES) {
        ESP_ERROR_CHECK(nvs_flash_erase());
        err = nvs_flash_init();
    }
    ESP_ERROR_CHECK( err );
    
    //storage nvs partition
    err = nvs_flash_init_partition("storage");
    if (err == ESP_ERR_NVS_NO_FREE_PAGES) {
        ESP_ERROR_CHECK(nvs_flash_erase_partition("storage"));
        err = nvs_flash_init_partition("storage");
    }
    ESP_ERROR_CHECK( err );
Commenting out the "storage" partition init results in a heap savings of almost 82kB, but I don't understand why. I have yet to write any code that gets/sets on that partition. Partition is purposefully at the end of the table so that we can expand for 16MB chips. Maybe this isn't necessary. Should I just combine that with the primary nvs partition? 82k usage results in insufficient memory for our functionality beyond wifi, bluetooth, azure, etc.

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

Re: Large heap usage from nvs flash init

Postby WiFive » Sat Jan 29, 2022 4:17 am

Maybe because nvs stores page metadata in heap and you have 1k pages.

glrtheil
Posts: 40
Joined: Tue Dec 07, 2021 2:48 pm

Re: Large heap usage from nvs flash init

Postby glrtheil » Sat Jan 29, 2022 4:31 pm

WiFive wrote:
Sat Jan 29, 2022 4:17 am
Maybe because nvs stores page metadata in heap and you have 1k pages.
Wow, so in order to use the full 16MB of a chip as nvs it requires usage of the vast majority of the heap. Bummer. Guess we'll have to go the SD card route.

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

Re: Large heap usage from nvs flash init

Postby WiFive » Sat Jan 29, 2022 8:57 pm

Definitely preferred to use SD card or secondary flash to remove the conflict with flash cache. Have you tried other filesystems though?

glrtheil
Posts: 40
Joined: Tue Dec 07, 2021 2:48 pm

Re: Large heap usage from nvs flash init

Postby glrtheil » Tue Feb 01, 2022 3:25 am

WiFive wrote:
Sat Jan 29, 2022 8:57 pm
Definitely preferred to use SD card or secondary flash to remove the conflict with flash cache. Have you tried other filesystems though?
Are you talking about using different filesystems, such as littleFS, to access flash memory? On the hardware we are migrating from, it's all SDFAT on an sd card, but I'm willing to test whatever on esp32. We only need a few MB.

Who is online

Users browsing this forum: No registered users and 36 guests