1

I have a VPS with 8 GB of memory running mainly docker containers.

When I go to the cloud monitoring service provided by my provider, I see that ~10% of the RAM is used.

I don't understand how this value is related to the output of the three following commands (I have put the outputs of these at the end of my question):

$ free -mh
$ top
$ docker stats

Could someone explain me why free -mh tells me that I am using 7.5/7.8GB of memory, while my VPS tells me I am only using 10%, and the values given by the top command do not make sense to me?


free

free -mh
             total       used       free     shared    buffers     cached
Mem:          7.8G       7.5G       275M       144M       348M       2.3G
-/+ buffers/cache:       4.9G       3.0G
Swap:         1.9G       454M       1.5G

docker stats

docker stats --no-stream
CONTAINER           CPU %               MEM USAGE / LIMIT       MEM %               NET I/O               BLOCK I/O             PIDS
496ec398b3f9        0.09%               2.285 MiB / 7.812 GiB   0.03%               648 B / 648 B         40.96 kB / 0 B        0
e8d13a2df058        0.07%               674.2 MiB / 7.812 GiB   8.43%               196.4 kB / 252.3 kB   10.43 MB / 364.5 kB   0
87f43f54f772        0.01%               276.8 MiB / 7.812 GiB   3.46%               7.396 MB / 7.802 MB   71.07 MB / 0 B        0
6a9039c835ad        3.49%               885.1 MiB / 7.812 GiB   11.06%              150.6 kB / 20.93 MB   124.9 MB / 138.7 MB   0
5f56a4113665        0.91%               1014 MiB / 7.812 GiB    12.67%              2.681 GB / 368.8 MB   197.2 MB / 17.56 MB   0
8dabe37320f9        0.10%               3.762 MiB / 7.812 GiB   0.05%               270.1 MB / 213.4 MB   249.9 kB / 3.883 MB   0
57f6c6b96e72        0.34%               39.24 MiB / 7.812 GiB   0.49%               58.84 MB / 67.32 MB   6.246 MB / 4.649 MB   0
738e3d84e9d4        0.00%               3.562 MiB / 7.812 GiB   0.04%               1.048 GB / 1.045 GB   1.155 MB / 0 B        0
17704ca17a93        0.00%               49.04 MiB / 7.812 GiB   0.61%               271.8 MB / 1.484 GB   83.34 MB / 0 B        0
3beefb4fd14a        0.04%               31.12 MiB / 7.812 GiB   0.39%               342.5 kB / 875.2 kB   5.235 MB / 69.63 kB   0
4035cf7f0af5        0.04%               68.16 MiB / 7.812 GiB   0.85%               215.2 MB / 672.8 MB   148.9 MB / 16.09 GB   0
4fba55aa76a4        0.05%               42.61 MiB / 7.812 GiB   0.53%               147.5 kB / 19.09 kB   167 MB / 24.58 kB     0
83571a1747cb        0.00%               8.207 MiB / 7.812 GiB   0.10%               25.23 MB / 20.19 MB   13.8 MB / 8.192 kB    0

top

top # Sorted by memory usage

top - 10:14:19 up 20 days, 17:27,  1 user,  load average: 0.36, 0.43, 0.47
Tasks: 284 total,   1 running, 283 sleeping,   0 stopped,   0 zombie
%Cpu(s):  1.0 us,  0.4 sy,  0.0 ni, 98.5 id,  0.1 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem:   8191140 total,  7896220 used,   294920 free,   356984 buffers
KiB Swap:  1998844 total,   465312 used,  1533532 free.  2449876 cached Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                                                                                   
 8034 systemd+  20   0  711.4m 469.8m   2.7m S   0.0  5.9   0:00.00 clamd                                                                                                     
43964 998       20   0  712.7m 369.3m   8.1m S   1.7  4.6 144:06.61 bundle                                                                                                    
44897 998       20   0  688.2m 226.1m   7.1m S   0.0  2.8   0:03.19 bundle                                                                                                    
44895 998       20   0  507.8m 194.5m   6.9m S   0.0  2.4   0:02.27 bundle                                                                                                    
46409 www-data  20   0 3728.6m 167.0m   4.7m S   0.0  2.1  10:42.66 node                                                                                                      
43885 998       20   0  505.8m 158.7m   6.8m S   0.0  2.0   0:46.59 bundle                                                                                                    
 8058 Debian-+  20   0  230.3m 114.9m   6.4m S   0.0  1.4   0:00.72 /usr/sbin/amavi                                                                                           
 8057 Debian-+  20   0  228.7m 113.3m   6.4m S   0.0  1.4   0:00.22 /usr/sbin/amavi                                                                                           
 8052 Debian-+  20   0  227.0m 112.1m   5.5m S   0.0  1.4   0:01.21 /usr/sbin/amavi                                                                                           
