I'm working on a project using an embedded Linux kernel and I encounter a problem of thread latency when accessing a flash memory.
My application is multithreaded and some threads have to complete a given task in less than 500 ms. The problem is that these threads are sometimes "frozen" during more than 1 second and my 500 ms execution time is exceded.
This behaviour seems to be linked to flash writes since it occurs also when I execute a "dd" command from shell to write continuously in the flash memory.
I tried various configurations :
By using the ftrace tool I could see that, during the "freeze" time, some threads and processes are still running, with a lot of "idle" task time between the others tasks (idle task timeslot duration is > 20ms):
I don't understand:
I suspect something linked with the IO management in the kernel, as if the kernel preempted every non IO thread in order to do all the works relating to IO (network, files, ...).
Does anybody have an idea of what might cause this latency ?
My kernel settings:
Edit:
As I'm not an expert, I share with you ftrace capture (to be viewed with kernelshark): https://drive.google.com/file/d/0B6pJb20-D0D2NHZBUHJVRlV0aDg/view?usp=sharing
Maybe it could help you to see what is really happening on my system.
In this capture I reproduced, with an external "dd" command, a similar behavior I encountered with my application in nominal condition.
The "hole" ("freeze") is (no more custom ftrace marker from my application) at timestamps:
Another little "hole"
I think this can be because the kernel has decided it must flush some filesystem metadata, or do other filesystem housekeeping, and must stall your process until it has done enough.
I had similar problems and used multi-threading and a userland buffer to absorb the stalls. See my old question and answer here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With