-
Notifications
You must be signed in to change notification settings - Fork 797
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
What is the maximum stack depth of LFS? #417
Comments
From readme.md (the front page):
Other than that, it's going to be rather processor-dependent. And there are the hardware-level access routines to allow for. |
Memory consuption depends on which API function you use. In my project on AVR8 avarage stack depth is about 500 bytes. But it is really important for me to know calculated (is it possible?) amount of memory required. May be author knows something? |
Stack usage is going to depend not only on the chosen processor, but on the compiler used and the compile options chosen; so I don't see any alternative to measuring it. |
I would also like to know about the worst-case call chain along with a process by which it could be triggered. We've seen filesystem corruption errors occasionally in the field, and I suspect it's due to some unusual lfs code path blowing out the stack. After rebooting, the filesystem (usually a single file) is in a corrupt state and can't be used without either deleting the corrupt file or, in some cases, reformatting the filesystem. |
@zacwbond, hello! |
Ah, sorry for the late response. Unfortunately littlefs's stack usage is an area that needs quite a bit of work. There are quite a few corner cases that can lead to different stack uses, and other than best practices such as no on-stack arrays, I don't have more in-depth info. The relocation logic is definitely the path to be the most concerned about, as it is written recursively. It should be tail-recursive, but whether or not that gets optimized away is at the whim of the compiler. (It only recurses if bad blocks are detected while relocating another bad block, this is rare but I realize it is still an important concern for small stacks). What should be done is this piece of logic should be rewritten as a proper loop. After that it may be interesting to explore more the stack usage in-depth. It will just be a bit tricky given all the routes littlefs can take. |
I put up a PR that should remove all recursion in littlefs, there turned out to be more places with recursion than I thought, though these were bounded by runtime behavior: #658 The current maximum depth measured by GCC's Also worth noting I haven't spent any time optimization the stack usage. There may be some low-hanging fruit to reduce this further but I haven't looked. |
I see a recursive function in the file system.
The text was updated successfully, but these errors were encountered: