Bug 469094

Summary: NVIDIA GPU memory leak
Product: [Plasma] plasmashell Reporter: forestofrain
Component: generic-performanceAssignee: Plasma Bugs List <plasma-bugs-null>
Status: RESOLVED UPSTREAM    
Severity: major CC: aleixpol, arisu+kdebugs, nate, niccolo.venerandi, notmart, rickard, traceydick, voidpointertonull+bugskdeorg
Priority: NOR    
Version First Reported In: 5.27.4   
Target Milestone: 1.0   
Platform: Gentoo Packages   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description forestofrain 2023-04-28 09:41:13 UTC
SUMMARY
I have to logout/reboot my system often, due to GPU memory leaking? I notice it mostly after locking my screen and coming back after several hours. It has been happening for many months, can't even remember which version it started, only hoping that the next release fixes the issue.  

Similar issue can be seen using System Settings and selecting another scaling factor and then revert. Do this several times and all GPU memory will be consumed.

Possible relation to bug 428394.

My setup is three 4k monitors. One larger in the middle, with the other two in portrait mode on each side.  After a fresh boot, the GPU memory will be anywhere from 2GB to 4.2GB. The range is all dependent upon KDE updates, not each reboot on the same version.

Using nvidia-smi or nvtop, the process GPU usage does not add up to total consumed.

Monitor setup
1. Left, 3840x2160 @ 200%, portrait, 27"
2. Center, primary, 3840x2160 @ 125%, 43"
3. Right, 3840x2160 @ 200%, portrait, 27"

STEPS TO REPRODUCE
1. Lock screen
2. Come back in a few hours or next morning

Alternative Steps
1. System settings, display and monitor
2. Change a screen scale, I selected the middle. Go from 125% to 100%
3. Revert
4. GPU memory usage climbed
5. Repeat scale and revert a few times
6. Be careful to not max out GPU memory

OBSERVED RESULT
GPU Memory almost doubled in the standard scenario. 
The alternative steps, it will keep climbing on each scale/revert cycle.

EXPECTED RESULT
GPU memory usage would be nearly the same as before. Ideally, not use so much to begin with.

SOFTWARE/OS VERSIONS
Operating System: Gentoo Linux 2.13
KDE Plasma Version: 5.27.4
KDE Frameworks Version: 5.105.0
Qt Version: 5.15.9
Kernel Version: 6.2.13-gentoo-dist (64-bit)
Graphics Platform: Wayland
Graphics Processor: NVIDIA GeForce RTX 3080/PCIe/SSE2

ADDITIONAL INFORMATION

Using the same monitor setup with a "trash can" mac, scales just as nice and uses way less GPU memory, somewhere around 1GB.
Windows on the same computer, not as nice scaling between monitors, uses around 1.4GB GPU memory.

It would be a dream to see KDE on wayland under 2GB GPU. :)

After 3 change scale/revert cycles nvidia-smi output

Before
|=========================================+======================+======================|
|   0  NVIDIA GeForce RTX 3080         Off| 00000000:01:00.0  On |                  N/A |
| 30%   41C    P0               84W / 320W|   3716MiB / 10240MiB |      1%      Default |
|                                         |                      |                  N/A |
+-----------------------------------------+----------------------+----------------------+
                                                                                         
+---------------------------------------------------------------------------------------+
| Processes:                                                                            |
|  GPU   GI   CI        PID   Type   Process name                            GPU Memory |
|        ID   ID                                                             Usage      |
|=======================================================================================|
|    0   N/A  N/A      1217      G   /usr/bin/kwin_wayland                      1475MiB |
|    0   N/A  N/A      1583      G   /usr/bin/Xwayland                            29MiB |
|    0   N/A  N/A      1591      G   /usr/bin/ksmserver                            3MiB |
|    0   N/A  N/A      1603      G   /usr/bin/kded5                                3MiB |
|    0   N/A  N/A      1678      G   /usr/bin/plasmashell                        753MiB |
|    0   N/A  N/A      1730      G   ...c/polkit-kde-authentication-agent-1        3MiB |
|    0   N/A  N/A      1732      G   ...ib64/libexec/xdg-desktop-portal-kde        3MiB |
|    0   N/A  N/A      1867      G   /usr/lib64/libexec/kdeconnectd                3MiB |
|    0   N/A  N/A      1869      G   /usr/bin/some_qt_app                            3MiB |
|    0   N/A  N/A      1878      G   /usr/bin/kaccess                              3MiB |
|    0   N/A  N/A      1880      G   /usr/bin/kalendarac                           3MiB |
|    0   N/A  N/A      2360      G   /usr/lib64/libexec/baloorunner                3MiB |
|    0   N/A  N/A     81264      G   /usr/bin/krunner                             27MiB |
|    0   N/A  N/A    148708      G   /usr/bin/konsole                              3MiB |
|    0   N/A  N/A    148925      G   ...ble-features=WebRTCPipeWireCapturer        4MiB |
|    0   N/A  N/A    151890      G   /usr/bin/kate                                 3MiB |
+---------------------------------------------------------------------------------------+

