M HYPE SPLASH
// general

gnome-shell consumes several GB of RAM

By Emily Wilson

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
    $ gnome-extensions list --enabled
    $ 
10

2 Answers

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.

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).

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy