Bug 475894 - screen recording using spectacle uses all memory ram and freezes system
Summary: screen recording using spectacle uses all memory ram and freezes system
Status: RESOLVED FIXED
Alias: None
Product: Spectacle
Classification: Applications
Component: General (show other bugs)
Version: 23.08.1
Platform: openSUSE Linux
: NOR crash
Target Milestone: ---
Assignee: Noah Davis
URL:
Keywords:
: 477924 (view as bug list)
Depends on:
Blocks:
 
Reported: 2023-10-20 21:34 UTC by sombriks
Modified: 2024-04-25 20:46 UTC (History)
5 users (show)

See Also:
Latest Commit:
Version Fixed In: 6.0


Attachments
print of the system activity showing spectacle eating all ram (230.88 KB, image/png)
2023-11-05 23:41 UTC, Vinícius
Details
journalctl logs of spectacle (78.51 KB, text/plain)
2023-11-06 00:00 UTC, Vinícius
Details
missing recording tab (417.00 KB, image/png)
2023-12-07 00:27 UTC, sombriks
Details

Note You need to log in before you can comment on or make changes to this bug.
Description sombriks 2023-10-20 21:34:11 UTC
SUMMARY

every time i try to record my screen with spectacle it starts to use all ram and freezes my machine

STEPS TO REPRODUCE

1. press print screen 
2. select recording tab 
3. start recording. it will use all remaining ram in about 30 seconds (16GB ram at already 40 or 50% usage)

OBSERVED RESULT

system freeze, hard reset to come back to life

EXPECTED RESULT

i expected to record at least a few minutes of my screen before it dies

SOFTWARE/OS VERSIONS

Linux/KDE Plasma: 6.5.6-1-default (64-bit) openSUSE Tumbleweed / KDE Plasma on Wayland 
KDE Plasma Version: 5.27.8
KDE Frameworks Version: 5.110.0
Qt Version: 5.15.11

ADDITIONAL INFORMATION
Comment 1 Vinícius 2023-11-05 23:41:52 UTC
Created attachment 162887 [details]
print of the system activity showing spectacle eating all ram

I have the same bug, but on Fedora Kinoite, the print was just from 5 seconds of starting spectacle, and it keep growing rapidly 

Operating System: Fedora Linux 39
KDE Plasma Version: 5.27.8
KDE Frameworks Version: 5.110.0
Qt Version: 5.15.10
Kernel Version: 6.5.6-300.fc39.x86_64 (64-bit)
Graphics Platform: Wayland
Processors: 16 × AMD Ryzen 7 5700U with Radeon Graphics
Memory: 6,6 GiB of RAM
Graphics Processor: AMD Radeon Graphics
Manufacturer: LENOVO
Product Name: 82MF
System Version: IdeaPad 3 15ALC6
Comment 2 Vinícius 2023-11-06 00:00:43 UTC
Created attachment 162888 [details]
journalctl logs of spectacle
Comment 3 johnathan 2023-11-14 11:33:54 UTC
spectacle looks 3.7GB in the video but the display was not responding properly so i suspect it must've been much higher.

https://imgur.com/elt3YU0

Operating System: KDE neon 5.27
KDE Plasma Version: 5.27.9
KDE Frameworks Version: 5.111.0
Qt Version: 5.15.11
Kernel Version: 6.2.0-36-generic (64-bit)
Graphics Platform: Wayland
Processors: 4 × AMD Ryzen 3 3200U with Radeon Vega Mobile Gfx
Memory: 5.7 GiB of RAM
Graphics Processor: AMD Radeon Vega 3 Graphics
Manufacturer: LENOVO
Product Name: 81UT
System Version: Lenovo IdeaPad S145-15API
Comment 4 Noah Davis 2023-12-03 11:58:09 UTC
*** Bug 477924 has been marked as a duplicate of this bug. ***
Comment 5 Noah Davis 2023-12-03 12:28:55 UTC
Just letting people know, I'm currently unable to reproduce this bug. My assumption right now is that it's similar to the problem I get when using the wrong encoder settings with a stream, which is that the RAM usage grows rapidly until OOMing if it can't process the incoming frames quickly enough.

