mempool can result in OOM while memory is available #15154
Labels
area: Kernel
bug
The issue is a bug, or the PR is fixing a bug
priority: medium
Medium impact/importance bug
Describe the bug
This is known issue. The problem is we are being hit by it frequently.
The mempool alloctor when looking for a block to give takes the smallest one available and if it is too large breaks it into smaller pieces. The problem is lock is released during this operation. This can lead to memory depletion if low priority task grabs the large block but cannot finish split as a high priority task (or isr) takes CPU and wants to allocate too.
The chance of hitting it is quite high as mempool is constantly breaking and merging blocks (causing huge performance drop btw!).
Expanding the memory will not help really. This can happen regardless of the heap size as long as you have at least 5 places that can allocate and preempt each other.
Can also happen if you have 2 contexts but 3/4 of the memory is taken, 3 context but 2/4 or memory is taken , etc. (so only one large block is left for split and two context compete for it).
To Reproduce
Steps to reproduce the behavior:
Allocate from various context of mixed priorities. This is a race.
Expected behavior
Should work, no races.
Impact
Showstopper.
Screenshots or console output
N/A
Environment (please complete the following information):
ncs zephyr:
0bf5263b0522bb5cfac84eefdfdee86dc2c67e3e
(upstreamd3bb3cf
)Additional context
Call stack when OOM points to the ISR. I added a stats collector that shows 288 of 512 B heap are allocated. I suspect at least one
k_malloc
is happeing.The text was updated successfully, but these errors were encountered: