Bug 403803 - Memory leak in Kaffeine when using deinterlacing
Summary: Memory leak in Kaffeine when using deinterlacing
Status: RESOLVED NOT A BUG
Alias: None
Product: kaffeine
Classification: Applications
Component: general (show other bugs)
Version: 2.0.16-2
Platform: Gentoo Packages Linux
: NOR normal
Target Milestone: ---
Assignee: Mauro Carvalho Chehab
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-01-31 15:00 UTC by Petr Kovács
Modified: 2019-05-03 19:02 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Petr Kovács 2019-01-31 15:00:41 UTC
SUMMARY
When playing video file or DVB-T stream in Kaffeine, memory consumption grows steadily until kernel kills the process. It is happening only when you select the option "discard" in menu Playback -> Video -> Deinterlace. Other options (algorithms) aren't causing this problem.

STEPS TO REPRODUCE
1. Play video file or DVB-T stream
2. Enable "discard" option in menu Playback -> Video -> Deinterlace
3. Watch memory usage to steadily grow each second

OBSERVED RESULT
Kaffeine memory usage grows until it consumes all memory and kernel kills it.

EXPECTED RESULT
Memory usage should be similar, regardless of what deinterlacing algorithm is used.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Linux kernel 4.20.5 / KDE Plasma 5.14.5
(available in About System)
KDE Plasma Version: 
KDE Frameworks Version: 
Qt Version: 

ADDITIONAL INFORMATION
I'm using Gentoo Linux, Kaffeine 2.0.16
Comment 1 Patrick Silva 2019-02-23 17:51:23 UTC
I can reproduce with Kaffeine 2.0.16 on Arch Linux.
Comment 2 Mauro Carvalho Chehab 2019-03-09 12:30:00 UTC
Memory leak issues are hard to detect and fix, specially on GUI apps, as Qt and glib do internal allocations that are freed at their will, with not much control from the application.

I took some time to identify several cleanups at Kaffeine, in order to solve memory leaks, specially at backend-vlc.

After those, playing a mp4 video movie, with deinterlaced OFF, I'm getting those results:

       PID  PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
----- 9690  20   0 2347836 191212 129664 S   2,3   0,6   0:04.31 kaffeine
00:00 9690  20   0 2611344 206048 130168 S   4,0   0,6   0:05.18 kaffeine
01:00 9690  20   0 2611472 209280 130232 S   3,3   0,6   0:07.06 kaffeine
03:00 9690  20   0 2611472 213044 130300 S   3,0   0,6   0:11.15 kaffeine
08:00 9690  20   0 2612368 213852 130300 S   3,3   0,7   0:21.43 kaffeine
11:00 9690  20   0 2611472 213852 130300 S   3,3   0,7   0:27.60 kaffeine
15:00 9690  20   0 2611472 213852 130300 S   4,0   0,7   0:36.36 kaffeine
18:00 9690  20   0 2612092 214100 130548 S   3,7   0,7   0:42.15 kaffeine
26:00 9690  20   0 2613160 215180 131616 S   3,3   0,7   0:58.23 kaffeine                            
----- 9690  20   0 2348776 214304 130736 S   0,0   0,7   1:00.49 kaffeine                            

It is natural to have some variance on allocated memory, but the above doesn't seem absurd to me. 

While valgrind still points to some memory leaks at backend-vlc, none seem to be happening while the video is playing. They could very well be false-positives.

That's said, de-interlacing code is internal to libVlc and to accel libraries (like vaapi). Here, I'm using open source i965 driver with an Intel board. I suspect that using a closed source driver would produce a way worse result, as I've heard about bad things that would be happening with memory allocation on such drivers.

It should also be noticed that it is expected that digital TV playing would steadily increase the memory consumption as new EPG entries are added. 

I didn't try yet to address eventual memory leaks at the DVB part of Kaffeine's code, as we need first to address the leaks at the VLC backend.
Comment 3 Petr Kovács 2019-03-11 20:55:18 UTC
Mauro, I'm not sure if we understand each other. The problem occurs when you set deinterlacing method to "discard". When you disable deinterlacing or use another method than discard, everything is fine.

When discard is selected, Kaffeine's memory consumption grows by 23 MiB each time TOP refreshes (which is every 3 seconds on my computer). At this rate, you are out of memory in a few minutes (depending on your RAM size of course).

I'm using nouveau graphics driver on GeForce GTX460. I will try to install the proprietary nvidia drivers and check if that helps.
Comment 4 Mauro Carvalho Chehab 2019-03-11 21:55:24 UTC
(In reply to Petr Kovács from comment #3)
> Mauro, I'm not sure if we understand each other. The problem occurs when you
> set deinterlacing method to "discard". When you disable deinterlacing or use
> another method than discard, everything is fine.
> 
> When discard is selected, Kaffeine's memory consumption grows by 23 MiB each
> time TOP refreshes (which is every 3 seconds on my computer). At this rate,
> you are out of memory in a few minutes (depending on your RAM size of
> course).

Wow! I can't reproduce this behaviour here. Anyway, it is libvlc with handles de-interlacing. Here, I'm using version 3.0.6, with is the latest stable one while playing a *.mp4 file. No memory consumption increase on such rate (it has a small increase at the beggining, while libVlc is doing some buffering).

With DVB, memory consumption may grow with time, due to EPG data.

> 
> I'm using nouveau graphics driver on GeForce GTX460. I will try to install
> the proprietary nvidia drivers and check if that helps.

I would rely a lot more on nouveau than with nvidia proprietary driver.
Comment 5 Petr Kovács 2019-03-15 11:39:01 UTC
So i tried nvidia drivers (390.116) instead of nouveau and there is no problem with leaking memory.
Comment 6 Mauro Carvalho Chehab 2019-03-15 14:09:04 UTC
(In reply to Petr Kovács from comment #5)
> So i tried nvidia drivers (390.116) instead of nouveau and there is no
> problem with leaking memory.

Ok. I guess that the best would be if you would open a BZ at freedesktop reporting the issue with the nouveau driver.
Comment 7 Mauro Carvalho Chehab 2019-05-03 19:02:56 UTC
(In reply to Petr Kovács from comment #5)
> So i tried nvidia drivers (390.116) instead of nouveau and there is no
> problem with leaking memory.

As this sounds to be an issue with the GPU driver, I'm closing this bug.