Bug 462438 - KWin huge memory usage after alt-tabbing for some time
Summary: KWin huge memory usage after alt-tabbing for some time
Status: RESOLVED WORKSFORME
Alias: None
Product: kwin
Classification: Plasma
Component: tabbox (other bugs)
Version First Reported In: 5.26.3
Platform: Manjaro Linux
: NOR normal
Target Milestone: ---
Assignee: KWin default assignee
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-11-30 13:21 UTC by Eduardo
Modified: 2023-01-01 21:17 UTC (History)
3 users (show)

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


Attachments
kwin alt-tab + memory ussage video (2.31 MB, video/x-matroska)
2022-11-30 13:21 UTC, Eduardo
Details
alt-tab automation script (157 bytes, application/x-shellscript)
2022-11-30 13:23 UTC, Eduardo
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Eduardo 2022-11-30 13:21:41 UTC
Created attachment 154167 [details]
kwin alt-tab + memory ussage video

SUMMARY
KWin uses a LOT of memory when doing alt-tab for some time.
This is what I have observed.

I rarely restart the system and lately had to alt-tab quite a lot, then everything started to stutter a lot. Investigation showed that all memory was used up and almost all swap space too. Before investigation, I turned off swap.

At that time checking out xrestop showed that kwin used 5GB of pixmaps (if I remember right), free -hw showed that "shared" was used for 15GB, after restarting kwin, all freed up, memory was back to normal, that is "shared" to 3.5GB and xrestop showed some 300MB pixmap usage.

Since this is built-in graphics adapter, main memory is shared between system and gpu, this is why, I think, all memory went to "shared" portion and I was not able to detect this earlier.

So, I wrote a script which did alt-tabbing for me, opened 25 kwrite windows and recorded a video which shows start of the alt-tabbing and the end of alt-tabbing.
As you'll be able to see, memory increases A LOT, 300 times alt-tab increased used pixmap memory from 300MB to 3GB and "shared" portion of used memory from 3.7GB to 8.7GB.

This is with modesetting driver, X11. Restarting kwin helps for a while.

If you need more tests, please ask. I'll attach video and script to this report.
Sorry for video quality but I can not upload larger video to bug report, anyhow, this should suffice.

STEPS TO REPRODUCE
1. work as usual
2. alt-tab for a while
3. observe how memory gets used up

OBSERVED RESULT
Huge memory usage

EXPECTED RESULT
Normal memory usage

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: 
Operating System: Manjaro Linux
KDE Plasma Version: 5.26.3
KDE Frameworks Version: 5.100.0
Qt Version: 5.15.7
Kernel Version: 6.0.7-linux-mjasnik-pds-20221106 (64-bit)
Graphics Platform: X11
Processors: 8 × Intel® Core™ i7-6700HQ CPU @ 2.60GHz
Memory: 31,2 GiB of RAM
Graphics Processor: Mesa Intel® HD Graphics 530
Manufacturer: Dell Inc.
Product Name: XPS 15 9550

ADDITIONAL INFORMATION
When using simple task switcher (without thumbnails), kwin eats memory at quite a lower pace.
It appears that it eats memory proportionally how many window thumbnails are shown on alt-tab popup.
Comment 1 Eduardo 2022-11-30 13:23:37 UTC
Created attachment 154168 [details]
alt-tab automation script
Comment 2 Eduardo 2022-12-02 09:15:43 UTC
If I can - I'd suggest changing the importance/priority a bit higher, as this will cause system to run out of memory sooner rather than later.
Comment 3 Eduardo 2022-12-29 15:45:35 UTC
It seems that this does not happen anymore, probably KDE Frameworks update fixed this.
Comment 4 Matt McHenry 2022-12-31 16:22:26 UTC
I have:

Operating System: NixOS 23.05
KDE Plasma Version: 5.26.4
KDE Frameworks Version: 5.101.0
Qt Version: 5.15.7
Kernel Version: 6.1.1 (64-bit)
Graphics Platform: X11
Processors: 16 × 12th Gen Intel® Core™ i7-1270P
Memory: 31.0 GiB of RAM
Graphics Processor: Mesa Intel® Graphics

And the "Pxm mem" column in xrestop still grows every time I alt-tab.  What versions are you on, Eduardo?
Comment 5 Eduardo 2023-01-01 21:17:43 UTC
My versions are as follows:
---------------------------
Operating System: Manjaro Linux
KDE Plasma Version: 5.26.4
KDE Frameworks Version: 5.101.0
Qt Version: 5.15.7
Kernel Version: 6.0.16-linux-mjasnik-bmq-20230101 (64-bit)
Graphics Platform: X11
Processors: 8 × Intel® Core™ i7-8650U CPU @ 1.90GHz
Memory: 31,2 GiB of RAM
Graphics Processor: Mesa Intel® UHD Graphics 620
---------------------------