Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

The more I read, the more confused I get.. I want to generate a list of processes and their memory consumption (physical + virtual).

So far, this is what I have done:

  • I take the VSZ of each process, and multiplying it with 1024 (into bytes)
  • I take the RSS, and does the same
  • Then I subtract the VSZ with the RSS, since VSZ contains RSS already

Instead of showing all the threads, I sum up the processes with the same user+comm.

This gives me a list similar to this:

MEM        VMEM       PMEM        User       Command
16.27 GB   15.47 GB   811.73 MB   apache     httpd          
2.37 GB    2.19 GB    186.12 MB   mysql      mysqld         
372.99 MB  320.18 MB  52.81 MB    memcached  memcached      
985.78 MB  954.60 MB  31.18 MB    root       httpd  

The MEM column is basically VMEM (VSZ - RSS) + PMEM (the RSS).

But I was a bit baffled by this.. Apache spawns ~ 10 threads, and this list says it is consuming 16 GB of memory. The hard drive is only ~14 GB, and we have 8 GB of RAM.

So then I thought: "Even though the VSZ is different for each thread, perhaps it is sort off a value that is absolute for every thread". So if I took the VSZ column and subtracted each thread's RSS, I got this:

MEM        VMEM       PMEM        User       Command
1.38 GB    680.54 MB  737.68 MB   apache     httpd          
2.55 GB    2.37 GB    186.09 MB   mysql      mysqld         
425.80 MB  372.99 MB  52.81 MB    memcached  memcached      
1016.96 MB 985.78 MB  31.18 MB    root       httpd  

And I though: "Well, this must be true!".

Question is, am I right? I just cannot believe that apache is consuming 16 GB of memory.

Am I doing something horrible wrong here?

Updated: I am getting the same values when using top. It's also a CentOS machine.

share|improve this question
    
Yes, you are doing something wrong. What is reported is the size of memory that the process has available (RSS), which includes pieces shared with other processes (shared libraries, others). The virtual size is the address space that the process can access, parts of that might not be allocated at all (think "here I have 20 more pages, all zero, which I haven't touched"). The numbers given are for one process only, can't just add them up. –  vonbrand Feb 4 '13 at 18:02
    
Hm, okay. Thank you for your answer! I have setup a NewRelic account to monitor our server, and they are reporting that httpd is using ~800 MB (close to my PMEM). They have added every process of "httpd" up.. Is there another way of doing this then? –  DavidS Feb 4 '13 at 18:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.