46410 www-data  20   0  998.3m 105.9m   4.5m S   0.0  1.3   9:20.22 node                                                                                                      
46418 www-data  20   0  983.0m  95.9m   6.1m S   0.0  1.2   0:51.50 node                                                                                                      
46415 www-data  20   0  993.0m  80.7m   4.2m S   0.0  1.0   0:19.56 node                                                                                                      
46400 www-data  20   0  974.3m  78.4m   4.3m S   0.3  1.0  60:12.96 node                                                                                                      
46402 www-data  20   0  991.1m  76.0m   4.7m S   0.0  1.0   0:20.13 node                                                                                                      
46414 www-data  20   0  990.3m  75.7m   4.0m S   0.0  0.9   0:58.40 node                                                                                                      
46411 www-data  20   0  971.2m  74.5m   3.9m S   0.0  0.9   7:59.44 node                                                                                                      
46398 www-data  20   0  985.9m  71.8m   4.0m S   0.0  0.9   0:18.67 node                                                                                                      
46408 www-data  20   0  957.8m  64.1m   3.6m S   0.0  0.8   8:40.84 node                                                                                                      
  311 mikael    20   0  636.8m  63.0m  57.4m S   0.0  0.8   0:00.18 php-fpm7.1                                                                                                
46413 www-data  20   0 1754.8m  52.8m   3.3m S   0.0  0.7   0:01.27 node                                                                                                      
  550 root      20   0 1872.5m  52.0m  19.7m S   0.0  0.7  96:58.89 dockerd                                                                                                   
 1415 999       20   0  966.3m  48.6m   4.9m S   0.0  0.6  19:56.53 mysqld                                                                                                    
  322 mikael    20   0  646.2m  47.1m  31.0m S   0.0  0.6   0:04.53 php-fpm7.1                                                                                                
  321 mikael    20   0  646.2m  46.7m  30.8m S   0.0  0.6   0:05.11 php-fpm7.1                                                                                                
  360 mikael    20   0  643.8m  44.4m  31.0m S   0.0  0.6   0:03.86 php-fpm7.1                                                                                                
13400 999       20   0  937.7m  34.0m   3.9m S   0.0  0.4  12:39.05 mysqld                                                                                                    
30467 999       20   0  344.9m  25.6m   4.6m S   0.0  0.3  38:51.77 mongod                                                                                                    
44940 996       20   0   59.1m  21.7m   7.7m S   0.0  0.3   0:00.14 postgres          

Some commands outputs

$ uname -a
Linux domain.com 3.16.0-4-amd64 #1 SMP Debian 3.16.39-1 (2016-12-30) x86_64 GNU/Linux

$ docker version
Client:
 Version:      1.12.6
 API version:  1.24
 Go version:   go1.6.4
 Git commit:   78d1802
 Built:        Tue Jan 10 20:17:57 2017
 OS/Arch:      linux/amd64

Server:
 Version:      1.12.6
 API version:  1.24
 Go version:   go1.6.4
 Git commit:   78d1802
 Built:        Tue Jan 10 20:17:57 2017
 OS/Arch:      linux/amd64

$ virt-what
vmware
Holt
  • 181
  • 2
  • 8
  • 1
    You will see this often on servers. As far as I know from deb/ubuntu it uses most of the ram to store/cache data if the ram is unused. If you start another program that needs i.e. 4gb those 4gb will be available. – Tom-Oliver Heidel Feb 17 '17 at 14:47
  • The amount of memory that's used is not a useful metric. Honestly, you just shouldn't worry about it since it isn't a meaningful measurement. If lots of memory is free, that does indicate that your system isn't under any memory pressure and couldn't benefit from more memory. But that's about the only way it's useful. If it isn't a large value, it means almost nothing. – David Schwartz Feb 18 '17 at 07:56
  • 1
    As I understand it, this is not about memory usage _per se_ but about the discrepancy between the values shown in the VM and the values shown in the VM provider's metrics, neither of which apparently have even a passing resemblance to the other. – Michael Hampton Feb 18 '17 at 18:58
  • @MichaelHampton Yes, exactly! I had to restart my server for some reason, and I have similar output for `top` and `docker stats`, but now `free -mh` gives me `4.4G` used and `3.4G` free... I don't really understand... – Holt Feb 18 '17 at 19:07

2 Answers2

2

Your memory is distributed this way:

  • 5.2Gb is actively used by processes + 0.5Gb is swapped out to disk.
  • 2.3Gb of page cache (file cache) can be freed and used by active processes at any time they need it (in exchange for file operations performance of course).

So, your memory usage is definitely not at 10%. You really have some memory pressure on VPS and can possibly benefit from raising it's memory size.

GreyWolf
  • 76
  • 3
  • Why do you think he has memory pressure? – David Schwartz Feb 18 '17 at 07:54
  • 1
    Because page cache and buffers are large, some memory was already moved to swap, free memory is low. There're usually symptoms of active file system operations, hungry for cache.Another symptom is a combination of mysql, postgre and mongodb on the same machine. Mongodb is known to eat all available memory by the way of mmaping its datafiles, so, possibly large pagecache deals with mongo datafiles. BTW, combination of 3 DB servers, PHP and NodeJS on one VPS is generally bad idea :) – GreyWolf Feb 18 '17 at 09:25
-4

There is a lot of cache memory consumed on your VPS, i suggest you to clear cache memory you will be having more memory as free.

Every Linux System has three options to clear cache without interrupting any processes or services. Run the below commands to clear the unwanted memory

1) clear page-cache - # sync; echo 1 > /proc/sys/vm/drop_caches

2) clear dentries and inodes - # sync; echo 2 > /proc/sys/vm/drop_caches

3) clear both page and dentries and inodes - # sync; echo 3 > /proc/sys/vm/drop_caches

R Jack
  • 1
  • 1