I think that this issue should be more commonly encountered on systems with weak CPUs, but that doesn't explain why Viniciusdaros's PC had the problem. I have an AMD Ryzen 7 4800H with Radeon Graphics and 30.8 GiB of RAM. Viniciusdaros has much lower RAM than me, but their CPU is not vastly different in performance (https://www.notebookcheck.net/R7-5700U-vs-R7-4800H_12978_11677.247596.0.html). Based on my observations under normal circumstances, Spectacle's RAM usage should be 200-300 while GPU encoding and 2x that while CPU encoding (depends on the encoder). Under normal circumstances, 6.6 GiB of RAM should be enough to record with Spectacle without OOMing unless the system is already close to running out of RAM.
Comment 6 sombriks 2023-12-06 14:32:20 UTC
(In reply to Noah Davis from comment #5)
> Just letting people know, I'm currently unable to reproduce this bug. My
> assumption right now is that it's similar to the problem I get when using
> the wrong encoder settings with a stream, which is that the RAM usage grows
> rapidly until OOMing if it can't process the incoming frames quickly enough.
> 
> I think that this issue should be more commonly encountered on systems with
> weak CPUs, but that doesn't explain why Viniciusdaros's PC had the problem.
> I have an AMD Ryzen 7 4800H with Radeon Graphics and 30.8 GiB of RAM.
> Viniciusdaros has much lower RAM than me, but their CPU is not vastly
> different in performance
> (https://www.notebookcheck.net/R7-5700U-vs-R7-4800H_12978_11677.247596.0.
> html). Based on my observations under normal circumstances, Spectacle's RAM
> usage should be 200-300 while GPU encoding and 2x that while CPU encoding
> (depends on the encoder). Under normal circumstances, 6.6 GiB of RAM should
> be enough to record with Spectacle without OOMing unless the system is
> already close to running out of RAM.

I got the same issue on same hardware on openSUSE Tumbleweed KDE and Fedora 39 KDE, but i recently formatted it again, Fedora 39 with GNOME and default GNOME's recording tool does not suffer of any memory leak. it just keeps recording and recording my screen.

The system is a ThinkPad T14 Gen 2a with 16 × AMD Ryzen 7 PRO 5850U with Radeon Graphics and 48GB of RAM

I am unable to format at the moment, but let me know if virtual machines are good to try to reproduce the issue, and if there is any specific version or parameter to pass so we can get more detaile info.
Comment 7 Vinícius 2023-12-06 16:06:25 UTC
(In reply to Noah Davis from comment #5)
> Just letting people know, I'm currently unable to reproduce this bug. My
> assumption right now is that it's similar to the problem I get when using
> the wrong encoder settings with a stream, which is that the RAM usage grows
> rapidly until OOMing if it can't process the incoming frames quickly enough.
> 
> I think that this issue should be more commonly encountered on systems with
> weak CPUs, but that doesn't explain why Viniciusdaros's PC had the problem.
> I have an AMD Ryzen 7 4800H with Radeon Graphics and 30.8 GiB of RAM.
> Viniciusdaros has much lower RAM than me, but their CPU is not vastly
> different in performance
> (https://www.notebookcheck.net/R7-5700U-vs-R7-4800H_12978_11677.247596.0.
> html). Based on my observations under normal circumstances, Spectacle's RAM
> usage should be 200-300 while GPU encoding and 2x that while CPU encoding
> (depends on the encoder). Under normal circumstances, 6.6 GiB of RAM should
> be enough to record with Spectacle without OOMing unless the system is
> already close to running out of RAM.

btw, i can't reproduce it since i rebased kinoite to plasma 6
Comment 8 sombriks 2023-12-07 00:26:42 UTC
similar issue here, unable to reproduce. 
just installed kde neon testing and **no recording tab** on spectacle.

how do i rebase it to plasma 6? just wait and install a new vm?
Comment 9 sombriks 2023-12-07 00:27:23 UTC
Created attachment 163962 [details]
missing recording tab
Comment 10 Noah Davis 2023-12-07 10:06:18 UTC
(In reply to sombriks from comment #8)
> similar issue here, unable to reproduce. 
> just installed kde neon testing and **no recording tab** on spectacle.

Spectacle only does recording on Wayland. If you are on X11, this behavior is expected.

> how do i rebase it to plasma 6? just wait and install a new vm?

Not sure about KDE Neon. If in doubt, you could try Unstable Edition.
Comment 11 Arjen Hiemstra 2023-12-19 14:56:24 UTC
Git commit 66774b90e2f346d681f3d27a271ce5ad82b82bf7 by Arjen Hiemstra.
Committed on 18/12/2023 at 12:00.
Pushed by ahiemstra into branch 'master'.

encoding: Track the number of frames in flight

If the encoder cannot keep up, we can run into cases where either the
filter or encode queues are filling up with frames, causing memory usage
to increase unconstrained. Unfortunately, FFMpeg does not have any way
to set limits on its internal queues. So instead, we manually track
frames enqueued and dequeued so that we can drop frames should the
queues fill up too fast.
Related: bug 469005

M  +29   -11   src/encoder.cpp
M  +9    -2    src/encoder_p.h
M  +20   -6    src/pipewireproduce.cpp
M  +3    -0    src/pipewireproduce_p.h

https://invent.kde.org/plasma/kpipewire/-/commit/66774b90e2f346d681f3d27a271ce5ad82b82bf7
Comment 12 sombriks 2024-04-25 20:46:21 UTC
hey i just came here to say thank you! 
spectacle is recording nicely on fedora 40!