Bug 443990

Summary: Kwin memory leak
Product: [Plasma] kwin Reporter: Komorebi <markovs.i.mail>
Component: auroraeAssignee: KWin default assignee <kwin-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: 80p3fy75dc, audvare, kde, ralf, the_archer_xz, varlesh
Priority: NOR    
Version: 5.23.4   
Target Milestone: ---   
Platform: Neon   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: Kwin memory usage
heaptrack screenshot
kwin_x11 >1.8GB
heaptrack

Description Komorebi 2021-10-18 19:16:10 UTC
SUMMARY
I've noticed kwin_x11 memory leak after updating plasma to the latest version (5.23.0)

STEPS TO REPRODUCE
1. Update to 5.23.0
2. Wait 4 days

OBSERVED RESULT
After 4 days of uptime kwin uses 560MiB of ram. It was using ~200MiB (or less) before. 

Operating System: KDE neon 5.23
KDE Plasma Version: 5.23.0
KDE Frameworks Version: 5.87.0
Qt Version: 5.15.3
Kernel Version: 5.11.0-36-generic (64-bit)
Graphics Platform: X11
Processors: 4 × Intel® Xeon® CPU E3-1225 V2 @ 3.20GHz
Memory: 23,4 GiB of RAM
Graphics Processor: Radeon RX550/550 Series
Comment 1 Komorebi 2021-10-18 19:17:18 UTC
Created attachment 142587 [details]
Kwin memory usage
Comment 2 Vlad Zahorodnii 2021-10-20 11:20:17 UTC
Interesting... It will be very helpful if you could run kwin with heaptrack, but I'm not sure that it's feasible to run kwin + heaptrack for more even than a day.
Comment 3 Vlad Zahorodnii 2021-10-20 11:21:27 UTC
Can you verify whether alt-tab'ing constantly increases memory usage?
Comment 4 Komorebi 2021-10-21 16:08:25 UTC
I can't confirm alt+tabing increases memory usage. Will try heaptrack.
Comment 5 Komorebi 2021-10-26 13:40:29 UTC
~1 day heaptrack https://drive.google.com/file/d/1fmY3vrwmtUeaAu34zql9NJmPJEWje5cX/view?usp=sharing

I'm still running kwin with heaptrack and will upload one more snapshot later.
Comment 6 Vlad Zahorodnii 2021-10-26 14:21:45 UTC
Created attachment 142910 [details]
heaptrack screenshot
Comment 8 Andrew Udvare 2021-10-27 18:27:22 UTC
Are you getting endless messages in DBus? Maybe related:

