Memory management with NVS

Hi

I am using Nordic's NVS system on an nRF5340.
I have successfully got the code mounting, writing and reading from a user defined partition in flash memory.

For now, I am using just two sectors

The documentation here contains information on calculating flash wear etc.

My question:
Does the NVS system automatically manage sector clean-up / erasing, or is this something that I need to manually look after by using the nvs_calc_free_space() function?

Regards

Garrett

Parents Reply Children
  • Hi Swathy

     

    Thanks for the response.

     

    I read the post you refer to.

    The information is not too clear though.

     

    From reading that post, it seems to state:

    • If you are using only one variable, and you keep over-writing that variable, then the NVS system will look after tidy up / erasing, when a sector becomes full
    • If you are continuously writing new data, the NVS system will NOT look after the tidy up / erasing. Instead, when it eventually runs out of space, the write function will return an error.
    • If you have, say, 10 variables, and some of these are being updated from time to time, then...???

     

    In the end, I have about 10 variables I want to store in Flash. My code will be writing to Flash to update a single variable, whenever that variable is changed.

     

    Question: Will the tidy up / erasing be managed automatically by the NVS system, or will I eventually run out of space?

     

    Regards

     

    Garrett

     

  • Hi Garret,

    garrettb said:
    My code will be writing to Flash to update a single variable, whenever that variable is changed.

    It will only be updating a single value in an already stored record in this case right.? Or is it that you are planning to store the new value as a new record.?

    f you are just updating a value in the record, then it would be erased when a sector becomes full. You can read about flash wear here: https://docs.zephyrproject.org/latest/services/storage/nvs/nvs.html#calculating-expected-device-lifetime 

    However, if you keep storing new data as a new record, then there is no mechanism to erase the old data to get space for new data.

    Regards,

    Swathy

  • Hi SwRa,

    I think I understand what you are saying.

    What I am saying is this:

    • I will be saving about 10 variables in Flash.
    • I will be reading them all, on power up.
    • At run time, one or more of these variables will be updated, from time to time - depending on user interaction.

    That's it.

    So in that case, I suppose I have 10 stored records - re-using the same records all the time (whenever user interactions determine that I need to update one or more variables).

    So do I have to manually look after sector erasing etc., or will that be done automatically by the NVS system?

    Thanks 

    Garrett

  • Hi Garrett,

    garrettb said:
    re-using the same records all the time

    In this case, you don't need to manually implement sector erasing since you are not saving it as a new record.

    Regards,

    Swathy

Related