After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 766353 - Huge memory usage related with changing background
Huge memory usage related with changing background
Status: RESOLVED FIXED
Product: gnome-shell
Classification: Core
Component: background
3.16.x
Other Linux
: Normal major
: ---
Assigned To: gnome-shell-maint
gnome-shell-maint
: 769927 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2016-05-12 23:04 UTC by Damian
Modified: 2016-08-15 14:33 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
System Monitor shows huge memory usage of Gnome Shell (27.18 KB, image/png)
2016-05-12 23:04 UTC, Damian
  Details
background: free MetaBackground explicitly when its MetaBackgroundActor is destroyed (1.46 KB, patch)
2016-06-10 11:09 UTC, Hyungwon Hwang
committed Details | Review

Description Damian 2016-05-12 23:04:18 UTC
Created attachment 327745 [details]
System Monitor shows huge memory usage of Gnome Shell

Appearance:
when background settings changes fast and repeatedly - the more frequency, the greater and fastest memory usage can be observed.
most noticeable when change wallpaper mode ("picture-options"), but changing "color-shading-type", and "picture-uri" values also works. 


Occurs:
with proprietary and open-source drivers, with AMD/ATI and NVIDIA cards,
on i386 and amd64 architecture, in X and Wayland session.
I recreated this error in configurations:

Ubuntu 14.04 amd64
gnome-shell 3.12.2
4.3.0 NVIDIA 355.11

Ubuntu 15.10 amd64
gnome-shell 3.16.4
4.4.0 NVIDIA 352.63

Fedora 24 i386
GNOME Shell 3.20.1
Gallium 0.4 on NVC4

Fedora 24 i386
GNOME Shell 3.20.1
Gallium 0.4 on ATI RV530


How reproduce the issue:
0. disable icons on desktop (gsettings set org.gnome.desktop.background show-desktop-icons false)

I) how I found this bug:
1. open "gnome-tweak-tool" 
2. go to "Desktop" -> "Background" (not "Lock Screen")
3. constantly and quickly change value in "Mode" combo box (by mouse scrolling, not click and choose from a list; to several seconds)

II) how I recreated in other configurations:
1. set image as wallpaper
2. run this script to changing background settings repeatedly as fast as possible (warning: infinite loop, run in terminal, CTRL + C to cancel):

#!/bin/bash
declare -a arr=("wallpaper" "centered" "scaled" "stretched" "zoom" "spanned")
while [ 1 ]; do
for mode in "${arr[@]}"; do
echo "$mode"
gsettings set org.gnome.desktop.background picture-options "$mode"
sleep 0.1
done
done


