Replies: 5 comments 3 replies
-
Your definitions are right.
No - littlefs goes to great lengths to ensure that this doesn't happen, re-mapping sectors to minimise wear. You might like to read this doc which describes the ideas behind its design. |
Beta Was this translation helpful? Give feedback.
-
@peterhinch Thank you to point me that doc, I saw there that What do you think about to use esp nvs instead normal write mode? The nvs does I'm thinking to migrate my normal mode (using LittleFs) to NVS because in my tests the NVS is very very faster than normal write when data is less than 1KB. What do you think about that? Follow bellow my code with the real test: import json, time
from esp32 import NVS
nvs = NVS("datax1")
list_data = []
list_data.append('.' * 1)
list_data.append('.' * 10)
list_data.append('.' * 50)
list_data.append('.' * 100)
list_data.append('.' * 200)
list_data.append('.' * 300)
list_data.append('.' * 400)
list_data.append('.' * 500)
list_data.append('.' * 600)
list_data.append('.' * 700)
list_data.append('.' * 800)
list_data.append('.' * 900)
list_data.append('.' * 1000)
list_data.append('.' * 1200)
list_data.append('.' * 1400)
list_data.append('.' * 1600)
list_data.append('.' * 1800)
list_data.append('.' * 2000)
list_data.append('.' * 2500)
list_data.append('.' * 3000)
list_data.append('.' * 3500)
list_data.append('.' * 4000)
for data in list_data:
datax1 = json.dumps(data)
key = 'datax1'
data = datax1
len_data = len(data)
start_time = time.ticks_ms()
nvs.set_blob(key, data)
nvs.commit()
end_time = time.ticks_ms()
delta_time_nvs = time.ticks_diff(end_time, start_time)
nvs.erase_key(key)
start_time = time.ticks_ms()
f = open('test.json', 'w')
f.write(data)
f.close()
end_time = time.ticks_ms()
delta_time_normal_mode = time.ticks_diff(end_time, start_time)
print(f'Time to write {len_data} bytes is -> NVS: {delta_time_nvs} ms, Normal Mode: {delta_time_normal_mode} ms')
print('----------------------') Output: $ mpremote run nvs_vs_normal_write_test_01.py
Time to write 3 bytes is -> NVS: 1 ms, Normal Mode: 6 ms
----------------------
Time to write 12 bytes is -> NVS: 2 ms, Normal Mode: 16 ms
----------------------
Time to write 52 bytes is -> NVS: 2 ms, Normal Mode: 7 ms
----------------------
Time to write 102 bytes is -> NVS: 2 ms, Normal Mode: 8 ms
----------------------
Time to write 202 bytes is -> NVS: 3 ms, Normal Mode: 115 ms
----------------------
Time to write 302 bytes is -> NVS: 3 ms, Normal Mode: 51 ms
----------------------
Time to write 402 bytes is -> NVS: 58 ms, Normal Mode: 47 ms
----------------------
Time to write 502 bytes is -> NVS: 4 ms, Normal Mode: 61 ms
----------------------
Time to write 602 bytes is -> NVS: 4 ms, Normal Mode: 61 ms
----------------------
Time to write 702 bytes is -> NVS: 4 ms, Normal Mode: 59 ms
----------------------
Time to write 802 bytes is -> NVS: 5 ms, Normal Mode: 69 ms
----------------------
Time to write 902 bytes is -> NVS: 63 ms, Normal Mode: 49 ms
----------------------
Time to write 1002 bytes is -> NVS: 5 ms, Normal Mode: 48 ms
----------------------
Time to write 1202 bytes is -> NVS: 5 ms, Normal Mode: 49 ms
----------------------
Time to write 1402 bytes is -> NVS: 70 ms, Normal Mode: 52 ms
----------------------
Time to write 1602 bytes is -> NVS: 14 ms, Normal Mode: 58 ms
----------------------
Time to write 1802 bytes is -> NVS: 68 ms, Normal Mode: 64 ms
----------------------
Time to write 2002 bytes is -> NVS: 102 ms, Normal Mode: 59 ms
----------------------
Time to write 2502 bytes is -> NVS: 70 ms, Normal Mode: 72 ms
----------------------
Time to write 3002 bytes is -> NVS: 104 ms, Normal Mode: 76 ms
----------------------
Time to write 3502 bytes is -> NVS: 62 ms, Normal Mode: 96 ms
----------------------
Time to write 4002 bytes is -> NVS: 182 ms, Normal Mode: 85 ms
---------------------- |
Beta Was this translation helpful? Give feedback.
-
The flash block size is 4 kB (4096 bytes) on the ESP32-S3 module. |
Beta Was this translation helpful? Give feedback.
-
What are the nvs advantages (in addition to being very faster) that you see over normal mode write using littlefs? And about the nvs disadvantages? |
Beta Was this translation helpful? Give feedback.
-
Working through similar findings with LFS2 previously I found after modifying Roberts code:
yielded:
So we see that LFS2 behaves badly for very small file sizes, although it is able to accommodate more than one file into a 4096 bytes block. Roughly we observe the first saw-tooth above the 4K file size. But the constant upper limit at a 4-fold space consumption is not there. Seems that the nfs advantage is just in this area, regarding file space. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi all
I Have a question to understand how to consider write/erase flash cycles with
MicroPython
. I'm using anEspressif ESP32-S3
module (ESP32-S3-WROOM-1
)N16R2
, so it has 16 MB SPI Flash and 2MB SPI RAM.Some definitions:
LittleFS
filesystem. As I'm usingMicroPython 1.20.0
(official firmware .bin), until I know, the default filesystem in the 1.20.0 isLittleFS
right?ESP32-S3
module has, of course, a limit of write/erase cycles. That can be between10k-100k cycles
, that depends temperature that will be run, etc.If some that definitions above is not correct, please, fix me.
Well, now the question:
When I'm writing new data in each one of that files, will the files continue located forever in the same sectors?
My goal with this question is to count how much write cycles I can have using my scenario until reach 10k cycles (for example):
a. Need I to consider in my scenario that each file that I will write new data as +1 cycle?
b. Or the correct is to consider as +1 cycle just when I write new data in all my files (if each file will be in the same sector forever)? Or
c. Or both (a and b is wrong), so how I should be consider?
A complement question: considering my scenario, how many bytes has a sector and how is the relation between a sector and a Flash block size?
This doc say that by default Sector size is 512 bytes (https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/storage/wear-levelling.html#:~:text=Sector%20size%20is%20512%20bytes)
My use:
Espressif module ESP32-S3-WROOM-1-N16R2
MicroPython 1.20.0
Thank you very much!
Beta Was this translation helpful? Give feedback.
All reactions