Sum of memory of few processes in top is greater than 100%
The %MEM field is the number of pages of physical memory the process is using times 100 divided by the total number of pages of physical memory. There is no reason it should sum to 100 -- consider ten processes that are all using the very same page of physical memory.
You may also have a buggy version of top
that computes %MEM as VSZ/mem instead of RSS/mem. Find a case where these produce different results and make sure the top value is RSS/mem.
Use top -v
to see if you have the BusyBox version of top. That tends to be buggier than the procps version.
Related videos on Youtube
Prakash
Updated on September 18, 2022Comments
-
Prakash over 1 year
I'm trying to calculate the amount of memory used by AMP in an LAMP stack machine.
top -bn1 | grep -E '(mysql|httpd|php)' | awk '{mem += $(NF-2)} END {print mem}'
But the sum generated using the above command is greater than 100%, but I was expecting something below 100% since individual processes memory usage is already represented in % by
top
.Please help me understand whether memory reported by
top
can't be used this way to calculate the memory usage?-
Zoredache over 11 yearsAdding up percentages is almost always the wrong way to do things.
-
Prakash over 11 years@Zoredache Yeah! I totally agree that. It would be helpful if you could let me know any other method is find the memory usage in percentage of various processes
-
-
Prakash over 11 yearsThanks for your inputs. I'm now taking the total system memory using the following command. Please let me know whether this is a right approach
free | grep 'buffers/cache' | awk '{printf "%.2f", (($NF-1)/($NF + $(NF-1)))*100}'
-
David Schwartz over 11 yearsWhat are you expecting this measurement to tell you? It will roughly tell you the percentage of physical memory used for things other than buffers and caches.