(Perhaps the problem is confirmed by another user in this commentary: https://bugzilla.gnome.org/show_bug.cgi?id=735705#c56)
Comment 1 Florian Müllner 2016-05-13 14:46:08 UTC
Does the memory usage go down if you run "imports.system.gc()" in looking glass (<alt>f2 lg<enter>)?
Comment 2 Damian 2016-05-13 15:48:47 UTC
(In reply to Florian Müllner from comment #1)
> Does the memory usage go down if you run "imports.system.gc()" in looking
> glass (<alt>f2 lg<enter>)?

Memory usage is only increasing, and not decreasing, even after forcing garbage collector.

When using proprietary graphics drivers, system starts to use swap space, everything is slowing down. Appear the message like "Failed to launch 'app' Failed to fork (Cannot allocate memory)", etc. Only restart shell (press ALT+F2, type r, and press Enter) can return to initial state (I will not make it on time, the all system is freeze). With using open-source drivers, freezing proceeds much faster, and then left only a hard reset computer.
Comment 3 Hussam Al-Tayeb 2016-05-13 17:32:11 UTC
(In reply to Florian Müllner from comment #1)
> Does the memory usage go down if you run "imports.system.gc()" in looking
> glass (<alt>f2 lg<enter>)?

It does a significant amount here but not all the memory is recovered.
If it was 312MB before the background change, it goes up to 321MB and the  "imports.system.gc()" brings it down to 316MB.
Comment 4 Hussam Al-Tayeb 2016-05-15 20:40:34 UTC
Can garbage collection be done automatically?
Comment 5 Eric Gach 2016-06-01 15:27:35 UTC
Yes, same bug I have experienced and mentioned in the prior comment. gnome-shell slowly leaks memory as the background changes. The only way I can make the memory "go down" is by restarting gnome-shell with "r" through the run dialog or using `kill -1` to make it reload itself. Running imports.system.gc() does not have much, if any, effect on memory usage while gnome-shell is running. I should note, the only time I have personally seen this happen is when using proprietary video drivers (currently nvidia). When using an onboard intel graphics card with the open source drivers, I have no memory leaking problems to this extent. I can't use the nouveau driver to see if that helps memory either because it locks the GPU after 30 minutes or so forcing a reboot. Please let me know if there is any information I can contribute, I'd be more than happy to provide anything needed or desired just to help track this down.
Comment 6 Hyungwon Hwang 2016-06-10 11:09:28 UTC
Created attachment 329557 [details] [review]
background: free MetaBackground explicitly when its MetaBackgroundActor is destroyed

The problem happens when background mode or file is changed, because the memory which MetaBackground uses a lot of memory and not freed until garbage collection runs.

The attached patch fixes this problem by freeing MetaBackground explicitly when its MetaBackgroundActor is destroyed.

Please look at it, if it could be help.


ps. I modified Damian's script for testing of changing background file.
#!/bin/bash
declare -a arr=("file:///usr/share/backgrounds/gnome/Blinds.jpg" "file:///usr/share/backgrounds/gnome/Bokeh_Tails.jpg" "file:///usr/share/backgrounds/gnome/Chmiri.jpg" "file:///usr/share/backgrounds/gnome/Dark_Ivy.jpg" "file:///usr/share/backgrounds/gnome/Fabric.jpg" "file:///usr/share/backgrounds/gnome/Flowerbed.jpg" "file:///usr/share/backgrounds/gnome/FootFall.png" "file:///usr/share/backgrounds/gnome/Godafoss_Iceland.jpg" "file:///usr/share/backgrounds/gnome/Mirror.jpg" "file:///usr/share/backgrounds/gnome/Road.jpg" "file:///usr/share/backgrounds/gnome/Sandstone.jpg" "file:///usr/share/backgrounds/gnome/Stones.jpg" "file:///usr/share/backgrounds/gnome/Terraform-green.jpg" "file:///usr/share/backgrounds/gnome/Waves.jpg" "file:///usr/share/backgrounds/gnome/Whispy_Tails.jpg" "file:///usr/share/backgrounds/gnome/adwaita-day.jpg" "file:///usr/share/backgrounds/gnome/adwaita-lock.jpg" "file:///usr/share/backgrounds/gnome/adwaita-morning.jpg" "file:///usr/share/backgrounds/gnome/adwaita-night.jpg")
while [ 1 ]; do
for f in "${arr[@]}"; do
echo "$f"
gsettings set org.gnome.desktop.background picture-uri "$f"
sleep 0.1
done
done
Comment 7 Florian Müllner 2016-06-10 11:10:46 UTC
Review of attachment 329557 [details] [review]:

LGTM, thanks!
Comment 8 Rui Matos 2016-06-29 13:19:10 UTC
Ups, this almost fell through the cracks.

   e0307bb..71c26cc  gnome-3-20 -> gnome-3-20
   b5dd4d1..e72d388  master -> master


Attachment 329557 [details] pushed as e72d388 - background: free MetaBackground explicitly when its MetaBackgroundActor is destroyed
Comment 9 Florian Müllner 2016-08-15 14:33:15 UTC
*** Bug 769927 has been marked as a duplicate of this bug. ***