Page 1 of 1

duplicate nvs keys

Posted: Mon Jan 08, 2024 12:05 am
by mattia424
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

Re: duplicate nvs keys

Posted: Mon Jan 08, 2024 1:25 pm
by Sprite
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.

Re: duplicate nvs keys

Posted: Thu Jun 04, 2026 3:10 pm
by PETERESP
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.