0

I have two vm's one with 2vCPU , 4GB RAM and other with 4vCPU and 8GB RAM

Now I have installed / ran the same application(k8s pods) with same memory , cpu allocations , requests , limits on both the VM's.

Observations

  • When dumping the entire top output on both vm's and summing up all process's Resident memory I get to see similar numbers on both VM's i.e around 2GB consumed.
  • Summing up all the numbers under column VIRT gives 55456748 more or less on both vm's

Question

  • However in top command summary / process memory info commands shows different numbers on two VM's , Any pointers on why & where , how to find out the extra memory/root cause for memory consumption 4cPU and 8 GB ?
2VCPU 4GB

$ cat /proc/meminfo
MemTotal:        3880500 kB
MemFree:          144924 kB
MemAvailable:     590280 kB
SwapTotal:       1327100 kB
SwapFree:        1261564 kB
4VCPU 8GB

$ cat /proc/meminfo
MemTotal:        8008964 kB
MemFree:          197860 kB
MemAvailable:    1470412 kB
SwapTotal:       1327100 kB
SwapFree:        1321408 kB
2
  • Do not consider MemFree. Instead use the MemAvailable for memory usage.
    – FedKad
    Jun 30, 2021 at 16:04
  • @FedonKadifeli I've updated the question with MemAvailable , still has the discrepancy. i.e, 8GB RAM shows only 1.5 GB available and 4GB VM shows only 590 MB available
    – Mozhi
    Jun 30, 2021 at 16:20

2 Answers 2

1

Do not use MemFree, but instead use the MemAvailable metric to determine the amount of "free" memory the system can use for applications without going to swap.

A detailed explanation for this is given here, for example:

https://superuser.com/questions/980820/what-is-the-difference-between-memfree-and-memavailable-in-proc-meminfo

I have written the following Bash function for general memory usage inspection. You can insert the code to the end of your .bash_aliases file.

function mf
{
 mt=($(grep '^MemTotal:' /proc/meminfo))
 ma=($(grep '^MemAvailable:' /proc/meminfo))
 let mtmb=${mt[1]}/1024
 let mamb=${ma[1]}/1024
 let mumb="(${mt[1]}-${ma[1]})/1024"
 let muse="(${mt[1]}-${ma[1]})*100/${mt[1]}"

 st=($(grep '^SwapTotal:' /proc/meminfo))
 sf=($(grep '^SwapFree:' /proc/meminfo))
 let stmb=${st[1]}/1024
 let sfmb=${sf[1]}/1024
 let sumb="(${st[1]}-${sf[1]})/1024"
 if (( st[1] != 0 )) ; then
   let suse="(${st[1]}-${sf[1]})*100/${st[1]}"
 else
   suse=0
 fi
 printf "%17s%10s%10s%6s
Memory %9sM%9sM%9sM%5s%%
Swap   %9sM%9sM%9sM%5s%%
" 'Total' 'Used' 'Av/Free' 'Use%' \
   $mtmb $mumb $mamb $muse \
   $stmb $sumb $sfmb $suse
}
2
  • Thank you for the response , but i still see discrepancy in final numbers with your script as well , not saying anything wrong with your script but underlying numbers reported by vm may be misleading On 4cpu 8GB RAM VM Total Used Av/Free Use% Memory 7821M 6377M 1443M 81% Swap 1295M 5M 1290M 0%
    – Mozhi
    Jun 30, 2021 at 16:24
  • ON 2 cpu 4GB RAM VM Total Used Av/Free Use% Memory 3789M 3209M 579M 84% Swap 1295M 63M 1232M 4%
    – Mozhi
    Jun 30, 2021 at 16:24
1

OK , This was due to hugepages configuration that i've set while installing an application , OS creates the pages apparently based on values specified while enabling them.

2VCPU 

around 600 pages with each 2048k i.e 1.23 GB locked 

4 vcpu

around 2048 pages with each 2048k i.e 4.2 GB locked in main memory
1
  • 1
    There are many reasons that a system with larger memory will use more memory than an identical system with smaller memory. You found one of them. Please, expand your answer as you find other reasons. (My answer was given to stress the point that MemAvailable should be used instead of MemFree. And I am giving my points to your answer!)
    – FedKad
    Jul 1, 2021 at 11:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .