-
Notifications
You must be signed in to change notification settings - Fork 7.3k
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
ESP32s3 heap capability allocator leads to memory fragmentation. (IDFGH-12587) #13588
Comments
Hi @PaulMartinsen,
I am currently working on an alternative approach to the startup stack problem that will result in creating a single heap per memory region. That will solve the issue you are facing at the moment. |
Thanks @SoucheSouche for your quick and helpful comments. Particularly for clarifying where heap 3 comes from. Your new approach to join heaps 2 & 3 sounds great and a lot better than allocating into heap 3 explicitly (which would be gone with the new approach). I think this will be a big step forward for us. When I enabled support for Thanks again for your comments and work on the memory management. |
@PaulMartinsen, no problem. we can leave this ticket open and I will link it to the merge request for this heap initialization update so it gets closed when the new implementation gets merged in master. The modifications are quite big so it might take a little while before I can merge. |
Also seeing similar issues - unable to start camera because it wants to make a ~30kb dma-capable allocation, but largest single block of dram is only ~28kb, even though >80kb free dram. esp32 classic does not have this problem afaics because the smaller heaps are first, so get used first, leaving most of the final (largest) heap free. Reordering the [equivalent DRAM] heaps such that the smaller ones are searched/used before the larger would be a huge win, I'm sure. |
@SoucheSouche How is the status of this fix? espressif/tlsf#2 |
@SoucheSouche When will esp-idf update tlsf submodule to get above fix? Will you update tlsf for release branches as well? |
@AxelLin, the MR to update the tlsf submodule is created and under review now. No backport can be done for espressif/tlsf#2 because backporting implies patching the ROM version of the TLSF and since this PR updates static inline functions, it simply can't be done. @PaulMartinsen the new implementation of the heap init process is stalled because of ROM TLSF backport issue as well. In the mean time, I will update the heap init to sort the heaps by increasing size to fix your issue and backport this fix. |
@PaulMartinsen, I created a fix that sorts the heap by increasing size. It is currently under review. |
@SoucheSouche I notice the v5.4 branch includes the fix espressif/tlsf#2 . |
@SoucheSouche How is the status now? Could you share the commit for this fix? |
@AxelLin, the fix has been reviewed and will be merged soon. The commit will be made available when the work is merged and synced with GH. |
I won't call it soon if it takes more than 3 weeks. |
Answers checklist.
General issue report
Please rethink the capability heap's allocation strategy.
Currently
malloc
appears to allocate from the largest heap first. This led to a fragmentation related allocation fault. It would seem better to place smaller objects in smaller heaps first by default. I think the largest heap is just the piece of contiguous memory left after statically scoped variables are placed by the complier.Details
Yesterday I ran out of heap memory. More precisely, I had about 100k free of
MALLOC_CAP_8BIT
capable memory, needed 36k but the largest free block was only 34k. I was sad.It appears the ESP32s3 (and probably other devices):
malloc
fills up the 200k ram first. This is why I was unable to obtain a 36k block of RAM.For reference, here's a summary of my memory disposition:
Questions
heap_caps_malloc
to place an object in heap 3 or 4 in the diagram above? I can't see any combination ofMALLOC_CAP_*
flags that would let me do this before heap 2 was too small for the allocation.The text was updated successfully, but these errors were encountered: