Sum of memory of few processes in top is greater than 100%

5,918

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.

Share:
5,918

Related videos on Youtube

Prakash
Author by

Prakash

Updated on September 18, 2022

Comments

  • Prakash
    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
      Zoredache over 11 years
      Adding up percentages is almost always the wrong way to do things.
    • Prakash
      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
    Prakash over 11 years
    Thanks 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
    David Schwartz over 11 years
    What 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.