Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I went through this article, which explains various methods for checking your RAM usage. However, I can't reconcile the different methods and don't know which one is correct.

When I first login, I'm greeted with a screen like this:

  System information as of Sun Apr 28 21:46:58 UTC 2013

  System load:  0.0               Processes:           76
  Usage of /:   15.6% of 7.87GB   Users logged in:     1
  Memory usage: 41%               IP address for eth0: 
  Swap usage:   0%

This suggests to me that I am using 41% of my RAM, which seems quite high since the server isn't doing much. Or does that number refer to something besides RAM?

Next I try the free -m method:

ubuntu@ip-:~$ free -m
             total       used       free     shared    buffers     cached
Mem:           590        513         76          0         67        315
-/+ buffers/cache:        130        459
Swap:            0          0          0

According to the explanatory graphic in the article, this implies I have 130MB of used RAM and 459MB of free RAM, which suggests I'm using about 22% of my RAM.

Next I run top:

top - 22:14:48 up 195 days, 21:30,  2 users,  load average: 0.00, 0.01, 0.05
Tasks:  77 total,   1 running,  76 sleeping,   0 stopped,   0 zombie
Cpu(s):  1.3%us,  0.3%sy,  0.0%ni, 97.7%id,  0.7%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:    604376k total,   525692k used,    78684k free,    69124k buffers
Swap:        0k total,        0k used,        0k free,   322740k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND            
    1 root      20   0 24332 1864  976 S  0.0  0.3   0:08.75 init               
    2 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kthreadd     

This is the most confusing, as the summary shows me using 525MG of 604M total, and yet when is use the "m" interactive command to sort by top memory the top process is only using 0.3% of the memory???

Finally, the ps command seems to show very little memory usage as well:

root@ip-:/home/ubuntu# ps -o command,rss
COMMAND                       RSS
ps -o command,rss             788
sudo su root                 1764
su root                      1404
bash                         2132

I would love for someone to correct whatever misunderstandings I have that are creating these apparent conflicts.


EDIT for Rahul

Ouput of cat /proc/meminfo:

MemTotal:         604376 kB
MemFree:          157564 kB
Buffers:           49640 kB
Cached:           231376 kB
SwapCached:            0 kB
Active:           290040 kB
Inactive:          97772 kB
Active(anon):     107672 kB
Inactive(anon):     4844 kB
Active(file):     182368 kB
Inactive(file):    92928 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:             0 kB
SwapFree:              0 kB
Dirty:                52 kB
Writeback:             0 kB
AnonPages:        106836 kB
Mapped:            22920 kB
Shmem:              5712 kB
Slab:              42032 kB
SReclaimable:      34016 kB
SUnreclaim:         8016 kB
KernelStack:         688 kB
PageTables:         3584 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:      302188 kB
Committed_AS:     242768 kB
VmallocTotal:   34359738367 kB
VmallocUsed:        7152 kB
VmallocChunk:   34359729008 kB
HardwareCorrupted:     0 kB
AnonHugePages:         0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
DirectMap4k:      637952 kB
DirectMap2M:           0 kB
share|improve this question
#1) The command in top to sort by memory isn't m, it's M. #2) To see all processes try ** ps ax -o command,rss**; what you ran just shows your own ones. –  tink Apr 29 '13 at 1:47
Please also update us output of cat /proc/meminfo –  Rahul Patil Apr 29 '13 at 2:04
linuxatemyram.com –  Michael Hampton Apr 29 '13 at 3:35
@tink, thanks for that explanation. I tried ps ax -o rss | awk '{ sum+=$1} END {print sum}' just now and 153156. –  Jonah Apr 29 '13 at 3:54
@RahulPatil, OP updated. Note that the processes running may be slightly different from the original numbers, but shouldn't be that far off. Also, the result I got for you seems not to match the result I got for tink in the comment above this. Those were taken just a couple minutes apart. –  Jonah Apr 29 '13 at 3:59
show 4 more comments

3 Answers

up vote 8 down vote accepted

You just need to understand Memory Concept

As per your Output Of /proc/meminfo , You just need to Notice below things :

Buffers :- A buffer is something that has yet to be "written" to disk. It represents how much RAM is dedicated to cache disk block. "Cached" is similar to "Buffers", only this time it caches pages from file reading

Cached :- A cache is something that has been "read" from the disk and stored for later use. Generally, you can consider cache area as another "free" RAM since it will be shrunk gradually if the application demands more memory.

It is enough to understand that both "buffers" and "Cached" represent the size of system cache. They dynamically grow or shrink as requested by internal Linux kernel mechanism.

at Webhosting they do cache clear using below cmd: (mostly configured in cron):

sync && echo 3 > /proc/sys/vm/drop_caches

Quote Link

EDIT for one more requirement i.e per user memory usage


printf "%-10s%-10s\n" User MemUsage

while read u m
        [[ $old_user != $u ]] && { printf "%-10s%-0.1f\n" $old_user $total_mem; total_mem=0; }
        total_mem=$(echo $m + $total_mem | bc);

done < <(ps --no-headers -eo user,%mem| sort -k1)


Please check with above script and let me know, if it showing properly or not.

share|improve this answer
Thanks Rahul. One final question. Since free -m does not provide a way to view memory used per user, what is an accurate way to determine how much real RAM is being consumed by a particular user? This comes up when monitoring your own memory use on a shared server, for example. –  Jonah Apr 29 '13 at 6:34
@Jonah I have updated.. please check and let me know –  Rahul Patil Apr 29 '13 at 7:13
that script is not working as expected.. but I'm trying will update soon –  Rahul Patil Apr 29 '13 at 8:28
@Jonah thanks for accepting my ans.. but real thanks for MichaelHampton... –  Rahul Patil Apr 29 '13 at 12:37
add comment

Good answer @RahulPatil.

Another point to consider about ps or top is as follows

This tool [exmap] is more accurate than ps or top because it takes into account shared libraries in use by multiple applications. For example, if two applications are using the same shared library, which takes up 1MB of memory, ps will show both apps using 1MB of extra memory, whereas exmap more correctly shows each app using 500 KB. This greater accuracy is particularly important for assessing desktop environments such as KDE and GNOME, which make very heavy use of libraries shared between applications.

Via ibm/developerworks/linux_memory

Since your question refers to a headless server - I am not sure how much double reporting top or ps will actually have.

share|improve this answer
add comment

I fear we may be overlooking the obvious because it's such an "of course" for most of us.

Jonah, forgive me if I'm wrong, but your questions sound like you may not have realized that all of these values, CPU usage in particular, will normally vary quite a lot from second to second.

CPU usage may go from single digits to 100% instantly as a new process is started but quickly (hopefully) fall back to the sub-50% range.

Memory usage changes more slowly but there, Linux tries to use memory not in active use by running processes for "caching" disk accesses. For example, it tries to predict what will need to be read from disk next, such as maybe the rest of a large file after a portion has been read, and preload it in cache. Some of the memory usage values include both the memory used by processes as well as the memory used for caching. On a system that's been running awhile, the two combined will probably be 80-90% or more.

Consider too that the process you run to show the usage, such as top, uses CPU and memory as well. If you wrote a script with a loop to report CPU usage continuously, it would almost surely always show 100% because the act of reporting the usage itself (without some sleep delays thrown in) uses all the CPU.

share|improve this answer
Doc, thanks for the thought, but this was not the issue –  Jonah May 3 '13 at 11:26
add comment

Your Answer


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

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