Is NVS iteration order maintained?
Posted: Fri Dec 19, 2025 2:59 pm
After writing key+values into NVS, is the iteration order maintained across power cycles? Across defrags? Across deletions and insertions?
Examples:
Context: I need to implement a nonvolatile ring buffer - if `nvs_entry_find()/next()` always return keys in insertion order, it simplifies locating the oldest object for garbage collection. I've tried a few, and it seems ok, but not to the point I'd rely on it. It seems possible, since NVS is a log-structured filesystem(ish).
Examples:
- If I write keys "A", "B", "C", would the iteration order then be "A", "B", "C"?
- If I write keys "A", "B", "C", then delete "B", would the iteration order then be "A", "C"?
- If I write keys "A", "B", "C", then write key "D", would the iteration order always be "A","B","C","D"?
Context: I need to implement a nonvolatile ring buffer - if `nvs_entry_find()/next()` always return keys in insertion order, it simplifies locating the oldest object for garbage collection. I've tried a few, and it seems ok, but not to the point I'd rely on it. It seems possible, since NVS is a log-structured filesystem(ish).