NVS Arduino Library Wear Leveling?

clearlynotstefan
Posts: 4
Joined: Sat Mar 14, 2020 4:55 pm

NVS Arduino Library Wear Leveling?

Postby clearlynotstefan » Sun Oct 25, 2020 3:31 pm

Hi All,
I'm quite new at all this but am loving it and learning a ton. I'm still using arduino IDE with my esp32 projects but some day I'll graduate. I made smart roller shades using motors with encoders, esp32, and two l98ns (there are 3 shades connected). Rather than using endstop switches, I'm using this NVS library that ports nvs functions to the arduino platform.
https://github.com/rpolitex/ArduinoNvs
My code writes the relevant encoder position when it arrives at its targeted location and writes the target location when it gets a command to move. What I can't figure out is whether this library is capitalizing on Wear Leveling, or if it would need to be modified in some way to improve longevity by wear leveling. My current feeling is that wear leveling is built into the api that the library is using by default and thus I'm covered without doing anything further. I'm doing about 24 writes of integers per day, so I should be set for a while, but it'd still be dumb to keep hitting the same space every time if I could avoid it as replacing the board is a big pain! Any thoughts?

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

Re: NVS Arduino Library Wear Leveling?

Postby ESP_Sprite » Mon Oct 26, 2020 12:39 am

clearlynotstefan wrote:
Sun Oct 25, 2020 3:31 pm
...
My current feeling is that wear leveling is built into the api that the library is using by default and thus I'm covered without doing anything further. I'm doing about 24 writes of integers per day, so I should be set for a while, but it'd still be dumb to keep hitting the same space every time if I could avoid it as replacing the board is a big pain! Any thoughts?

Your feeling is correct, the underlying NVS API uses wear levelling. Especially with only 24 writes a day, flash wear should not be an issue in this use case.

OutOfLine
Posts: 52
Joined: Sat Feb 24, 2018 1:32 pm

Re: NVS Arduino Library Wear Leveling?

Postby OutOfLine » Mon Oct 26, 2020 6:18 pm

As far as I remember it works about like this: nvs stores sequential key value pairs in blocks. New pairs are always added to the end. If the value associated with an existing key gets updated it will *not* be stored in the same old location, but a new pair is added to the end and the old one is marked as deleted. When a block is full a new one is used. If there are too many invalid (deleted) pairs in a given block the remaining valid key value pairs will be copied to the end of the block where new entries are currently written and the old block is marked as free. This avoids wear leveling.

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

Re: NVS Arduino Library Wear Leveling?

Postby ESP_Sprite » Tue Oct 27, 2020 4:24 am

OutOfLine wrote:
Mon Oct 26, 2020 6:18 pm
This avoids wear leveling.
Well, technically this strategy is akin to a log-structured file-system, which is a wear-leveling mechanism all by itself.

OutOfLine
Posts: 52
Joined: Sat Feb 24, 2018 1:32 pm

Re: NVS Arduino Library Wear Leveling?

Postby OutOfLine » Tue Oct 27, 2020 8:59 am

Yes, sorry my wording ("This avoids wear leveling") was wrong. I wanted to say that this avoids problems with wearing. Thank you for correcting that.

Who is online

Users browsing this forum: No registered users and 153 guests