littlefs panic when partition is full

owenjames
Posts: 12
Joined: Fri Sep 02, 2022 6:24 pm

littlefs panic when partition is full

Postby owenjames » Tue Apr 02, 2024 1:28 am

I am using littlefs to store logs to internal flash and have been testing the behaviour when the littlefs partition is full. I expected a graceful failure of fopen() or fprintf() but I get a DivideByZero exception from lfs_alloc in the bowels of the library from fclose(). It seems that I need to leave 8K of unused space to avoid this. Am I missing some config?

ESP-IDF v5.1.2
litlefs v1.14.2

ESP_adokitkat
Posts: 52
Joined: Thu Jun 22, 2023 12:50 pm

Re: littlefs panic when partition is full

Postby ESP_adokitkat » Mon Apr 15, 2024 11:27 am

Thank you for the report. We will investigate this. However it may be an issue on the LittleFS side. If so we will notify the maintainers.

bnp117
Posts: 17
Joined: Fri Jun 15, 2018 3:08 am

Re: littlefs panic when partition is full

Postby bnp117 » Mon Apr 15, 2024 6:53 pm

@owenjames can you post the full log? I believe this is an upstream core littlefs issue (unexpected divide by zero); esp_littlefs should be reporting an appropriate error code. The log can help us raise an appropriate issue in https://github.com/littlefs-project/littlefs

owenjames
Posts: 12
Joined: Fri Sep 02, 2022 6:24 pm

Re: littlefs panic when partition is full

Postby owenjames » Tue Apr 16, 2024 1:45 am

Sorry, I don't have the log now but my notes show the exception occurs in lfs.c (when block_count is zero):
  1. static int lfs_alloc(lfs_t *lfs, lfs_block_t *block) {
  2. ...
  3.         // In order to keep our block allocator from spinning forever when our
  4.         // filesystem is full, we mark points where there are no in-flight
  5.         // allocations with a checkpoint before starting a set of allocations.
  6.         //
  7.         // If we've looked at all blocks since the last checkpoint, we report
  8.         // the filesystem as out of storage.
  9.         //
  10.         if (lfs->lookahead.ckpoint <= 0) {
  11.             LFS_ERROR("No more free space 0x%"PRIx32,
  12.                     (lfs->lookahead.start + lfs->lookahead.next)
  13.                         % lfs->cfg->block_count);
  14.             return LFS_ERR_NOSPC;
  15.         }

bnp117
Posts: 17
Joined: Fri Jun 15, 2018 3:08 am

Re: littlefs panic when partition is full

Postby bnp117 » Tue Apr 16, 2024 11:14 pm

In this context,

Code: Select all

block_count
is the number of blocks in the entire filesystem, not free ones remaining. In newer versions of littlefs, the

Code: Select all

lfs_config.block_count
value can be set to 0 to be inferred from an existing filesystem; on mount

Code: Select all

lfs.block_count
is then appropriately populated.

If you can get a fullstack trace, or other info, it would greatly help! Upstream littlefs does have exhaustion tests, and I cannot find a location by inspection where a DivideByZero could occur. Thanks!

Also, I just released esp_littlefs v1.14.3 that updates littlefs v2.9.0 to v2.9.1, incase that fixes anything.

bnp117
Posts: 17
Joined: Fri Jun 15, 2018 3:08 am

Re: littlefs panic when partition is full

Postby bnp117 » Wed Apr 17, 2024 3:41 am

Based on huming2207 being able to reproduce it here: https://github.com/joltwallet/esp_littlefs/issues/183

I opened up a PR that may resolve the issue here: https://github.com/littlefs-project/littlefs/pull/966

Will update when it gets merged and and makes its way to esp_littlefs.

bnp117
Posts: 17
Joined: Fri Jun 15, 2018 3:08 am

Re: littlefs panic when partition is full

Postby bnp117 » Wed Apr 17, 2024 6:15 pm

fixed in core littlefs v2.9.2, and subsequently in esp_littlefs v1.14.4

Who is online

Users browsing this forum: No registered users and 114 guests