! Please note that this is a snapshot of our old Bugzilla server, which is read only since May 29, 2020. Please go to gitlab.xfce.org for our new server !
Possible memory leak in xfdesktop 4.14.1 when connecting and disconnecting DP...
Status:
RESOLVED: FIXED
Product:
Xfdesktop
Component:
General

Comments

Description Hakan Bayındır 2019-12-30 06:49:17 CET
Created attachment 9338 
xfdesktop memory usage log, 15 minutes resolution, 10 days.

xfdesktop-4.14.1 is leaking memory when a DisplayPort monitor is connected and disconnected.

Configuration Details:
- Debian testing with XFCE desktop.
- nVidia GeForce GT 730 with nVidia drivers 430.64
- HP EliteDisplay e273q monitıor @ 2560x1440 via DisplayPort connection.

Another notes of interest:
- XScreensaver is installed since system was locking up with XFCE's screensaver.

What happens at a glance: Memory usage of xfdesktop process increases about ~60MB when monitor is turned off. Some memory is reclaimed over time, but it's not enough to reverse the leak.

Steps to Reproduce:
1- Boot to your desktop
2- Use your system as normal.
3- Turn off your monitor for some reason.
4 - You've leaked ~60MB of RAM.

Expected Behavior:
1- Boot to your desktop
2- Use your system as normal.
3- Turn off your monitor for some reason.
4 - Nothing happens to your RAM usage.

Supporting material:
* I've traced the memory usage of the xfdesktop process with 15 minutes resoluton for 10 days. Memory jumps always happens after I turn off my monitor for the night (around 17:20, everyday).
Comment 1 Hakan Bayındır 2019-12-30 07:03:59 CET
Created attachment 9339 
xfdesktop memory usage graph, 15 minutes resolution, 10 days.

This graph plots the RSS column in the attached log file. The slight down slope at the right side is the weekend, where the monitor is not ever turned on.

The memory leak can be seen as jumps in the graph.
Comment 2 Hakan Bayındır 2019-12-30 07:06:02 CET
This can be a possible duplicate of bug #12805 since turning off the monitor effectively disconnects it.
Comment 3 Andre Miranda editbugs 2020-01-05 20:52:49 CET
More likely a dup of Bug #14844. I can't reproduce by turning off my monitor, changing the resolution makes it leak once or twice (from 48MiB to 91MiB) then it stops leaking, which is pretty much what I reported at that bug.
Comment 4 Hakan Bayındır 2020-01-06 07:09:25 CET
Thanks for your answer. Yes, that's another possible duplicate however, I reliably leak the memory the moment I turn off my monitor.

Have you tried physically disconnecting your monitor? From my experience, not all monitors completely disconnect when they're turned off and, as far as I understand DisplayPort is different enough to create behavioral differences in underlying systems when compared to DVI & HDMI.

What can I do more to trace down the problem? I'd like to provide as much information as I can.
Comment 5 matt 2020-02-10 02:56:09 CET
I have the same problem. It is an Intel NUC connected to a TV via HDMI. It doesn't just leak when the TV is off, but also when the TV is connected to a different input. Similarly, when it starts up, HDMI audio works fine, but after switching the TV to a different input and then back again, audio stops working. KDE has the same problem.
Comment 6 Theo Linkspfeifer editbugs 2020-02-16 12:51:55 CET
Valgrind could be used to further debug the issue:

https://bugzilla.xfce.org/show_bug.cgi?id=12805#c2
Comment 7 Jan Ziak (http://atom-symbol.net) 2020-03-15 12:49:14 CET
Created attachment 9602 
Valgrind - Invalid read of size 8 - xfce-backdrop.c:1714
Comment 8 Jan Ziak (http://atom-symbol.net) 2020-03-15 13:00:26 CET
Created attachment 9603 
backdrop.patch

This patch fixes the invalid memory access reported by Valgrind and fixes the memory leak (xfdesktop 4.14.2). Please review the patch and confirm whether it works for you. The resulting maximum memory consumption of 148 MB RSS on a single 4K display, after the display is turned off and then turned on, is still a bit excessive though, but this can (and should) be fixed by a different patch.
Comment 9 Jan Ziak (http://atom-symbol.net) 2020-03-15 13:10:49 CET
*** Bug 16531 has been marked as a duplicate of this bug. ***
Comment 10 Andre Miranda editbugs 2020-03-16 00:55:05 CET
Thanks Jan for the patch, like I said I'm unable to reproduce the problem, with your patch xfdesktop behaves exactly the same to me (which is good, no crashes).
If Hakan and Matt let us that this patch works for them I'll gladly merge it.
Comment 11 Hakan Bayındır 2020-03-16 07:35:14 CET
I'll compile and test the patch as soon as I can. I've prepared the VM, I'll just recompile and deploy to the affected system.
Comment 12 Jonas Kvinge 2020-04-08 20:28:40 CEST
I've been using XFCE for many years and have never seen this issue before now. But I've been working from home lately because of the corona virus. So I have a KVM switch that I use to switch from my home desktop to my work laptop, lately I've seen issues with xfdesktop growing to 2.5GB and more. I have to reboot often now to free memory.
I notice that the memory increases if I switch to my work laptop and back with around 125MB each time.

I have applied the patch now. Looks like the memory increased the first times I switch, but stopped on 99MB now. I will do some more testing for a while before I conclude.
If anyone is using openSUSE I've built xfdesktop with the patch here:
https://build.opensuse.org/package/show/home:jonaski:branches:X11:xfce/xfdesktop
Comment 13 Jan Ziak (http://atom-symbol.net) 2020-04-08 23:23:14 CEST
(In reply to Jonas Kvinge from comment #12)
> lately I've seen issues with xfdesktop growing to 2.5GB and more. I have to reboot often now to free memory.

Just a note: You do not need to reboot the machine, it should be possible to restart xfdesktop by sending SIGHUP to it, for example by pressing 'k' in htop.
Comment 14 Jonas Kvinge 2020-04-09 15:51:48 CEST
Patch looks good to me, so far no memory 100% steady when switching displays, I even saw it decreasing once now.
Comment 15 Andre Miranda editbugs 2020-04-11 04:11:09 CEST
Good news, I've got myself a new monitor and I can reproduce the leak when unplugging/plugging it.

@Jan, can you please attach a patch in git format? (it retains authorship, if you don't mind please let me know)

By the way, you said xfdesktop was using 148MB for a 4K Display, in my case (1080p+720p) it doesn't go past 80MB, we can try to investigate this later, but I suspect the increased memory consumption is due the raw image buffer in memory, a 3840x2160 32-bits bitmap file is about 30MB, maybe GdkPixmap uses even more. Once again thanks!
Comment 16 Jan Ziak (http://atom-symbol.net) 2020-04-11 15:53:27 CEST
Created attachment 9702 
0001-Fix-memory-leak-when-reconnecting-DP-monitor-Bug-16314.patch

Patch in git format.
Comment 17 Jan Ziak (http://atom-symbol.net) 2020-04-11 16:13:14 CEST
(In reply to Andre Miranda from comment #15)
> By the way, you said xfdesktop was using 148MB for a 4K Display, in my case
> (1080p+720p) it doesn't go past 80MB, we can try to investigate this later,
> but I suspect the increased memory consumption is due the raw image buffer
> in memory, a 3840x2160 32-bits bitmap file is about 30MB, maybe GdkPixmap
> uses even more. Once again thanks!

It is possible to lower the memory consumption (RSS) by calling malloc_trim(0) from "gdb --pid $(pidof xfdesktop)" to free about 30 MB of memory (on a 4K display) to get 117 MB RSS.

It might be the case that some of the trimmed 117 MB isn't returned to the operating system because of memory fragmentation. I will try to determine whether this is the case.
Comment 18 Git Bot editbugs 2020-04-11 18:16:32 CEST
Jan Ziak referenced this bugreport in commit f3f9bdb5a9162480ba1a892d37859321f37c4d51

Fix memory leak when reconnecting DP monitor (Bug #16314)

https://git.xfce.org/xfce/xfdesktop/commit?id=f3f9bdb5a9162480ba1a892d37859321f37c4d51
Comment 19 Git Bot editbugs 2020-04-11 18:17:12 CEST
Jan Ziak referenced this bugreport in commit bd6cd3ce62057370a9e7c6699e52385f479e3390

Fix memory leak when reconnecting DP monitor (Bug #16314)

https://git.xfce.org/xfce/xfdesktop/commit?id=bd6cd3ce62057370a9e7c6699e52385f479e3390
Comment 20 Andre Miranda editbugs 2020-04-11 18:28:19 CEST
Pushed to master and xfce-4.14 branches, thanks!

(In reply to Jan Ziak (http://atom-symbol.net) from comment #17)
> It is possible to lower the memory consumption (RSS) by calling
> malloc_trim(0) from "gdb --pid $(pidof xfdesktop)" to free about 30 MB of
> memory (on a 4K display) to get 117 MB RSS.
> 
> It might be the case that some of the trimmed 117 MB isn't returned to the
> operating system because of memory fragmentation. I will try to determine
> whether this is the case.

Awesome, if you find anything, please file a new bug.
Comment 21 Jan Ziak (http://atom-symbol.net) 2020-05-04 21:56:48 CEST
I did not get any feedback on bug 16773 so I am sending a note here as a reminder.(In reply to Andre Miranda from comment #20)
> Pushed to master and xfce-4.14 branches, thanks!
> 
> (In reply to Jan Ziak (http://atom-symbol.net) from comment #17)
> > It is possible to lower the memory consumption (RSS) by calling
> > malloc_trim(0) from "gdb --pid $(pidof xfdesktop)" to free about 30 MB of
> > memory (on a 4K display) to get 117 MB RSS.
> > 
> > It might be the case that some of the trimmed 117 MB isn't returned to the
> > operating system because of memory fragmentation. I will try to determine
> > whether this is the case.
> 
> Awesome, if you find anything, please file a new bug.

Hi. I did not get any feedback on bug 16773 within the timeframe of a week, so I decided to post a reminder here.
Comment 22 Andre Miranda editbugs 2020-05-04 22:00:04 CEST
(In reply to Jan Ziak (http://atom-symbol.net) from comment #21)
> Hi. I did not get any feedback on bug 16773 within the timeframe of a week,
> so I decided to post a reminder here.

Hi Jan, sorry for not commenting, that bug is on my inbox (among three other), I hope to get to it before the end this week.
Thanks for one more patch!

Bug #16314

Reported by:
Hakan Bayındır
Reported on: 2019-12-30
Last modified on: 2020-05-04
Duplicates (1):
  • 16531 xfdesktop consumes 2.5 GB of memory

People

Assignee:
Xfce Bug Triage
CC List:
5 users

Version

Version:
4.14.1

Attachments

xfdesktop memory usage log, 15 minutes resolution, 10 days. (83.93 KB, text/x-log)
2019-12-30 06:49 CET , Hakan Bayındır
no flags
xfdesktop memory usage graph, 15 minutes resolution, 10 days. (72.10 KB, image/png)
2019-12-30 07:03 CET , Hakan Bayındır
no flags
Valgrind - Invalid read of size 8 - xfce-backdrop.c:1714 (8.40 KB, text/plain)
2020-03-15 12:49 CET , Jan Ziak (http://atom-symbol.net)
no flags
backdrop.patch (804 bytes, patch)
2020-03-15 13:00 CET , Jan Ziak (http://atom-symbol.net)
no flags
0001-Fix-memory-leak-when-reconnecting-DP-monitor-Bug-16314.patch (1.14 KB, patch)
2020-04-11 15:53 CEST , Jan Ziak (http://atom-symbol.net)
no flags

Additional information