breadboard-os icon indicating copy to clipboard operation
breadboard-os copied to clipboard

LittleFS is still using malloc()

Open mcknly opened this issue 10 months ago • 2 comments

Even though buffers are provided to littlefs (see storman_service.c in 94b76e44e503777ae5352db12459fd63a14b2633), it still seems to be calling malloc() and causing FreeRTOS to overflow its heap. Increasing FreeRTOS heap in hardware/[platform]/rtos_config.h is a workaround, but we really shouldn't have LFS or any other task calling malloc.

This can be tested by placing a breakpoint at littlefs/littlefs/lfs_util.h line 249 and calling a flash filesystem function via /mnt/flash0, it will only hit the breakpoint if LFS is using malloc.

mcknly avatar Feb 13 '25 21:02 mcknly

Just getting back to having some free time and was pulling down the latest to get it to compile. Seems a lot of awesome improvements have been made.

I can't seem to get it to compile though. This is a barebones compile. My Cmake settings:

# PROJECT NAME - in quotes, no spaces
set(PROJ_NAME "ALDA")

# PROJECT VERSION - in quotes, no spaces, can contain alphanumeric if necessary
set(PROJ_VER "0.1")

# CLI INTERFACE - 0: use UART for CLI (default), 1: use USB for CLI
set(CLI_IFACE 1)

# MCU PLATFORM - set the MCU platform being used (i.e. the subdir in 'hardware/')
set(PLATFORM rp2xxx)

# BOARD - set the board being used (platform-specific prebuild.cmake contains more information about boards)
set(BOARD pico_w)

# HOSTNAME - hostname will be shown at CLI prompt, and used for network connections
set(HOSTNAME "ALDA")

# BUILD OPTIONS - individual features which can be enabled or disabled
option(ENABLE_MOTD "Enable Message of the Day print at boot" true)
option(ENABLE_WIFI "Enable WiFi support" true)
option(ENABLE_HTTPD "Enable httpd web server" true)`

And the error I'm getting.

[ 52%] Linking CXX executable ALDA.elf
/usr/bin/../lib/gcc/arm-none-eabi/14.3.1/../../../../arm-none-eabi/bin/ld: ALDA.elf section `.heap' will not fit in region `RAM'
/usr/bin/../lib/gcc/arm-none-eabi/14.3.1/../../../../arm-none-eabi/bin/ld: section .stack1_dummy VMA [20040000,200407ff] overlaps section .heap VMA [2003fd80,2004057f]
/usr/bin/../lib/gcc/arm-none-eabi/14.3.1/../../../../arm-none-eabi/bin/ld: region `RAM' overflowed by 1408 bytes
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/ALDA.dir/build.make:3820: ALDA.elf] Error 1
make[1]: *** [CMakeFiles/Makefile2:1989: CMakeFiles/ALDA.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

I thought that maybe I was enabling features but even with Wi-Fi support disabled and not using USB CLI I get the same heap error and the 1408 bytes is consistent no matter what I change.

I'm using the latest versions of everything. How much did you increase the heap size? My shots in the dark do not seem to be working.

fatdollar avatar Nov 10 '25 17:11 fatdollar

#elif defined(USING_RP2040) && defined(HW_USE_WIFI)
#define RTOS_HEAP_SIZE (184*1024) // RP2040 with wireless stack
#endif

I was able to get it to compile by reducing the heap size by 2 was originally 186*1024

I'm at least able to get it to run at this point I'll see about digging into the malloc/heap issue some more

fatdollar avatar Nov 10 '25 22:11 fatdollar