|=========================================+======================+======================|
|   0  NVIDIA GeForce RTX 3080         Off| 00000000:01:00.0  On |                  N/A |
| 30%   41C    P0               84W / 320W|   6647MiB / 10240MiB |      0%      Default |
|                                         |                      |                  N/A |
+-----------------------------------------+----------------------+----------------------+
  
After                                                                                       
+---------------------------------------------------------------------------------------+
| Processes:                                                                            |
|  GPU   GI   CI        PID   Type   Process name                            GPU Memory |
|        ID   ID                                                             Usage      |
|=======================================================================================|
|    0   N/A  N/A      1217      G   /usr/bin/kwin_wayland                      1473MiB |
|    0   N/A  N/A      1583      G   /usr/bin/Xwayland                            29MiB |
|    0   N/A  N/A      1591      G   /usr/bin/ksmserver                            3MiB |
|    0   N/A  N/A      1603      G   /usr/bin/kded5                                3MiB |
|    0   N/A  N/A      1678      G   /usr/bin/plasmashell                       3435MiB |
|    0   N/A  N/A      1730      G   ...c/polkit-kde-authentication-agent-1        3MiB |
|    0   N/A  N/A      1732      G   ...ib64/libexec/xdg-desktop-portal-kde        3MiB |
|    0   N/A  N/A      1867      G   /usr/lib64/libexec/kdeconnectd                3MiB |
|    0   N/A  N/A      1869      G   /usr/bin/some_qt_app                            3MiB |
|    0   N/A  N/A      1878      G   /usr/bin/kaccess                              3MiB |
|    0   N/A  N/A      1880      G   /usr/bin/kalendarac                           3MiB |
|    0   N/A  N/A      2360      G   /usr/lib64/libexec/baloorunner                3MiB |
|    0   N/A  N/A     81264      G   /usr/bin/krunner                             27MiB |
|    0   N/A  N/A    148708      G   /usr/bin/konsole                              3MiB |
|    0   N/A  N/A    148925      G   ...ble-features=WebRTCPipeWireCapturer        4MiB |
|    0   N/A  N/A    151890      G   /usr/bin/kate                                 3MiB |
|    0   N/A  N/A    153731      G   /usr/bin/systemsettings                     250MiB |
+---------------------------------------------------------------------------------------+
Comment 1 forestofrain 2023-04-29 16:10:06 UTC
Here is a case showing the difference with the default wallpaper image and plain color applying the same change the scale and revert quick test. I removed all the small 3Mib processes and only left the relevant ones below. Hope that helps to narrow the issue. Feels like the wallpaper image or plain color gpu memory is not released.

Default wallpaper image


nvidia-smi                                                                                                                       13:12:24
Sat Apr 29 13:12:35 2023
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 530.41.03              Driver Version: 530.41.03    CUDA Version: 12.1     |
|-----------------------------------------+----------------------+----------------------+
| GPU  Name                  Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf            Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                                         |                      |               MIG M. |
|=========================================+======================+======================|
|   0  NVIDIA GeForce RTX 3080         Off| 00000000:01:00.0  On |                  N/A |
| 30%   41C    P0               83W / 320W|   3071MiB / 10240MiB |      0%      Default |
|                                         |                      |                  N/A |
+-----------------------------------------+----------------------+----------------------+

+---------------------------------------------------------------------------------------+
| Processes:                                                                            |
|  GPU   GI   CI        PID   Type   Process name                            GPU Memory |
|        ID   ID                                                             Usage      |
|=======================================================================================|
|    0   N/A  N/A      1244      G   /usr/bin/kwin_wayland                      1130MiB |
|    0   N/A  N/A      1630      G   /usr/bin/Xwayland                            20MiB |
|    0   N/A  N/A      1721      G   /usr/bin/plasmashell                        878MiB |
+---------------------------------------------------------------------------------------+