Oct 27 14:25:06 limelight dbus-daemon[2019]: [system] Rejected: destination has a full message queue, 0 matched rules; type="error", sender="(unset)" ((bus)) interface="(unset)" member="(unset)" error name="org.freedesktop.DBus.Error.ServiceUnknown" requested_reply="1" destination=":1.39" (uid=1000 pid=2627 comm="/usr/bin/kwin_x11 ")
Oct 27 14:25:06 limelight dbus-daemon[2019]: [system] Rejected: destination has a full message queue, 0 matched rules; type="error", sender="(unset)" ((bus)) interface="(unset)" member="(unset)" error name="org.freedesktop.DBus.Error.ServiceUnknown" requested_reply="1" destination=":1.39" (uid=1000 pid=2627 comm="/usr/bin/kwin_x11 ")
Oct 27 14:25:06 limelight dbus-daemon[2019]: [system] Rejected: destination has a full message queue, 0 matched rules; type="error", sender="(unset)" ((bus)) interface="(unset)" member="(unset)" error name="org.freedesktop.DBus.Error.ServiceUnknown" requested_reply="1" destination=":1.39" (uid=1000 pid=2627 comm="/usr/bin/kwin_x11 ")
Oct 27 14:25:06 limelight dbus-daemon[2019]: [system] Rejected: destination has a full message queue, 0 matched rules; type="error", sender="(unset)" ((bus)) interface="(unset)" member="(unset)" error name="org.freedesktop.DBus.Error.ServiceUnknown" requested_reply="1" destination=":1.39" (uid=1000 pid=2627 comm="/usr/bin/kwin_x11 ")
Oct 27 14:25:06 limelight dbus-daemon[2019]: [system] Rejected: destination has a full message queue, 0 matched rules; type="error", sender="(unset)" ((bus)) interface="(unset)" member="(unset)" error name="org.freedesktop.DBus.Error.ServiceUnknown" requested_reply="1" destination=":1.39" (uid=1000 pid=2627 comm="/usr/bin/kwin_x11 ")
Oct 27 14:25:06 limelight dbus-daemon[2019]: [system] Rejected: destination has a full message queue, 0 matched rules; type="error", sender="(unset)" ((bus)) interface="(unset)" member="(unset)" error name="org.freedesktop.DBus.Error.ServiceUnknown" requested_reply="1" destination=":1.39" (uid=1000 pid=2627 comm="/usr/bin/kwin_x11 ")
Oct 27 14:25:06 limelight dbus-daemon[2019]: [system] Rejected: destination has a full message queue, 0 matched rules; type="error", sender="(unset)" ((bus)) interface="(unset)" member="(unset)" error name="org.freedesktop.DBus.Error.ServiceUnknown" requested_reply="1" destination=":1.39" (uid=1000 pid=2627 comm="/usr/bin/kwin_x11 ")
Oct 27 14:25:06 limelight dbus-daemon[2019]: [system] Rejected: destination has a full message queue, 0 matched rules; type="error", sender="(unset)" ((bus)) interface="(unset)" member="(unset)" error name="org.freedesktop.DBus.Error.ServiceUnknown" requested_reply="1" destination=":1.39" (uid=1000 pid=2627 comm="/usr/bin/kwin_x11 ")
Oct 27 14:25:06 limelight dbus-daemon[2019]: [system] Rejected: destination has a full message queue, 0 matched rules; type="error", sender="(unset)" ((bus)) interface="(unset)" member="(unset)" error name="org.freedesktop.DBus.Error.ServiceUnknown" requested_reply="1" destination=":1.39" (uid=1000 pid=2627 comm="/usr/bin/kwin_x11 ")
Oct 27 14:25:06 limelight dbus-daemon[2019]: [system] Rejected: destination has a full message queue, 0 matched rules; type="error", sender="(unset)" ((bus)) interface="(unset)" member="(unset)" error name="org.freedesktop.DBus.Error.ServiceUnknown" requested_reply="1" destination=":1.39" (uid=1000 pid=2627 comm="/usr/bin/kwin_x11 ")
Comment 9 Vlad Zahorodnii 2021-10-29 13:44:08 UTC
@Komorebi is memory leaked when using breeze window deco?
Comment 10 kde 2021-10-29 14:05:05 UTC
I can confirm that, for me, spamming Alt-Tab visible increases the RAM utilization. 

The thing I noticed is that you can make kwin_x11 reach 500+ MB heap in under a minute by repeatedly opening and closing windows. After each open+close, it's like 2 to 5 MB higher, according to ksysguard.
Video: https://www.youtube.com/watch?v=2CBsheEeg_4
Comment 11 kde 2021-10-29 14:05:55 UTC
I can confirm that, for me, spamming Alt-Tab visible increases the RAM utilization. 

The thing I noticed is that you can make kwin_x11 reach 500+ MB heap in under a minute by repeatedly opening and closing windows. After each open+close, it's like 2 to 5 MB higher, according to ksysguard.
Video: https://www.youtube.com/watch?v=2CBsheEeg_4

