Bug 493462 - kwin with wayland excessive VRAM usage
Summary: kwin with wayland excessive VRAM usage
Status: RESOLVED WORKSFORME
Alias: None
Product: kwin
Classification: Plasma
Component: xwayland (other bugs)
Version First Reported In: 6.1.5
Platform: Neon Linux
: NOR normal
Target Milestone: ---
Assignee: KWin default assignee
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-09-22 01:59 UTC by Maxim Egorushkin
Modified: 2024-10-28 03:46 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
nvtop screenshot (189.73 KB, image/png)
2024-09-22 01:59 UTC, Maxim Egorushkin
Details
`qdbus org.kde.KWin /KWin supportInformation` output (6.79 KB, text/plain)
2024-09-23 20:26 UTC, Maxim Egorushkin
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Maxim Egorushkin 2024-09-22 01:59:54 UTC
Created attachment 173947 [details]
nvtop screenshot

I observe kwin with wayland using 5GB of VRAM while running a Plasma shell with an Emacs and 3 Konsoles. Which looks a bit too excessive for me.

My research involves training lots of relatively small PyTorch models on a single GPU in parallel. VRAM is a limiting resource for me, and getting more of it is most expensive and non-trivial. That's why I keep an eye on VRAM usage.

OBSERVED RESULT

kwin with wayland use 5GB of VRAM (21% of 24GB) just to display a Plasma shell with an Emacs and 3 Konsoles.

EXPECTED RESULT

kwin with wayland use well under 1GB VRAM for this use case.

SOFTWARE/OS VERSIONS

Operating System: KDE neon 6.0
KDE Plasma Version: 6.1.5
KDE Frameworks Version: 6.5.0
Qt Version: 6.7.2
Kernel Version: 6.8.0-45-lowlatency (64-bit)
Graphics Platform: Wayland
Processors: 32 × AMD Ryzen 9 5950X 16-Core Processor
Memory: 125.7 GiB of RAM
Graphics Processor: NVIDIA GeForce RTX 4090/PCIe/SSE2
nvidia-driver-555

ADDITIONAL INFORMATION

nvidia-smi -q output (sometime earlier than nvtop screenshot):

...
Processes
    Process ID                        : 2302
        Type                          : G
        Name                          : /usr/lib/xorg/Xorg
        Used GPU Memory               : 30 MiB
    Process ID                        : 6113
        Type                          : G
        Name                          : /usr/bin/kwin_wayland
        Used GPU Memory               : 2326 MiB
    Process ID                        : 6182
        Type                          : G
        Name                          : /usr/bin/Xwayland
        Used GPU Memory               : 2478 MiB
    Process ID                        : 6217
        Type                          : G
        Name                          : /usr/bin/ksmserver
        Used GPU Memory               : 6 MiB
    Process ID                        : 6233
        Type                          : G
        Name                          : /usr/bin/plasmashell
        Used GPU Memory               : 122 MiB
...
Comment 1 Vlad Zahorodnii 2024-09-23 08:19:23 UTC
    Process ID                        : 6182
        Type                          : G
        Name                          : /usr/bin/Xwayland
        Used GPU Memory               : 2478 MiB

what's the VRAM usage of Xwayland without open windows? also please post output of `qdbus org.kde.KWin /KWin supportInformation`
Comment 2 Kelvie Wong 2024-09-23 17:13:51 UTC
https://invent.kde.org/-/snippets/3238

I have similar GPU usage under nvidia (different kernel/driver version though), I've attached the support information as well as my kwin output (I try to avoid using Xwayland so I don't have the xwayland problem, but 2.7GB vram usage seems excessive for kwin_wayland
Comment 3 Kelvie Wong 2024-09-23 17:14:44 UTC
I meant my VRAM usage output (from nvidia-smi) and kwin support information. I have explicit sync turned on for nvidia/mesa/egl-wayland
Comment 4 Kelvie Wong 2024-09-23 17:25:00 UTC
Turning off auto-start, on a clean start of kwin_wayland, it only uses 116MB (with Plasma)

