Increasing memory usage after Qt5 upgrade
-
I have a application running on a Yocto Linux ARMv5 platform where I recently upgraded Qt from 5.4 to 5.15. After the upgrade when running the application for a few minutes memory usage starts increasing in chunks of 4-20 kB until eventually the application is killed by the oom_killer in the kernel for using too much memory. The application prior to the Qt upgrade never did this and could run forever without going past its peak memory usage.
The only changes made after the Qt upgrade was to correct code that was now deprecated or obsolete such as adding namespaces to certain stream modifiers and replacing global functions with their replacements in the new Qt version.
I've spent the week trying to find what causes the memory usage increase without luck. Since I'm running this on a ARMv5 platform most of the tools for this such as valgrind cannot be used. I've tried using heaptrack on the target but it slows down the application to the point it's unusable, taking 2 hours only to do the initialization which normally takes 10 seconds.
The application uses a number of hardware peripherals such as I2C, SPI, GPIO and UART which makes trying to run it on any other platform than the target a daunting task. The only third-party library I use is a logging library called CuteLogger. I use core, network and serialport Qt modules. It's a console application so no GUI.
At this point I've run out of ideas. The application hasn't changed other than what is required by the Qt upgrade and on 5.4 it works perfectly but on 5.15 it's leaking memory.
Has anyone done such an upgrade and encountered something like this before?
-
@Elin-Ericsson You could try to disable parts of your app until the issue disappears to at least roughly localize the issue.
-
@jsulm I've tried doing that to narrow it down, but it just seems to delay when the memory increase starts. At first I thought I had found it by turning off a timer that reads a GPIO (by using QFile on the sysfs gpio files). I pipe the value into a debouncer routine so the timer was running every 50 ms. The memory increase stopped for a while when I stopped the timer but then started later instead.
Some of the things I've been suspicious of are file accesses using QFile. There are a few places where that's used including the timer I mentioned earlier. I also use the QSettings classes for configuration and persistent status information which also does file I/O. Could fast repeated file access cause a continuous memory increase like this?
The application logs many of the things happening in the application but so far even with trace level logging (shows everything) the memory increases doesn't seem to be correlated with any one software module.
Something I've been considering is if something has changed significantly enough between Qt 5.4 and 5.15 that my use of a certain Qt-class is no the right way to do it. It is after all a pretty big leap in versions.
One observation is that it always takes some time until the memory starts increasing but once it starts it will continue until it's killed. The time until it starts will vary based on what happens in the application and how fast timers triggers.
-
So after much headscratching and troubleshooting I found out that a third-party library (CuteLogger) that the application uses caused the steady increase in memory. Apparently it had not been updated in a while and something in the latest version of Qt5 caused it to leak memory.
I've since switched over to Qt5's built-in logging facilities to log to journald and that seems to have fixed the issue.