10

I am using Ubuntu 20.04 (Linux 5.8.0-48-generic #54~20.04.1-Ubuntu) and today I find that gnome-shell is using LOTS OF RAM

        USER      PR  NI    VIRT    RES    SHR    %CPU  %MEM     TIME+ COMMAND                                    
   2365 gdm       20   0   14.7g  11.0g  10.8g S   0.0  35.1 143:54.82 gnome-shell                                
  76510 youran    20   0 8937064   3.2g   3.0g S   0.0  10.2 123:57.14 gnome-shell

This server has 32GB of RAM but 21GB is used even there is no workload.

            total        used        free      shared  buff/cache   available
Mem:        31Gi        21Gi       2.5Gi       1.8Gi       6.7Gi       7.1Gi

Notice that this server has been up for 123 days,

$ uptime
 13:08:18 up 123 days, 22:54,  4 users,  load average: 0.79, 1.19, 1.00

so I think there is some memory leak. I know a fresh restart can solve this problem. However, I want to know why, because Linux user should not always restart their computer. My gnome version is

$ gnome-shell --version
GNOME Shell 3.36.7

Related Questions:

  • In Gnome-shell is taking a lot of ram , the accepted answer suggests disabling gnome extensions, but I do not have any enabled extension.
    $ gnome-extensions list
    desktop-icons@csoriano
    ubuntu-appindicators@ubuntu.com
    ubuntu-dock@ubuntu.com
    $ gnome-extensions list --enabled
    $ 
    
Youran
  • 249
  • Comments are not for extended discussion; this conversation has been moved to chat. – Mitch Nov 06 '21 at 12:40
  • Status please... – heynnema Nov 10 '21 at 00:33
  • So I finally compromised and restarted GUI. – Youran Nov 11 '21 at 11:26
  • Sorry, this question's topic is asking WHY the GUI is taking so much RAM, or at least how to check why. "I know a fresh restart can solve this problem. However, I want to know why." However, I appreciate your answer, and your answer may be helpful for other users. – Youran Nov 17 '21 at 09:39
  • Your pastes show a system that is very behind on security patches so do you maintain your system? You're using 20.04.2 based on your paste; a fully upgraded system will report as 20.04.3, so what else have you held back that have caused security upgrades to not be applied? – guiverc Nov 17 '21 at 10:21
  • @Youran The WHY is because there's a bug in gnome-shell. Says so in the first line of my answer. The devs have been having a very hard time trying to figure out the bug and the fix. – heynnema Nov 20 '21 at 00:13
  • @Youran I note the process taking up the most RAM by far is the login session gnome shell (the one owned by gdm), but I see you're already logged in, hence that session shouldn't be existing unless you switched to virtual console 1 at some point. Killing that shell will probably be enough to close it, and should you need to invoke it again, just switch to VC 1 and it will respawn. – NovHak Nov 20 '21 at 03:30
  • @NovHak Yes, this is the situation. I logged in a long time ago and forgot to quit. The session exist from that time on. I now know that, as long as I remember to log out, it will not show increasing RAM usage. – Youran Nov 20 '21 at 04:01
  • I wasn't speaking about your user X session, rather about the gdm login session (the login screen if you prefer) : it's still active despite you're already logged in, and it's precisely its gnome-shell process that has the biggest resident set size (11 GB). Killing that process alone would free much memory, without having to close your user session. – NovHak Nov 20 '21 at 04:23
  • Thank you. I will keep an eye on this point. – Youran Nov 20 '21 at 07:11

2 Answers2

12

Memory leaks are a known problem (bug) of gnome-shell.

Three workarounds...

  1. Use Wayland instead of X11/xorg. (Change on your login screen).

  2. In X11/xorg, restart gnome-shell with ALT+F2, then "r", then ENTER.

  3. Update to a newer version of Ubuntu.

heynnema
  • 70,711
  • Thanks. I'll just note that GNOME Shell is still a memory hog under Wayland in 22.04. Using 37 GB of my memory at the moment. – nealmcb Mar 15 '24 at 15:21
  • @nealmcb Use the #3 solution in my answer. – heynnema Mar 15 '24 at 16:20
  • Are you saying that it has been fixed? If so, will it be backported to 22.04? Seems worthwhile to me. Many people are unwilling to run non-LTS versions. – nealmcb Mar 16 '24 at 17:31
  • @nealmcb 24.04 comes out next month. You're two years behind. – heynnema Mar 17 '24 at 13:29
  • I'm not behind yet. And I'm still wondering which bugs have been found and fixed, in which versions, so we can understand whether, and when, to upgrade to what. Upgrades often come at a large cost, and upgrading early often exposes us to other bugs that haven't been flushed out yet. But of course it may simply be true that gnome-shell is prone to leaks, and this answer will continue to be true for a long time, where we need to successively keep up-to-date. – nealmcb Mar 21 '24 at 15:13
  • @nealmcb Is your computer in a corporate environment? Do you have critical applications that must always work? Each version potentially comes with new bugs that usually get solved pretty quick, LTS or not. You can make a flash drive with whatever new version, and run/test on it until you feel comfortable. – heynnema Mar 21 '24 at 15:19
6

To automate the workaround mentioned by @heynnema I created a cron job that runs every night.
Run crontab -e as your normal user and add the following line:

20 4 * * * DISPLAY=:1 XDG_RUNTIME_DIR=/run/user/1000 dbus-send --type=method_call --print-reply --dest=org.gnome.Shell /org/gnome/Shell org.gnome.Shell.Eval string:'global.reexec_self()'

The same thing, but with a confirmation window using gnome-terminal in case I am up late and don't want to be interrupted:

20 4 * * * DISPLAY=:1 XDG_RUNTIME_DIR=/run/user/1000 gnome-terminal --window -- /bin/bash -c "read -t 10 -p 'gnome-shell will be reloaded in ten seconds, HIT ENTER TO ABORT!' || dbus-send --type=method_call --print-reply --dest=org.gnome.Shell /org/gnome/Shell org.gnome.Shell.Eval string:'global.reexec_self()'"

Check what your current DISPLAY environment variable is and change the cron job if needed(echo $DISPLAY).
If your UID isn't 1000, modify XDG_RUNTIME_DIR with your UID(use the id command to get your UID).

With that, I pretty much never notice the memory leak(with 16GB RAM).

  • IMHO this is the correct and best answer. I am seeing this same problem after doing the 22.04.1 upgrade. I posted a similar question about gnome gobbling up RAM and my question was ridiculed and eventually removed by the myopic children here. Your fix is obviously only a band-aid and the developers need to fix what's really causing this problem. But your cron job is elegant, effective and reliable. THANK YOU! – jones0610 Sep 04 '22 at 16:25
  • 1
    @jones0610 I had issues in Pop!_OS 22.04 and earlier where gnome was using +50% ram over a period of 24h. The memory leak grows the more you use the gnome UI (opening, closing, minimizing windows). In my case, I narrowed the issue down to a single extension: Ubuntu AppIndicators. The reason why people from the gnome project respond poorly to memory leak issues is probably because in 99% of cases the leak is caused by extensions. After switching to Fedora 36 I basically never have to restart gnome. Probably because it doesn't use Ubuntu AppIndicators. – Morpheus0x Sep 05 '22 at 14:27
  • Thanks Morpheus0x! I really like the AppIndicators extension. I've not see this problem in any past versions of Ubuntu but I may be running Xorg on some or all of my other machines. I had an issue on this particular machine in the past and shifted to Wayland to fix it. It's currently using the Ubuntu login choice. Gnome is eating RAM at the rate of ~ 50M per hour. One would think that instead of getting butt-hurt over questions the dev team would either fix this or come up with a AppIndicator replacement that is supportable. Sadly, the cron job doesn't fix this issue for me – jones0610 Sep 07 '22 at 06:03
  • There seems to be a supportable AppIndicator extension at https://github.com/ubuntu/gnome-shell-extension-appindicator but I can't figure out how to install it. – jones0610 Sep 07 '22 at 06:20
  • After downloading the latest version (v42) ninja -C . appindicatorsupportrgcjonas.gmail.com.v42.shell-extension.zip installed it. But I can't figure out how to enable/disable it. – jones0610 Sep 07 '22 at 06:30
  • it uses 7GB for me wth – silentsudo Jul 25 '23 at 10:41