As soon as I start something like Firefox and close it, it jumps to 2.4GB.
Comment 5 Maxim Egorushkin 2024-09-23 17:40:41 UTC
(In reply to Vlad Zahorodnii from comment #1)
>     Process ID                        : 6182
>         Type                          : G
>         Name                          : /usr/bin/Xwayland
>         Used GPU Memory               : 2478 MiB
> 
> what's the VRAM usage of Xwayland without open windows? also please post
> output of `qdbus org.kde.KWin /KWin supportInformation`

I rebooted after package upgrades and these processes use under 200MB VRAM each after reboot. 
 Few hours later VRAM usage crept up 1.5×.  Will keep an eye on it.
Comment 6 Kelvie Wong 2024-09-23 19:05:54 UTC
It turns out in my case it was the 3rd party "force blur" plugin. I've also disabled "blur" to get more vram savings.
Comment 7 Maxim Egorushkin 2024-09-23 20:26:56 UTC
Created attachment 173999 [details]
`qdbus org.kde.KWin /KWin supportInformation` output

Output of `qdbus org.kde.KWin /KWin supportInformation`.
Comment 8 Maxim Egorushkin 2024-09-23 20:29:27 UTC
(In reply to Kelvie Wong from comment #6)
> It turns out in my case it was the 3rd party "force blur" plugin. I've also disabled "blur" to get more vram savings.

None of these is enabled on my system.
Comment 9 Maxim Egorushkin 2024-09-23 22:38:52 UTC
(In reply to Vlad Zahorodnii from comment #1)
>     Process ID                        : 6182
>         Type                          : G
>         Name                          : /usr/bin/Xwayland
>         Used GPU Memory               : 2478 MiB
> 
> what's the VRAM usage of Xwayland without open windows? 

 I'll report what happens when all X applications are closed later on. 

VRAM usage of kwin_wayland and Xwayland processes grows with time:

Timestamp                                 : Mon Sep 23 00:28:21 2024
    Processes
        Process ID                        : 2248
            Type                          : G
            Name                          : /usr/lib/xorg/Xorg
            Used GPU Memory               : 30 MiB
        Process ID                        : 6080
            Type                          : G
            Name                          : /usr/bin/kwin_wayland
            Used GPU Memory               : 101 MiB
        Process ID                        : 6149
            Type                          : G
            Name                          : /usr/bin/Xwayland
            Used GPU Memory               : 22 MiB

Timestamp                                 : Mon Sep 23 23:22:21 2024
    Processes
        Process ID                        : 2248
            Type                          : G
            Name                          : /usr/lib/xorg/Xorg
            Used GPU Memory               : 30 MiB
        Process ID                        : 6080
            Type                          : G
            Name                          : /usr/bin/kwin_wayland
            Used GPU Memory               : 522 MiB
        Process ID                        : 6149
            Type                          : G
            Name                          : /usr/bin/Xwayland
            Used GPU Memory               : 534 MiB

The journal contains many messages like the following. Not sure if they are related to the issue:

Sep 23 23:14:31 kwin_wayland_wrapper[886215]: warning: queue 0x5c08738700f0 destroyed while proxies still attached:
Sep 23 23:14:31 kwin_wayland_wrapper[886215]:   zwp_linux_dmabuf_v1@37 still attached
Sep 23 23:17:27 kwin_wayland_wrapper[930799]: warning: queue 0x61f6821e2e00 destroyed while proxies still attached:
Sep 23 23:17:27 kwin_wayland_wrapper[930799]:   wl_registry@34 still attached
Comment 10 Kelvie Wong 2024-09-23 23:04:30 UTC
https://old.reddit.com/r/kde/comments/1ew4wcb/huge_vram_memory_leak_when_resizing_windows/ perhaps it is this problem, I think I narrowed it down to this. Seems to be an nvidia problem, it will use up to 10% of your VRAM due to some vram leak.
Comment 11 Maxim Egorushkin 2024-09-25 01:38:19 UTC
(In reply to Kelvie Wong from comment #10)
> https://old.reddit.com/r/kde/comments/1ew4wcb/
> huge_vram_memory_leak_when_resizing_windows/ perhaps it is this problem, I
> think I narrowed it down to this. Seems to be an nvidia problem, it will use
> up to 10% of your VRAM due to some vram leak.

I haven't been able to reproduce the issue by resizing Konsole or other windows.
Comment 12 David Edmundson 2024-09-25 12:59:18 UTC
>Sep 23 23:14:31 kwin_wayland_wrapper[886215]: warning: queue 0x5c08738700f0 destroyed while proxies still attached:
Sep 23 23:14:31 kwin_wayland_wrapper[886215]:   zwp_linux_dmabuf_v1@37 still attached

These are probably from xwayland, as it mentions a client.

Can you run 'killall Xwayland' and confirm that kwin's usage goes down? If so we need to file a bug report in XWayland.
Comment 13 Maxim Egorushkin 2024-09-25 22:58:30 UTC
(In reply to Maxim Egorushkin from comment #11)
> (In reply to Kelvie Wong from comment #10)
> > https://old.reddit.com/r/kde/comments/1ew4wcb/
> > huge_vram_memory_leak_when_resizing_windows/ perhaps it is this problem, I
> > think I narrowed it down to this. Seems to be an nvidia problem, it will use
> > up to 10% of your VRAM due to some vram leak.
> 
> I haven't been able to reproduce the issue by resizing Konsole or other
> windows.

That statement of mine is incorrect. 

Resizing Konsole does increase kwin_wayland VRAM usage significantly. Resizing emacs (gtk3 X11) doesn't.
Comment 14 Maxim Egorushkin 2024-09-25 22:59:30 UTC
(In reply to David Edmundson from comment #12)
> >Sep 23 23:14:31 kwin_wayland_wrapper[886215]: warning: queue 0x5c08738700f0 destroyed while proxies still attached:
> Sep 23 23:14:31 kwin_wayland_wrapper[886215]:   zwp_linux_dmabuf_v1@37 still
> attached
> 
> These are probably from xwayland, as it mentions a client.
> 
> Can you run 'killall Xwayland' and confirm that kwin's usage goes down? If
> so we need to file a bug report in XWayland.

Killing Xwayland doesn't reduce kwin_wayland VRAM usage.
Comment 15 Maxim Egorushkin 2024-09-27 01:03:14 UTC
(In reply to Kelvie Wong from comment #10)
> https://old.reddit.com/r/kde/comments/1ew4wcb/
> huge_vram_memory_leak_when_resizing_windows/ perhaps it is this problem, I
> think I narrowed it down to this. Seems to be an nvidia problem, it will use
> up to 10% of your VRAM due to some vram leak.

Having rebooted into a fresh Plasma Wayland session, running nvtop in one Konsole window, I opened another Konsole window and tried moving and resizing it. 

The new Konsole window opened tiled to the right half of the screen (I rebooted from a Konsole tiled exactly there). Moving it around the screen didn't affect kwin_wayland VRAM usage. Resizing it, though, made kwin_wayland quickly reach 10% of VRAM usage (2.4GB on RTX 4090), and stay pegged at that level regardless of any further window shape or position changes. 

I thought, oh well, resizing Konsole does make kwin_wayland hog VRAM, as reported by Kelvie Wong above, and was about to reboot. I invoked the keyboard shortcut to tile that Konsole window back to the right half of the screen where it opened, and that made kwin_wayland release all that VRAM back to under 1% level, to my great surprise. 

It appears, that restoring Konsole window size and position back to their initial states makes kwin_wayland release that 10% VRAM it allocated during moving around and resizing that window.

Let me know what other information I could collect to narrow down the root cause of the issue.
Comment 16 Maxim Egorushkin 2024-09-28 02:03:05 UTC
There is a workaround that fixes the issue for me https://github.com/NVIDIA/egl-wayland/issues/126#issuecomment-2379945259
Comment 17 Bug Janitor Service 2024-10-13 03:47:40 UTC
🐛🧹 ⚠️ This bug has been in NEEDSINFO status with no change for at least 15 days. Please provide the requested information, then set the bug status to REPORTED. If there is no change for at least 30 days, it will be automatically closed as RESOLVED WORKSFORME.

For more information about our bug triaging procedures, please read https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging.

Thank you for helping us make KDE software even better for everyone!
Comment 18 Bug Janitor Service 2024-10-28 03:46:44 UTC
🐛🧹 This bug has been in NEEDSINFO status with no change for at least 30 days. Closing as RESOLVED WORKSFORME.