Bug 466589 - With large clipboard history, plasmashell memory usage grows rapidly and consumes all available RAM
Summary: With large clipboard history, plasmashell memory usage grows rapidly and cons...
Status: RESOLVED UPSTREAM
Alias: None
Product: plasmashell
Classification: Plasma
Component: Clipboard (show other bugs)
Version: 5.27.2
Platform: Arch Linux Linux
: VHI grave
Target Milestone: 1.0
Assignee: Plasma Bugs List
URL:
Keywords: wayland
Depends on:
Blocks:
 
Reported: 2023-02-28 09:02 UTC by Pawel
Modified: 2023-03-25 10:21 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed In: Latest release of the KDE Qt 5 patch collection, or Qt 6


Attachments
screenshot plasma memory usage (50.46 KB, image/png)
2023-02-28 09:02 UTC, Pawel
Details
history clipboard (91.56 KB, image/png)
2023-03-03 11:59 UTC, Pawel
Details
clipboard defaults (90.61 KB, image/png)
2023-03-03 12:58 UTC, Pawel
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Pawel 2023-02-28 09:02:52 UTC
Created attachment 156822 [details]
screenshot plasma memory usage

I originally posted this in Bug 430139 but Nate asked for a new bug to be created.

Since very recently (not sure when exactly though) I have observed that the plasmashell process is consuming more and more memory at a frightening pace (e.g. usage grows to 22GB in the space of 3 minutes). Killing it doesn't always help (see video below).

video of plasmashell memory usage growing to 22GB in the space of less than 3 minutes.

https://mega.nz/file/o8pBARSY#QxC_k6BYt84bSUQje7RI74QNqMwYA9UjIuf3iMSFdMg

valgrind trace:

https://mega.nz/file/J0AhFIwK#pI_pFGmN8gWZCjHAjeuo1APerJ1rWoJavFPuwq3o1eo

I also tried:
1) monitoring the process with memleax but nothing was reported despite growing memory usage;
2) downgrading to glibc 2.36 but that didn't seem to help

Operating System: Arch Linux 
KDE Plasma Version: 5.27.1
KDE Frameworks Version: 5.103.0
Qt Version: 5.15.8
Kernel Version: 6.2.1-arch1-1 (64-bit)
Graphics Platform: Wayland
Processors: 24 × AMD Ryzen 9 5900X 12-Core Processor
Memory: 31.3 GiB of RAM
Graphics Processor: AMD Radeon RX 6800 XT
Comment 1 Pawel 2023-02-28 09:13:37 UTC
see 466320 - this is the only thing that gets spammed in the log
Comment 2 Nate Graham 2023-02-28 22:32:16 UTC
Do you have multiple screens?

If so does this stop when you use `xrandr` to manually enforce a particular configuration?

And do you have anything automatically changing screen settings outside of KScreen?
Comment 3 Pawel 2023-02-28 22:35:17 UTC
Hi Nate,

I only have 1 screen and I am not aware of anything changing my screen settings.
Comment 4 Nate Graham 2023-03-01 15:19:46 UTC
Ok then it's probably not something screen-related.
Comment 5 Pawel 2023-03-01 15:22:19 UTC
probably not.

I have also tried since:

3) disabling  libcamera in wireplumber
4) replacing wireplumber with pipewire-media-session
5) completely disconnecting the external camera

steps 3-5 based on https://gitlab.freedesktop.org/pipewire … issues/385
Comment 7 Pawel 2023-03-02 18:16:02 UTC
note, this does not seem to  reproduce on X11, only on wayland!
Comment 8 Arjen Hiemstra 2023-03-03 11:37:16 UTC
That trace seems to suggest there's a large memory leak in the clipboard data engine. According to heaptrack, there's about 230 MiB of QArrayData leaked and 190 MiB of QMimeData instances. Those are created in response to wayland events, probably explaining why it happens on Wayland only.

How much clipboard history have you set?
Comment 9 Pawel 2023-03-03 11:59:46 UTC
Created attachment 156954 [details]
history clipboard

(In reply to Arjen Hiemstra from comment #8)
> That trace seems to suggest there's a large memory leak in the clipboard
> data engine. According to heaptrack, there's about 230 MiB of QArrayData
> leaked and 190 MiB of QMimeData instances. Those are created in response to
> wayland events, probably explaining why it happens on Wayland only.
> 
> How much clipboard history have you set?

Hi Adrian,

50 items - see attached.
Comment 10 Pawel 2023-03-03 12:01:03 UTC
sorry, Arjen, not Adrian!
Comment 11 Pawel 2023-03-03 12:58:26 UTC
Created attachment 156955 [details]
clipboard defaults

Resetting clipboard settings to defaults resolves the issue and makes the memory leak go away.

So one (or more) of the non-default options is causing the issue.
Comment 12 David Redondo 2023-03-03 15:03:38 UTC
I think this a leak in QWaylandClipboard, surfaced since KSystemClipboard syncs to QClipboard, there was a qt6 commit to fix it. I opened a MR to backport it https://invent.kde.org/qt/qt/qtwayland/-/merge_requests/68
Comment 13 Pawel 2023-03-06 15:21:16 UTC
I have been running the Wayland session with https://invent.kde.org/qt/qt/qtwayland/-/merge_requests/68 applied and I can no longer reproduce this bug using the original clipboard settings. Plasma memory usage is sitting at ~325 MiB.
Comment 14 Nate Graham 2023-03-06 16:34:02 UTC
Yay! And it looks like that backport was merged; closing!