duplicate nvs keys

mattia424
Posts: 16
Joined: Sun Jan 07, 2024 11:56 pm

duplicate nvs keys

Postby mattia424 » Mon Jan 08, 2024 12:05 am

Hi, I have a "problem" about writing to the nvs partition, every time I do the get on a key e.g. nvs_get_u64() and then dump the partition I see that it goes to add 64bytes, in the queue of the previous ones, which contain the key and the new value set (in this case 4bytes)
But is such behavior normal? Shouldn't it update the same key? Maybe it does this to not use the same memory blocks all the time?

Image

Sprite
Espressif staff
Espressif staff
Posts: 10612
Joined: Thu Nov 26, 2015 4:08 am

Re: duplicate nvs keys

Postby Sprite » Mon Jan 08, 2024 1:25 pm

Yep, that is normal and desired. The trick with flash is that it only allows for a certain amount of erase cycles per 4Kbyte page, so ideally you want to keep the amount of erases to a minimum. So what NVS does instead is to write the new value after all the old values, and later when you request the value it gives you the newest. Only when there's no space left, it'll collect all the old values into a page and erase that page to free up some space.

PETERESP
Posts: 6
Joined: Mon May 25, 2026 7:45 am

Re: duplicate nvs keys

Postby PETERESP » Thu Jun 04, 2026 3:10 pm

it looks like use 24 bytes to storage the one byte "rebootcount", whose value varies from 0 to 255,consequently showing a glance of ASCII table.
Last edited by PETERESP on Thu Jun 04, 2026 3:36 pm, edited 1 time in total.

Who is online

Users browsing this forum: coccocbot, GPTBot and 2 guests