Please check if non-volatile storage wear calculation is correct

Hello everyone,

I am using the flash-memory on NRF52840 (using NCS and Zephyr) to store data and I just wanted to ask, if my calculation for the flash usage and wear is correct.

I have three partitions each of size 155648 Bytes (0x26000) with sector-size = 4096 which should lead to a sector count of 155648/4096 = 38 sectors.

I am saving 8-Byte data (a simple unsigned 32-bit counter) once per hour using nvs_write with a unique ID during each save-attempt which should need 16 bytes (including the 8-byte metadata) in total per write. (the ID is increasing every time too).

I should have enough storage for 155648Bytes/16Bytes=9728 entries in one partition, but I only write 8760 entries (one entry per hour for 1 year = 24*365=8760 entries) into one partition, and then start writing to the second. After writing 8760 entries into the second partition, I am writing 8760 into the third partition. After writing 8760 entries into the third partition, I am clearing/erasing the first partition (using nvs_clear), re-init it and start writing to the first again.

According to the data above: is my assumption correct, that each partition is only cleared once per year? I am just asking if the NVS library eventually internally erases any sectors/pages more often than I expect right now. If my assumption is correct, flash wear should not be a topic (3 years * 10000 writes = 30000 years).

My partitions are defined in the dts file as follows:

first_year_storage_partition: partition@4c000 { //flash storage for measurement results of the 1., 4., 7. ... year
  label = "first_year_storage_partition";
  reg = <0x4c000 0x26000>;
};
second_year_storage_partition: partition@72000 { //flash storage for measurement results of the 2., 5., 8. ... year
  label = "second_year_storage_partition";
reg = <0x72000 0x26000>;
};
third_year_storage_partition: partition@98000 { //flash storage for measurement results of the 3., 6., 9. ... year
  label = "third_year_storage_partition";
  reg = <0x98000 0x26000>;
};

Kind regards,

Dom

Parents Reply Children
Related