Bug 479846 - Thumbnail Grid, Wayland (NVIDIA?): video memory leak each time Task Switcher is shown, leading to OOM crash
Summary: Thumbnail Grid, Wayland (NVIDIA?): video memory leak each time Task Switcher ...
Status: RESOLVED FIXED
Alias: None
Product: kwin
Classification: Plasma
Component: effects-window-management (other bugs)
Version First Reported In: 5.92.0
Platform: Arch Linux Linux
: NOR crash
Target Milestone: ---
Assignee: KWin default assignee
URL:
Keywords: qt6
Depends on:
Blocks:
 
Reported: 2024-01-15 14:17 UTC by mooodyhunter@outlook.com
Modified: 2024-01-16 13:49 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed/Implemented In: 6.0
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description mooodyhunter@outlook.com 2024-01-15 14:17:07 UTC
SUMMARY

When "Thumbnail Grid" is configured to be the task switcher, each time Alt+Tab is pressed (and the switcher is shown), a chunk of video RAM is allocated, and doesn't seem to be released anymore, even if after the switcher is hidden.

Other task switchers doesn't seem to have the issue.

STEPS TO REPRODUCE
1. In Settings > Window Management > Task Switcher, set Thumbnail Grid as Visualization (other options doesn't seem to affect)
3. Open some windows (the more, the quicker it runs out of vram)
4. With `nvidia-smi`, run the following command to see how much VRAM kwin_wayland has used:

watch -n1 'nvidia-smi -q -d PIDS | grep -A1 kwin_wayland'

5. Alt+Tab to switch the windows, and observe the memory usage

OBSERVED RESULT

The VRAM usage goes up and down, but does not continuously increase

EXPECTED RESULT

The VRAM usage continuously increases, nearly 100M per one "switch"

SOFTWARE/OS VERSIONS
Operating System: Arch Linux 
KDE Plasma Version: 5.92.0
KDE Frameworks Version: 5.248.0
Qt Version: 6.7.0
Kernel Version: 6.7.0-arch3-1 (64-bit)
Graphics Platform: Wayland
Processors: 32 × 13th Gen Intel® Core™ i9-13900HX
Memory: 62.6 GiB of RAM
Graphics Processor: NVIDIA GeForce RTX 4050 Laptop GPU/PCIe/SSE2
Manufacturer: LENOVO
Product Name: 82WK
System Version: Legion Y9000P IRX8

ADDITIONAL INFORMATION

I cannot do screen recording probably due to some other bug(s) (the portal doesn't get shown)

The backtrace when crashing (which is not useful as it's a nullptr deref) 

Stack trace of thread 54639:
#0  0x000070471f8b5984 _ZNK4KWin16EglSwapchainSlot6bufferEv (libkwin.so.6 + 0x2b5984)
#1  0x000070471fa744a2 n/a (libkwin.so.6 + 0x4744a2)
#2  0x000070471f7c9d3f _ZN4KWin10Compositor9compositeEPNS_10RenderLoopE (libkwin.so.6 + 0x1c9d3f)
#3  0x000070471cdbeaa9 n/a (libQt6Core.so.6 + 0x1beaa9)
#4  0x000070471f7e17f7 _ZN4KWin10RenderLoop14frameRequestedEPS0_ (libkwin.so.6 + 0x1e17f7)
#5  0x000070471f7e75f8 _ZN4KWin17RenderLoopPrivate8dispatchEv (libkwin.so.6 + 0x1e75f8)
#6  0x000070471cdbeaa9 n/a (libQt6Core.so.6 + 0x1beaa9)
#7  0x000070471cdc4244 _ZN6QTimer10timerEventEP11QTimerEvent (libQt6Core.so.6 + 0x1c4244)
#8  0x000070471cdafc16 _ZN7QObject5eventEP6QEvent (libQt6Core.so.6 + 0x1afc16)
#9  0x000070471df7bf5b _ZN19QApplicationPrivate13notify_helperEP7QObjectP6QEvent (libQt6Widgets.so.6 + 0x17bf5b)
#10 0x000070471cd65488 _ZN16QCoreApplication15notifyInternal2EP7QObjectP6QEvent (libQt6Core.so.6 + 0x165488)
#11 0x000070471ced26cd _ZN14QTimerInfoList14activateTimersEv (libQt6Core.so.6 + 0x2d26cd)
#12 0x000070471ced91d1 _ZN20QEventDispatcherUNIX13processEventsE6QFlagsIN10QEventLoop17ProcessEventsFlagEE (libQt6Core.so.6 + 0x2d91d1)
#13 0x000070471d9f2ce2 _ZN23QUnixEventDispatcherQPA13processEventsE6QFlagsIN10QEventLoop17ProcessEventsFlagEE (libQt6Gui.so.6 + 0x5f2ce2)
#14 0x000070471cd6d67e _ZN10QEventLoop4execE6QFlagsINS_17ProcessEventsFlagEE (libQt6Core.so.6 + 0x16d67e)
#15 0x000070471cd690b8 _ZN16QCoreApplication4execEv (libQt6Core.so.6 + 0x1690b8)
#16 0x00005ae76a355e7e n/a (kwin_wayland + 0x4ce7e)
#17 0x000070471c645cd0 n/a (libc.so.6 + 0x27cd0)
#18 0x000070471c645d8a __libc_start_main (libc.so.6 + 0x27d8a)
#19 0x00005ae76a35be85 n/a (kwin_wayland + 0x52e85)
Comment 1 Bug Janitor Service 2024-01-16 12:43:52 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/kwin/-/merge_requests/4942
Comment 2 David Redondo 2024-01-16 13:08:28 UTC
Git commit 203c4998bca5a949f05c495040ecce5e4a6d4eeb by David Redondo.
Committed on 16/01/2024 at 13:45.
Pushed by davidre into branch 'master'.

Make sure window thumbnails and Qt Quick resources  are destroyed properly

Drops the doneCurrent as it was preventing proper cleanUp
because no context was current when textures were deleted.
Also avoid manipulating the context when Qt has the current
one, as various Qt classes have guards around their cleanup
handlers which rely on a current Qt context.
Despite the comment the order of render control and view destruction
needs to be switched as the QQuickWindow destructor calls into
the render control to notify if of window destruction.
Related: bug 478770
FIXED-IN:6.0

M  +1    -2    src/effect/offscreenquickview.cpp
M  +10   -10   src/scripting/windowthumbnailitem.cpp

https://invent.kde.org/plasma/kwin/-/commit/203c4998bca5a949f05c495040ecce5e4a6d4eeb
Comment 3 Vlad Zahorodnii 2024-01-16 13:49:42 UTC
Git commit 228ef989b4264b9cbac029c00d399dfb9f4bd0c2 by Vlad Zahorodnii, on behalf of David Redondo.
Committed on 16/01/2024 at 14:34.
Pushed by vladz into branch 'Plasma/6.0'.

Make sure window thumbnails and Qt Quick resources  are destroyed properly

Drops the doneCurrent as it was preventing proper cleanUp
because no context was current when textures were deleted.
Also avoid manipulating the context when Qt has the current
one, as various Qt classes have guards around their cleanup
handlers which rely on a current Qt context.
Despite the comment the order of render control and view destruction
needs to be switched as the QQuickWindow destructor calls into
the render control to notify if of window destruction.
Related: bug 478770
FIXED-IN:6.0


(cherry picked from commit 203c4998bca5a949f05c495040ecce5e4a6d4eeb)

M  +1    -2    src/effect/offscreenquickview.cpp
M  +10   -10   src/scripting/windowthumbnailitem.cpp

https://invent.kde.org/plasma/kwin/-/commit/228ef989b4264b9cbac029c00d399dfb9f4bd0c2