(I'm not on Neon, though, but on Archlinux)
Comment 12 80p3fy75dc 2021-10-29 14:52:49 UTC
Created attachment 143005 [details]
kwin_x11 >1.8GB

Same issue on Gentoo, the RAM usage keeps growing with time. The screenshot was taken after about 2 days of uptime.
Comment 13 kde 2021-10-29 14:57:48 UTC
I'm afraid it might have to do with the official nvidia driver.

I posted about the subject on Reddit. 3 people using Mesa/AMDGPU don't have the issue, and I'm not able to replicate it either, as soon as I remove the nvidia driver package.

Video without the proprietary nvidia driver: https://youtu.be/djzVQMEfQt8

Starts at ~70 MB, goes to ~100 after opening a few windows, instantly goes back to that after opening and closing 30+ windows.

alt-tab spam also raises the value by no more than 0.3 MB (which is also de-allocated only seconds later)
Comment 14 Andrew Udvare 2021-10-29 22:03:01 UTC
Is anyone here getting dbus-daemon spam in the log?

Oct 29 17:57:50 limelight dbus-daemon[2006]: [system] Rejected: destination has a full message queue, 0 matched rules; type="error", sender="(unset)" ((bus)) interface="(unset)" member="(unset)" error name="org.freedesktop.DBus.Error.ServiceUnknown" requested_reply="1" destination=":1.38" (uid=1000 pid=2526 comm="/usr/bin/kwin_x11 ")

It's not exactly causing a leak as I saw in that video (and I also use the Nvidia driver). But obviously it's very annoying as I have to filter dbus-daemon out when I try to check my log. Restarting fixes the issue temporarily.
Comment 15 Komorebi 2021-10-30 22:16:28 UTC
>@Komorebi is memory leaked when using breeze window deco?
Yes

>I'm afraid it might have to do with the official nvidia driver.

>I posted about the subject on Reddit. 3 people using Mesa/AMDGPU don't have the issue, and I'm not able to replicate it either, as soon as I remove the nvidia driver package.

I have Radeon RX550/550 Series, so there might be 2 different issues. 

>alt-tab spam also raises the value by no more than 0.3 MB (which is also de-allocated only seconds later)
I'm not able to reproduce the issue by making some actions like alt+tabing, opening and closing windows, etc. Consumed memory grows over time by itself. The only way to reproduce the issue for me is just to wait for 2-3 days of uptime. 
I believe it's very important thing to take into account.
Comment 16 kde 2021-10-31 11:52:51 UTC
@Komorebi that sounds like 2 different issues indeed. meeeh
Comment 17 varlesh 2021-11-26 06:21:29 UTC
I confirm this too. On my system i'm have over 500MB kwin_x11 memory usage.  But with restart it's use 151MB and growing again.
On heaptrack it's call to <unresolved function> in libGLX_nvidia.so.0
Earlier i'm disable dbus spam with this instruction:
https://forums.developer.nvidia.com/t/bug-nvidia-v495-29-05-driver-spamming-dbus-enabled-applications-with-invalid-messages/192892/9?u=rangelalvarado1
But anyway i see memory leak on KWin.
Also i noticed unstable work and constant crashes...
Comment 18 varlesh 2021-11-26 06:22:20 UTC
Created attachment 143955 [details]
heaptrack
Comment 19 Vlad Zahorodnii 2021-12-13 13:58:20 UTC
should be fixed with https://invent.kde.org/plasma/kwin/-/merge_requests/1791
Comment 20 Vlad Zahorodnii 2021-12-13 15:38:07 UTC
https://invent.kde.org/plasma/kwin/-/commit/8accc777a5b3ab1e53341f1838ed636652dc1221 will be shipped with 5.23.5. It would be great if somebody could confirm that it fixes the issue. Otherwise we could wait until 5.23.5 is released and revisit this bug.
Comment 21 Komorebi 2021-12-13 23:21:45 UTC
No longer happens to me. The system is up for 6 days and kwin consumes ~280MB of ram which is probably slightly more that before 5.23, but still less than in 5.23.0
Comment 22 the_archer_xz 2021-12-24 01:23:42 UTC
When my custom themes are applied, kwin jumps up a few megabytes at a time whenever a window is opened and closed again. So kwin keeps consuming more ram until I have to kill it and start again. Is there a fix for this or something I can fix with my themes?

These are my themes:

https://www.pling.com/p/1406638

https://www.pling.com/p/1574340
Comment 23 Vlad Zahorodnii 2022-01-11 08:52:29 UTC
(In reply to dreaperxz@gmail.com from comment #22)
> When my custom themes are applied, kwin jumps up a few megabytes at a time
> whenever a window is opened and closed again. So kwin keeps consuming more
> ram until I have to kill it and start again. Is there a fix for this or
> something I can fix with my themes?

Can you confirm whether it's fixed in 5.23.5?
Comment 24 the_archer_xz 2022-01-11 14:32:12 UTC
In 5.23.5, I don't see it spiking up every 3-4 MB whenever I open a window 
anymore. So it seems like it's fixed.

On Tuesday, January 11, 2022 1:52:29 A.M. MST you wrote:
> https://bugs.kde.org/show_bug.cgi?id=443990
> 
> --- Comment #23 from Vlad Zahorodnii <vlad.zahorodnii@kde.org> ---
> (In reply to dreaperxz@gmail.com from comment #22)
> 
> > When my custom themes are applied, kwin jumps up a few megabytes at a time
> > whenever a window is opened and closed again. So kwin keeps consuming more
> > ram until I have to kill it and start again. Is there a fix for this or
> > something I can fix with my themes?
> 
> Can you confirm whether it's fixed in 5.23.5?
Comment 25 Vlad Zahorodnii 2022-01-12 13:29:47 UTC
Thanks, closing the bug report.