1

I am checking my ram usage using free -lh command and it shows me below results.

             total       used       free     shared    buffers     cached
Mem:           62G        29G        33G       278M       335M        19G
Low:           62G        29G        33G
High:           0B         0B         0B
-/+ buffers/cache:       9.1G        53G
Swap:          15G         0B        15G

As i can see the used ram is 29GB and available ram is 33GB but when i check the same using top command it shows me below output.

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
23555 glassfi+  20   0 19.896g  5.270g  55092 S   0.0  8.4 121:16.24 java
 2457 hg+       20   0 20.294g  981344  20588 S   0.0  1.5   6:00.18 java
 2615 hg+       20   0 20.294g  950520  20560 S   0.0  1.4   0:22.18 java
 1992 tomcat6   20   0 5783768  518860  20976 S   0.0  0.8   8:05.15 java
.................................................

From the above result i can see glassfish is using 19GB RAM and hg+ is using 20GB Ram, it means more than 39 GB RAM is used.

My question is then why free -lh command is showing only 29GB RAM is used

1 Answers1

2

The “VIRT” column shows how much memory the processes have allocated, not how much they’re actually using. Processes can allocate more memory than they use; this is particularly true of Java processes which tend to allocate large heaps but don’t necessarily use everything. The “RES” column shows how much they’re using: just over 5GiB for the glassfish process, just under 1GiB each for the hg processes.

Stephen Kitt
  • 434,908
  • if "RES' is the actually memory used by process then sum of "RES" column values should reach to 29 GB . in my case if i add all values of "RES" column then it reaches to only around 9GB. where is remaining 20GB Memory?? – Sanjay Salunkhe Oct 05 '17 at 17:19
  • @Sanjay look at the -/+ buffers/cache line: the remaining 20GiB is used by the cache and buffers. – Stephen Kitt Oct 05 '17 at 17:21
  • but that line shows only 9.1G not 20Gib – Sanjay Salunkhe Oct 05 '17 at 17:28
  • @Sanjay yes, it shows that the system is only using 9GiB, ignoring the buffers and cache. You can see the buffer and cache sizes in the first line. – Stephen Kitt Oct 05 '17 at 17:33