tobozo / ESP32-PsRamFS

🐏 💾 RamDisk for ESP32-Arduino using PsRam and fs::FS
MIT License
48 stars 10 forks source link

Memory leak somewhere #15

Open jfseaman opened 1 month ago

jfseaman commented 1 month ago

There seems to be a memory leak.

Where? Library or in PSRamFS_Test.ino?

I did not audit PSRamFS_Test completely. I did change all the ESP_LOGx(...) to Serial.printf and fixed the formatting. I changed it to run in loop() instead of setup() with a halt at the end. I kept setup code in setup. Not much of that.

I tried a Arduino Nano ESP32 (16M flash, 8M PSRAM) and a Espressif ESP32-S3 De Kit N8R8 (8M flash, 8M PSRAM)

The leak is in both.

The biggest annoyance is that the leak is different for each iteration.

It could be as simple as an unpaired create/close. Like I said, didn't do a complete audit of PSRamFS_Test.ino and didn't create a sketch from scratch with more limited use of the library.

The leak is from 0 to 440 byes. Varies each run, each pass through loop.

23:13:16.615 -> Free PSRAM: 8385672 23:13:16.615 -> Running test setup_tesrdown 23:13:16.615 -> running test format_mounted partition 23:13:16.658 -> Free PSRAM: 8385672 ... 23:13:19.077 -> Test complete 23:13:19.077 -> Starting_Free_PSRAM (8385672) != ESP.getFreePsram() (8385456) ... 23:14:21.563 -> Test complete 23:14:21.563 -> Starting_Free_PSRAM (8385672) != ESP.getFreePsram() (8385244) ... 23:15:24.009 -> Test complete 23:15:24.009 -> Starting_Free_PSRAM (8385672) != ESP.getFreePsram() (8385032) ... 23:16:26.494 -> Test complete 23:16:26.494 -> Starting_Free_PSRAM (8385672) != ESP.getFreePsram() (8384820) ... 23:17:28.963 -> Test complete 23:17:28.963 -> Starting_Free_PSRAM (8385672) != ESP.getFreePsram() (8384588)

tobozo commented 1 month ago

hi,

thanks for your feedback :+1:

folder related functions are probably leaky, does it improve if you limit the tests to read/write/append/rename/delete ?

jfseaman commented 4 weeks ago

I don't know. Not tested that way.

I would have to write sketches to specifically test each realm of functions. File, directory, etc... to find the leak.

Or exclude the directory functions from example and see if it goes away.

It will be a couple days to do that.

tobozo commented 4 weeks ago

yes I meant to just exclude the directory functions from the example

have you tried commenting out this part?

#define UNIT_TESTS
jfseaman commented 4 weeks ago

Found it:

Application level error in PSRamFS_test.ino at line 441: if( ! PSRamFS.setPartitionSize( ESP.getFreePsram()/2 ) ) { // try to allocate half of psram

Change to: if( ! PSRamFS.setPartitionSize( ESP.getMaxAllocHeap()/2 ) ) { // try to allocate half of psram

No leaks

jfseaman commented 4 weeks ago

I'm stress testing it thoroughly ;)