My website is very slow at some times of the day, and I'm on the quest of finding out why. I'm currently looking into Apache memory usage and I have 2 tools that are supposed to tell me how much RAM it is currently using:


curl -sL https://raw.githubusercontent.com/richardforth/apache2buddy/master/apache2buddy.pl | perl


apache2 is currently using 8849.18 MB of memory.

Then I have this command which uses ps:

ps -ylC apache2 --sort:rss | awk '{sum+=$8; ++n} END {print "Tot="sum"("n")";print "Avg="sum"/"n"="sum/n/1024"MB"}'



So according to this one liner, Apache2 is using about 9GB of RAM which matches Apache2Buddy result.

However, when I run htop this is what I get:

enter image description here

Total memory usage seems to be only 2.7GB. Why this huge gap in results?


The resident size includes shared pages: this includes shared libraries, and in this instance, the apache2 binary itself. The tools you’re using count all this shared memory once per process, but they are only present once in physical memory, so they use far less than you’d expect from adding the resident sizes.

To get a better idea of your processes’ real memory use, you’d have to look at /proc/<pid>/smaps; for each section described there, compare the Rss value and the Shared_... values. The kernel attempts to help you perform the calculation you’re interested in by calculating the per-process share of RSS, given as Pss.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.