-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Filesystem fails to write file when there should be enough space available #105
Comments
Okay, so removing code function by functions it gets to a point where the fs doesn't error anymore. So, I've created this simplified version, in this case it has around 15KBs of comments at begging of the file and then this test code writing a file: # 12345678901234567
import gc
i = 0
while True:
i += 1
print("Attempt {}".format(i))
print(1, gc.mem_free())
f = open('file.txt','w')
print(2, gc.mem_free())
f.write("something")
f.close() And it fails after 32 writes:
Removing a single character from the header (so making main.py a single byte shorter, to 16118 bytes) fixes the issue. So, those numbers make this a lot more obvious. We don't have a full flash page of "freed" blocks that can be erased. Basically we have 24 KBs for the filesystem, 1 page (4 KBs) is the scratch page, leaving 20 KBs for files. This error appears when main.py is larger than 16 KBs (in physical flash space, not file size). So, with this example script, we have 31 free fs-blocks (128 bytes each), once they are all written into, even if they are all freed, the flash page that contains all these freed blocks also has a block used by main.py @dpgeorge I assumed at this point the microbit-fs would call |
In case it's useful, this is a flash read back after running the example script in my last message. And for info as well, the fs location and size are defined in: |
If there are any free chunks found then it's better to sweep the filesystem and use the available chunks, rather than error out with ENOSPC when there is in fact a bit of space remaining. Fixes issue #105. Signed-off-by: Damien George <[email protected]>
Fixed by b781e65 The problem was that the filesystem would not sweep and reclaim the usable chunks if the number of free chunks was less than 32. With the fix it now sweeps if there are any free chunks, so all available space can now be used. |
@microbit-carlos should we apply this patch also to micro:bit v1? |
Thanks Damien. And yeah, taking in consideration the fix shouldn't change the memory footprint, we should add it to V1 as well 👍 |
OK, same patch is now applied to micro:bit v1. |
From support ticket https://support.microbit.org/helpdesk/tickets/56425 (private)
|
Yes, we'll make a release very soon, which will include this fix. |
Edit: You can ignore the contents of this first message and start reading from comment #105 (comment)
Flashing this large Python file that tries to constantly write a
tello.cfg
file in the filesystem, which is less than a single fs block, works correctly for the first 19 writes, but then it fails:fs-error.py
As the file is less than a fs block in size, and is constantly overwriting it with the same file name, any used fs blocks should be free to be reused, so there should always be available space.
The
1 xxxx
,2 xxxx
,3 xxxx
lines are printing thegc.mem_free()
output, so there is plenty of free RAM to hold a full page of flash into RAM.Something might be going wrong at the point the file system is sweeping? https://github.com/bbcmicrobit/micropython/blob/v1.0.1/source/microbit/filesystem.c#L151
I cannot reproduce it with this smaller similar example:
The text was updated successfully, but these errors were encountered: