Score:0

Understanding memory usage in Ubuntu - after upgrading to Ubuntu 21.10 from 20.04 my memory usage increased dramatically

cn flag

After reading a lot of different articles on the Internet I'm still confused about how to find exactly what is using my memory.

After upgrading to Ubuntu Server 21.10 from 20.04 my memory usage increased dramatically and I'm trying to find out what is responsible for that.

When I'm logging into the server there are some welcome stats that say: Memory usage: 65%.

When I run free -m I get:

               total        used        free      shared  buff/cache   available
Mem:           31881       20575        9669         162        1636       10680
Swap:           8191           0        8191

So far it matches. I understand that there is some confusion here and my actual free memory is free + buff/cache or something like that but then I found a command on the Internet that returns the sum of memory consumption of all processes:

$ echo $(ps -o rss= ax | tr '\n' +) 0 | bc
5978056

That gives 5-6GB. It doesn't match with any value returned from free -m. The result of top sorted by memory column seems to confirm this:

top - 10:53:49 up 3 days, 13:28,  1 user,  load average: 0.11, 0.10, 0.09
Tasks: 451 total,   1 running, 438 sleeping,   0 stopped,  12 zombie
%Cpu(s):  0.2 us,  0.1 sy,  0.0 ni, 99.8 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
MiB Mem :  31881.4 total,   9791.5 free,  20453.8 used,   1636.1 buff/cache
MiB Swap:   8192.0 total,   8192.0 free,      0.0 used.  10801.7 avail Mem

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
   3930 mssql     20   0   20.6g   1.1g  44584 S   2.0   3.4 116:22.67 sqlservr
   3115 mysql     20   0 5336868 726652  19148 S   0.3   2.2  11:29.69 mariadbd
  19021 www-data  20   0  438324 231656 169396 S   0.0   0.7   3:31.67 php-fpm8.0
   3348 www-data  20   0  438112 231096 171232 S   0.0   0.7   3:52.81 php-fpm8.0
   3349 www-data  20   0  436832 227820 168664 S   0.0   0.7   3:26.81 php-fpm8.0
   3356 www-data  20   0  429292 223864 171360 S   0.0   0.7   3:59.62 php-fpm8.0
   3354 www-data  20   0  427580 221492 170016 S   0.0   0.7   3:47.99 php-fpm8.0
   3357 www-data  20   0  428052 221336 169144 S   0.0   0.7   3:51.86 php-fpm8.0
   3355 www-data  20   0  427056 220772 170064 S   0.0   0.7   3:35.60 php-fpm8.0
   3345 www-data  20   0  427080 220116 169212 S   0.0   0.7   3:51.67 php-fpm8.0
   3365 www-data  20   0  425712 220024 171216 S   0.0   0.7   3:42.05 php-fpm8.0
  19700 www-data  20   0  424868 218940 169908 S   0.0   0.7   3:39.68 php-fpm8.0
   3363 www-data  20   0  423260 218804 171252 S   0.0   0.7   3:45.00 php-fpm8.0
   3341 www-data  20   0  423184 217468 170044 S   0.0   0.7   3:49.10 php-fpm8.0
   3353 www-data  20   0  421016 214860 169556 S   0.0   0.7   3:30.55 php-fpm8.0
   3351 www-data  20   0  420432 212680 169256 S   0.0   0.7   3:25.20 php-fpm8.0
   2674 www-data  20   0   22.7g 169652  41068 S   0.0   0.5   3:03.73 dotnet
   2696 git       20   0 2181008 165396  43788 S   0.0   0.5   7:55.15 gitea
   1324 root      19  -1  134508  72360  71296 S   0.0   0.2   0:15.71 systemd-journal
   4159 root      20   0 2052028  62724  31824 S   0.0   0.2   4:02.05 dockerd
2289460 root      20   0 1910052  39892  20176 S   0.0   0.1   0:23.22 snapd
   2726 root      20   0 2011284  31740  16344 S   0.0   0.1   8:44.13 containerd
   2703 root      20   0  270968  26244  19164 S   0.0   0.1   0:23.63 php-fpm8.0
   3251 www-data  20   0  102500  21180  16652 S   0.0   0.1   6:46.80 nginx
   2734 root      20   0 1139124  20408   7864 S   0.3   0.1  14:21.22 fail2ban-server
   3254 www-data  20   0  101948  20048  16336 S   0.0   0.1   0:02.27 nginx
   4165 minidlna  20   0  239012  19372  14324 S   0.0   0.1   0:39.26 minidlnad
   2017 root      rt   0  280960  18584   8772 S   0.3   0.1   0:47.47 multipathd
   2801 root      20   0  112464  18560   9988 S   0.0   0.1   0:00.05 unattended-upgr
   4242 root      20   0   84880  17604  14660 S   0.0   0.1   0:15.41 smbd
   2664 root      20   0   34740  17488   8508 S   0.0   0.1   0:00.08 networkd-dispat
   3253 www-data  20   0  101372  17020  13748 S   0.0   0.1   0:00.18 nginx
 203855 root      20   0  295244  16160  13364 S   0.0   0.0   0:02.36 packagekitd
   2700 mssql     20   0   72632  14852   6224 S   0.0   0.0   0:00.85 sqlservr
   3257 www-data  20   0  101240  14756  11540 S   0.0   0.0   0:00.02 nginx
   4234 root      20   0   22436  12928   3544 S   0.0   0.0   0:10.19 ddclient - slee
   4160 root      20   0   70756  12212   9912 S   0.0   0.0   0:09.06 nmbd
   2676 root      20   0  395152  11632   8612 S   0.0   0.0   0:53.73 udisksd
   2591 systemd+  20   0   23640  11164   7108 S   0.0   0.0   1:26.88 systemd-resolve
      1 root      20   0  166644  10784   5516 S   0.0   0.0   0:29.92 systemd
   4561 root      20   0   26968  10156   7144 S   0.0   0.0   0:44.81 portainer
   4288 root      20   0   84864   9184   6240 S   0.0   0.0   0:00.99 lpqd
1319978 rychu     20   0   15832   8848   6896 S   0.0   0.0   0:00.06 systemd
   4284 root      20   0   82640   8748   5956 S   0.0   0.0   0:00.59 smbd-notifyd
   3255 www-data  20   0  101088   8668   5496 S   0.0   0.0   0:00.00 nginx
   2706 redis     20   0   70552   8420   6348 S   0.0   0.0  13:27.82 redis-server
1319928 root      20   0   14860   8112   6648 S   0.0   0.0   0:00.03 sshd
   2671 root      20   0  126992   7576   6720 S   0.0   0.0   0:22.24 thermald

Here is my snap list output:

$ snap list
Name                 Version    Rev    Tracking       Publisher   Notes
canonical-livepatch  10.1.2     126    latest/stable  canonical✓  -
core                 16-2.54.3  12725  latest/stable  canonical✓  core
core18               20211215   2284   latest/stable  canonical✓  base
core20               20220114   1328   latest/stable  canonical✓  base
lxd                  4.0.8      21835  4.0/stable/…   canonical✓  -

So I'm confused where does my ~14GB of used memory is?

heynnema avatar
ru flag
Redacting info from the **TOP** output doesn't help us to help you. You have at least a couple of suspect processes, but I can't tell you more.
Rychu avatar
cn flag
@heynnema updated the `top` output
heynnema avatar
ru flag
Just for curiosity sake, show me `snap list`.
Rychu avatar
cn flag
@heynnema updated again
Rychu avatar
cn flag
Maybe it's important - my server has two ZFS pools
heynnema avatar
ru flag
Thanks for updating your question. I guess that I'm beyond my memory troubleshooting skills on this problem. Sorry.
Score:2
mx flag

RSS (Resident Set Size) shows how much physical memory a given process uses. A part of that memory can be shared by more processes so you can't just add them up.

The answer in this Stackoverflow gives a deeper explanation: What is RSS and VSZ.

Score:2
co flag

Your running processes seem to utilize ca. 18% of your memory. And remaining usage could be ZFS ARC (basically up to 50% of system memory by default). See Is ZFS on Ubuntu 20.04 using a ton of memory?

P.S. Don't look at “free” memory - in essence it is the memory that is unused. Consider this like 35% RAM of my computer is wasting now (so to say it's superfluous at the moment).