❯ nvidia-smi                                                                                                                                     13:13:07
Sat Apr 29 13:13:33 2023
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 530.41.03              Driver Version: 530.41.03    CUDA Version: 12.1     |
|-----------------------------------------+----------------------+----------------------+
| GPU  Name                  Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf            Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                                         |                      |               MIG M. |
|=========================================+======================+======================|
|   0  NVIDIA GeForce RTX 3080         Off| 00000000:01:00.0  On |                  N/A |
| 30%   41C    P0               84W / 320W|   7924MiB / 10240MiB |      0%      Default |
|                                         |                      |                  N/A |
+-----------------------------------------+----------------------+----------------------+

+---------------------------------------------------------------------------------------+
| Processes:                                                                            |
|  GPU   GI   CI        PID   Type   Process name                            GPU Memory |
|        ID   ID                                                             Usage      |
|=======================================================================================|
|    0   N/A  N/A      1244      G   /usr/bin/kwin_wayland                      1126MiB |
|    0   N/A  N/A      1630      G   /usr/bin/Xwayland                            20MiB |
|    0   N/A  N/A      1721      G   /usr/bin/plasmashell                       5378MiB |
+---------------------------------------------------------------------------------------+


Plain color wallpaper

The plain color shifts after revert leaving black screen instead of the selected color.

❯ nvidia-smi                                                                                                                       13:16:21
Sat Apr 29 13:16:23 2023
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 530.41.03              Driver Version: 530.41.03    CUDA Version: 12.1     |
|-----------------------------------------+----------------------+----------------------+
| GPU  Name                  Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf            Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                                         |                      |               MIG M. |
|=========================================+======================+======================|
|   0  NVIDIA GeForce RTX 3080         Off| 00000000:01:00.0  On |                  N/A |
| 30%   41C    P0              114W / 320W|   1365MiB / 10240MiB |      0%      Default |
|                                         |                      |                  N/A |
+-----------------------------------------+----------------------+----------------------+

+---------------------------------------------------------------------------------------+
| Processes:                                                                            |
|  GPU   GI   CI        PID   Type   Process name                            GPU Memory |
|        ID   ID                                                             Usage      |
|=======================================================================================|
|    0   N/A  N/A      1208      G   /usr/bin/kwin_wayland                       577MiB |
|    0   N/A  N/A      1246      G   /usr/bin/Xwayland                             4MiB |
|    0   N/A  N/A      1662      G   /usr/bin/plasmashell                        749MiB |
+---------------------------------------------------------------------------------------+

❯ nvidia-smi                                                                                                                        13:17:15
Sat Apr 29 13:17:24 2023
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 530.41.03              Driver Version: 530.41.03    CUDA Version: 12.1     |
|-----------------------------------------+----------------------+----------------------+
| GPU  Name                  Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf            Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                                         |                      |               MIG M. |
|=========================================+======================+======================|
|   0  NVIDIA GeForce RTX 3080         Off| 00000000:01:00.0  On |                  N/A |
| 30%   41C    P0               83W / 320W|   1826MiB / 10240MiB |      0%      Default |
|                                         |                      |                  N/A |
+-----------------------------------------+----------------------+----------------------+

+---------------------------------------------------------------------------------------+
| Processes:                                                                            |
|  GPU   GI   CI        PID   Type   Process name                            GPU Memory |
|        ID   ID                                                             Usage      |
|=======================================================================================|
|    0   N/A  N/A      1208      G   /usr/bin/kwin_wayland                       607MiB |
|    0   N/A  N/A      1246      G   /usr/bin/Xwayland                             4MiB |
|    0   N/A  N/A      1662      G   /usr/bin/plasmashell                        749MiB |
+---------------------------------------------------------------------------------------+

Enabling the default wallpaper image

❯ nvidia-smi                                                                                                                        13:17:24
Sat Apr 29 13:19:39 2023
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 530.41.03              Driver Version: 530.41.03    CUDA Version: 12.1     |
|-----------------------------------------+----------------------+----------------------+
| GPU  Name                  Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf            Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                                         |                      |               MIG M. |
|=========================================+======================+======================|
|   0  NVIDIA GeForce RTX 3080         Off| 00000000:01:00.0  On |                  N/A |
| 30%   41C    P0               83W / 320W|   2358MiB / 10240MiB |      0%      Default |
|                                         |                      |                  N/A |
+-----------------------------------------+----------------------+----------------------+

+---------------------------------------------------------------------------------------+
| Processes:                                                                            |
|  GPU   GI   CI        PID   Type   Process name                            GPU Memory |
|        ID   ID                                                             Usage      |
|=======================================================================================|
|    0   N/A  N/A      1208      G   /usr/bin/kwin_wayland                       628MiB |
|    0   N/A  N/A      1246      G   /usr/bin/Xwayland                             4MiB |
|    0   N/A  N/A      1662      G   /usr/bin/plasmashell                       1339MiB |
+---------------------------------------------------------------------------------------+

❯ nvidia-smi                                                                                                                        13:19:39
Sat Apr 29 13:20:25 2023
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 530.41.03              Driver Version: 530.41.03    CUDA Version: 12.1     |
|-----------------------------------------+----------------------+----------------------+
| GPU  Name                  Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf            Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                                         |                      |               MIG M. |
|=========================================+======================+======================|
|   0  NVIDIA GeForce RTX 3080         Off| 00000000:01:00.0  On |                  N/A |
| 30%   41C    P0               84W / 320W|   7790MiB / 10240MiB |      0%      Default |
|                                         |                      |                  N/A |
+-----------------------------------------+----------------------+----------------------+

+---------------------------------------------------------------------------------------+
| Processes:                                                                            |
|  GPU   GI   CI        PID   Type   Process name                            GPU Memory |
|        ID   ID                                                             Usage      |
|=======================================================================================|
|    0   N/A  N/A      1208      G   /usr/bin/kwin_wayland                       628MiB |
|    0   N/A  N/A      1246      G   /usr/bin/Xwayland                             4MiB |
|    0   N/A  N/A      1662      G   /usr/bin/plasmashell                       6771MiB |
+---------------------------------------------------------------------------------------+
Comment 2 Pedro V 2024-01-01 12:48:15 UTC
Wondering if this issue is Nvidia related. There are still good reasons why they are being mocked as Novideo, and it generally doesn't seem like they care too much about Linux desktop. That's exactly why I went with an AMD GPU this time, leaving Nvidia struggles behind, improving my experience significantly.

Currently I'm at 16 days uptime with plasmashell GPU memory usage being less than 1 GiB with what looks like a wasteland of abandoned windows I really need to reap and/or catch up with. Not seeing kwin in nvtop, but with most memory usage being associated with Firefox, Thunderbird, and other known GPU hogs, I don't feel like KDE is bloated for me.

Did the monitor scale dance, total GPU memory consumption was almost 5.4 GiB, 100%->125%->100% dropped it down to almost 5.1 GiB, and then closing the settings window got it below 5 GiB. So quite amusingly your memory leak reproducer actually freed up memory for me.
I'm not sure if I ever ran out of GPU memory, but I definitely don't measure the frequency of my issues on the scale of hours, instead when I get too abusive with littering windows, plasmashell crashes maybe roughly weekly, but with a light load it's way less common, so I'm quite happy with KDE lately.

Operating System: Kubuntu 23.10
KDE Plasma Version: 5.27.8
KDE Frameworks Version: 5.110.0
Qt Version: 5.15.10
Kernel Version: 6.5.0-14-generic (64-bit)
Graphics Platform: Wayland
Graphics Processor: AMD Radeon RX 6800 XT
Comment 3 rickard 2024-06-02 07:21:36 UTC
I've seen this too, seems like plasmashell leaks GPU memory, at least under wayland.
Operating System: CachyOS Linux 
KDE Plasma Version: 6.0.5
KDE Frameworks Version: 6.2.0
Qt Version: 6.7.1
Kernel Version: 6.9.2-1-cachyos-lto (64-bit)
Graphics Platform: Wayland
Graphics Processor: NVIDIA GeForce RTX 4070/PCIe/SSE2
Driver: Nvidia 555.42.02

GPU memory usage:
/usr/bin/plasmashell  356MiB

It was roughly 260MiB 30 minutes ago, then it suddenly went up +100MB.
Comment 4 Nate Graham 2025-05-09 17:46:42 UTC
Thank you for the bug report! I'm sorry we weren't able to get to it yet.

If this is still happening for you with a more recent Plasma version, like 6.3.5 or later, can you tell me whether you have any GIF or other kind of animated wallpapers?

It would also be good to know if it goes away if you use a boring plain color wallpaper on all of your screens.
Comment 5 rickard 2025-05-15 19:08:30 UTC
Hi Nate!

TLDR;
It's an Nvidia driver issue.

This was partly fixed by Nvidia in their driver, it's not as severe as it used.
For reference, here's the (very long) issue thread. And to summarize, it basically affects all apps running on wayland (and Xwayland).
https://github.com/NVIDIA/egl-wayland/issues/126

I have an AMD GPU now and I don't really see it go up the same way it did with the Nvidia GPU, even if I try to "force it".
Comment 6 Nate Graham 2025-05-16 14:27:44 UTC
It often is. Thanks for reporting back about it!