After upgrading to Ubuntu Server 21.10 from 20.04 my memory usage increased dramatically

Together with output of free and top it means only that 21.10 is able to utilize your memory better than 20.04, nothing else.

Rychu avatar
cn flag
That seems correct to me. I run `arc_summary` and it says `ARC size (current): 33.8% 5.3GiB` so looks like this is the missing memory I was looking for (my system was restarted so the values in the original question are obsolete). The current memory sum from `top` is 5.51 GB. In total it gives 10.8GB so 34.75% of all of my RAM. When logging into the system I see in `motd`: `Memory usage: 29%`. So, considering, what @Soren A said, that some of the memory shown by `top` is shared, It matches now! Thank you. BTW. That also explains why I observe this rise mostly after weekly scrubbings.
Score:0
in flag

My machine also has 32GB of memory:

$ free -m

              total        used        free      shared  buff/cache   available
Mem:          32027       14140        6459         490       11427       16733
Swap:          8058           0        8058

$ snap list

Name               Version    Rev    Tracking       Publisher   Notes
core               16-2.54.3  12725  latest/stable  canonical✓  core
core18             20211215   2284   latest/stable  canonical✓  base
pycharm-community  2021.3.2   267    latest/stable  jetbrains✓  classic

To list the processes using the memory, sorted by percentage, use:

$ ps -o pid,user,%mem,command ax | sort -k3 -r -n

 5364 rick     10.5 /snap/pycharm-community/267/jbr/bin/java (... SNIP ...)
 3219 rick      8.1 /usr/lib/firefox/firefox
31414 rick      7.2 /usr/lib/firefox/firefox -contentproc -childID 20 -isForBrowser -prefsLen 10960 -prefMapSize 244395 -parentBuildID 20210415204500 -appdir /usr/lib/firefox/browser 3219 true tab
 3385 rick      4.7 /usr/lib/firefox/firefox -contentproc -childID 1 -isForBrowser -prefsLen 387 -prefMapSize 244395 -parentBuildID 20210415204500 -appdir /usr/lib/firefox/browser 3219 true tab
 1449 root      3.0 /usr/lib/xorg/Xorg -core :0 -seat seat0 -auth /var/run/lightdm/root/:0 -nolisten tcp vt7 -novtswitch
14808 rick      2.9 /usr/lib/firefox/firefox -contentproc -childID 15 -isForBrowser -prefsLen 6660 -prefMapSize 244395 -parentBuildID 20210415204500 -appdir /usr/lib/firefox/browser 3219 true tab
 3552 rick      2.5 /usr/lib/firefox/firefox -contentproc -childID 3 -isForBrowser -prefsLen 532 -prefMapSize 244395 -parentBuildID 20210415204500 -appdir /usr/lib/firefox/browser 3219 true tab
 2928 rick      2.2 compiz
25621 rick      2.1 /usr/lib/firefox/firefox -contentproc -childID 12 -isForBrowser -prefsLen 6660 -prefMapSize 244395 -parentBuildID 20210415204500 -appdir /usr/lib/firefox/browser 3219 true tab
18592 rick      1.6 /usr/lib/firefox/firefox -contentproc -childID 11 -isForBrowser -prefsLen 6660 -prefMapSize 244395 -parentBuildID 20210415204500 -appdir /usr/lib/firefox/browser 3219 true tab
 3843 rick      1.5 /usr/lib/firefox/firefox -contentproc -childID 5 -isForBrowser -prefsLen 5369 -prefMapSize 244395 -parentBuildID 20210415204500 -appdir /usr/lib/firefox/browser 3219 true tab
 3522 rick      1.5 /usr/lib/firefox/firefox -contentproc -childID 2 -isForBrowser -prefsLen 532 -prefMapSize 244395 -parentBuildID 20210415204500 -appdir /usr/lib/firefox/browser 3219 true tab
 3660 rick      1.4 /usr/lib/firefox/firefox -contentproc -childID 4 -isForBrowser -prefsLen 532 -prefMapSize 244395 -parentBuildID 20210415204500 -appdir /usr/lib/firefox/browser 3219 true tab
 3156 rick      0.9 /usr/bin/nautilus --gapplication-service

(... SNIP ...)

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.