LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-14-2010, 10:34 PM   #1
grob115
Member
 
Registered: Oct 2005
Posts: 540

Rep: Reputation: 32
Inconsistencies between top and free


Noticed a few discrepancies in the reports generated on my VPS:
Total Used Free
top command 262 132 129
free command 256 129 126

Not sure why but the top command gives an extra 3MB for both used and free memory.

Also, notice that there are a total of 29 rows of information returned by the top command for the httpd process. Each row indicates they took an average of 3.5-3.6%. Well, 29 * 3.5 = 101.5%. How can this be possible for two things: 1) The number greater than 100%. 2) The number doesn't correlate with the memory usage details returned by the top and free commands.

Puzzled.....

Code:
top - 17:44:47 up 14 days,  6:53,  1 user,  load average: 26.94, 10.80, 4.40
Tasks:  49 total,   1 running,  48 sleeping,   0 stopped,   0 zombie
Cpu(s):  8.6% us,  1.3% sy,  0.0% ni, 89.5% id,  0.5% wa,  0.0% hi,  0.0% si
Mem:    262144k total,   132572k used,   129572k free,        0k buffers
Swap:        0k total,        0k used,        0k free,        0k cached
 
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND            
    1 root      16   0  1668  608  528 S  0.0  0.2   0:00.63 init               
24474 root      16   0  1540  560  468 S  0.0  0.2   0:04.99 syslogd            
24489 root      16   0  4324 1048  748 S  0.0  0.4   0:09.09 sshd               
24497 root      15   0  2096  836  708 S  0.0  0.3   0:04.16 xinetd             
24528 root      18   0  2224 1124  964 S  0.0  0.4   0:00.00 mysqld_safe        
25606 mysql     15   0  189m  42m 5600 S  0.0 16.5 333:39.82 mysqld             
25630 42949672  15   0  3844 1004  724 S  0.0  0.4   0:00.47 nrpe               
25647 root      16   0  8456 2044  988 S  0.0  0.8   0:23.89 sendmail           
25655 smmsp     16   0  7492 1672  824 S  0.0  0.6   0:00.01 sendmail           
25660 root      22   0  2220 1072  940 S  0.0  0.4   0:00.00 vhost              
25662 root      24   0  7264 4192 2164 S  0.0  1.6   0:00.06 python             
25679 root      15   0  2504  928  544 S  0.0  0.4   0:00.06 crond              
25707 root      18   0  4364  800  560 S  0.0  0.3   0:00.00 saslauthd          
25708 root      18   0  4364  492  252 S  0.0  0.2   0:00.00 saslauthd          
25716 root      15   0 15180 2160 1476 S  0.0  0.8   0:18.32 monit              
29780 root      16   0 11712 4656 2596 S  0.0  1.8   0:15.09 snmpd              
17431 root      16   0  1588  440  380 S  0.0  0.2   0:00.00 cronolog           
17432 root      16   0  1588  452  380 S  0.0  0.2   0:00.44 cronolog           
 5311 apache    15   0 33300 9316 3812 S  0.0  3.6   0:02.81 httpd              
 5373 apache    16   0 33340 9332 3788 S  0.0  3.6   0:02.16 httpd              
 5381 apache    16   0 33304 9284 3776 S  0.0  3.5   0:02.06 httpd              
 5398 apache    16   0 33312 9332 3816 S  0.0  3.6   0:02.31 httpd              
 5408 apache    16   0 33312 9288 3772 S  0.0  3.5   0:01.46 httpd              
 5417 apache    16   0 33304 9256 3748 S  0.0  3.5   0:01.86 httpd              
 5422 apache    16   0 33328 9308 3776 S  0.0  3.6   0:00.64 httpd              
 5491 apache    15   0 33288 9280 3788 S  0.0  3.5   0:01.24 httpd              
 5493 apache    15   0 33316 9276 3760 S  0.0  3.5   0:00.93 httpd              
 5497 apache    16   0 33284 9264 3776 S  0.0  3.5   0:00.63 httpd              
 5498 apache    16   0 33312 9292 3776 S  0.0  3.5   0:01.11 httpd              
 5500 apache    16   0 33300 9288 3788 S  0.0  3.5   0:00.74 httpd              
 5501 apache    16   0 33256 9208 3748 S  0.0  3.5   0:00.22 httpd              
 5507 apache    15   0 33264 9212 3748 S  0.0  3.5   0:00.45 httpd              
 5508 apache    16   0 33256 9204 3748 S  0.0  3.5   0:00.22 httpd              
 5509 apache    16   0 33312 9376 3860 S  0.0  3.6   0:00.58 httpd              
 5510 apache    16   0 33312 9300 3788 S  0.0  3.5   0:00.76 httpd              
 5511 apache    15   0 33312 9296 3780 S  0.0  3.5   0:00.55 httpd              
 5512 apache    16   0 33336 9364 3828 S  0.0  3.6   0:00.82 httpd              
 5515 apache    15   0 33304 9292 3784 S  0.0  3.5   0:00.85 httpd              
 5516 apache    15   0 33280 9236 3756 S  0.0  3.5   0:00.52 httpd              
 5517 apache    16   0 33304 9304 3800 S  0.0  3.5   0:00.71 httpd              
 5518 apache    16   0 33332 9328 3792 S  0.0  3.6   0:00.61 httpd              
 5519 apache    15   0 33300 9300 3796 S  0.0  3.5   0:00.91 httpd              
 5520 apache    15   0 33280 9232 3748 S  0.0  3.5   0:00.65 httpd              
 5532 apache    15   0 33304 9308 3800 S  0.0  3.6   0:02.16 httpd              
 5533 apache    16   0 33324 9300 3772 S  0.0  3.5   0:00.95 httpd              
 5537 apache    15   0 33316 9292 3780 S  0.0  3.5   0:00.47 httpd              
 5570 apache    15   0 33280 9240 3764 S  0.0  3.5   0:00.32 httpd              
 5690 root      17   0  2220 1012  888 S  0.0  0.4   0:00.00 top.sh             
 5699 root      15   0  1940  904  716 R  0.0  0.3   0:00.00 top                
 
httpd total mem: 101.9%
             total       used       free     shared    buffers     cached
Mem:           256        129        126          0          0          0
-/+ buffers/cache:        129        126
Swap:            0          0          0
Total:         256        129        126

Last edited by grob115; 05-14-2010 at 10:52 PM.
 
Old 05-14-2010, 10:42 PM   #2
brucehinrichs
Member
 
Registered: Mar 2008
Location: US
Distribution: Debian Sid; Sabayon, UbuntuStudio, Slackware-multilib 13.1, Peppermint Ice, CentOS
Posts: 575

Rep: Reputation: 67
The output of top is very hard to read. Please post the output of commands in [CODE] tags for easier reading. It's the # toolbar button after you click 'Go Advanced'.
 
Old 05-14-2010, 11:12 PM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 14,832

Rep: Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820
Be better if you provide more detail on what you did. Let me guess you just dropped the last 3 digits from the top numbers - try dividing them by 1024 and see what happens.
Understanding kilo/mega/kibi/mebi-byte would be essential to reporting memory. Wikipedia has a good article.

Memory usage reported by top includes shared libraries. Correct memory accounting is non-trivial.
 
Old 05-15-2010, 10:22 AM   #4
grob115
Member
 
Registered: Oct 2005
Posts: 540

Original Poster
Rep: Reputation: 32
Wow it is indeed due to the 1024 vs 1000 issue. Thanks.
As for why the httpd process's memory% added up to more than 100% vs what both the top and free command indicates to have been consumed, any idea?

Both top and free indicates that there are almost 50% memory left. But httpd indicated by top suggests that the httpd alone has already taken all memory? Puzzled.
 
Old 05-15-2010, 10:49 AM   #5
divyashree
Senior Member
 
Registered: Apr 2007
Location: bbsr,orissa,India
Distribution: RHEL5 ,RHEL4,CENT OS5,FEDORA,UBUNTU
Posts: 1,362

Rep: Reputation: 135Reputation: 135
Quote:
Originally Posted by grob115 View Post
Noticed a few discrepancies in the reports generated on my VPS:
Total Used Free
top command 262 132 129
free command 256 129 126

Not sure why but the top command gives an extra 3MB for both used and free memory.

Also, notice that there are a total of 29 rows of information returned by the top command for the httpd process. Each row indicates they took an average of 3.5-3.6%. Well, 29 * 3.5 = 101.5%. How can this be possible for two things: 1) The number greater than 100%. 2) The number doesn't correlate with the memory usage details returned by the top and free commands.

Puzzled.....

Code:
top - 17:44:47 up 14 days,  6:53,  1 user,  load average: 26.94, 10.80, 4.40
Tasks:  49 total,   1 running,  48 sleeping,   0 stopped,   0 zombie
Cpu(s):  8.6% us,  1.3% sy,  0.0% ni, 89.5% id,  0.5% wa,  0.0% hi,  0.0% si
Mem:    262144k total,   132572k used,   129572k free,        0k buffers
Swap:        0k total,        0k used,        0k free,        0k cached
 
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND            
    1 root      16   0  1668  608  528 S  0.0  0.2   0:00.63 init               
24474 root      16   0  1540  560  468 S  0.0  0.2   0:04.99 syslogd            
24489 root      16   0  4324 1048  748 S  0.0  0.4   0:09.09 sshd               
24497 root      15   0  2096  836  708 S  0.0  0.3   0:04.16 xinetd             
24528 root      18   0  2224 1124  964 S  0.0  0.4   0:00.00 mysqld_safe        
25606 mysql     15   0  189m  42m 5600 S  0.0 16.5 333:39.82 mysqld             
25630 42949672  15   0  3844 1004  724 S  0.0  0.4   0:00.47 nrpe               
25647 root      16   0  8456 2044  988 S  0.0  0.8   0:23.89 sendmail           
25655 smmsp     16   0  7492 1672  824 S  0.0  0.6   0:00.01 sendmail           
25660 root      22   0  2220 1072  940 S  0.0  0.4   0:00.00 vhost              
25662 root      24   0  7264 4192 2164 S  0.0  1.6   0:00.06 python             
25679 root      15   0  2504  928  544 S  0.0  0.4   0:00.06 crond              
25707 root      18   0  4364  800  560 S  0.0  0.3   0:00.00 saslauthd          
25708 root      18   0  4364  492  252 S  0.0  0.2   0:00.00 saslauthd          
25716 root      15   0 15180 2160 1476 S  0.0  0.8   0:18.32 monit              
29780 root      16   0 11712 4656 2596 S  0.0  1.8   0:15.09 snmpd              
17431 root      16   0  1588  440  380 S  0.0  0.2   0:00.00 cronolog           
17432 root      16   0  1588  452  380 S  0.0  0.2   0:00.44 cronolog           
 5311 apache    15   0 33300 9316 3812 S  0.0  3.6   0:02.81 httpd              
 5373 apache    16   0 33340 9332 3788 S  0.0  3.6   0:02.16 httpd              
 5381 apache    16   0 33304 9284 3776 S  0.0  3.5   0:02.06 httpd              
 5398 apache    16   0 33312 9332 3816 S  0.0  3.6   0:02.31 httpd              
 5408 apache    16   0 33312 9288 3772 S  0.0  3.5   0:01.46 httpd              
 5417 apache    16   0 33304 9256 3748 S  0.0  3.5   0:01.86 httpd              
 5422 apache    16   0 33328 9308 3776 S  0.0  3.6   0:00.64 httpd              
 5491 apache    15   0 33288 9280 3788 S  0.0  3.5   0:01.24 httpd              
 5493 apache    15   0 33316 9276 3760 S  0.0  3.5   0:00.93 httpd              
 5497 apache    16   0 33284 9264 3776 S  0.0  3.5   0:00.63 httpd              
 5498 apache    16   0 33312 9292 3776 S  0.0  3.5   0:01.11 httpd              
 5500 apache    16   0 33300 9288 3788 S  0.0  3.5   0:00.74 httpd              
 5501 apache    16   0 33256 9208 3748 S  0.0  3.5   0:00.22 httpd              
 5507 apache    15   0 33264 9212 3748 S  0.0  3.5   0:00.45 httpd              
 5508 apache    16   0 33256 9204 3748 S  0.0  3.5   0:00.22 httpd              
 5509 apache    16   0 33312 9376 3860 S  0.0  3.6   0:00.58 httpd              
 5510 apache    16   0 33312 9300 3788 S  0.0  3.5   0:00.76 httpd              
 5511 apache    15   0 33312 9296 3780 S  0.0  3.5   0:00.55 httpd              
 5512 apache    16   0 33336 9364 3828 S  0.0  3.6   0:00.82 httpd              
 5515 apache    15   0 33304 9292 3784 S  0.0  3.5   0:00.85 httpd              
 5516 apache    15   0 33280 9236 3756 S  0.0  3.5   0:00.52 httpd              
 5517 apache    16   0 33304 9304 3800 S  0.0  3.5   0:00.71 httpd              
 5518 apache    16   0 33332 9328 3792 S  0.0  3.6   0:00.61 httpd              
 5519 apache    15   0 33300 9300 3796 S  0.0  3.5   0:00.91 httpd              
 5520 apache    15   0 33280 9232 3748 S  0.0  3.5   0:00.65 httpd              
 5532 apache    15   0 33304 9308 3800 S  0.0  3.6   0:02.16 httpd              
 5533 apache    16   0 33324 9300 3772 S  0.0  3.5   0:00.95 httpd              
 5537 apache    15   0 33316 9292 3780 S  0.0  3.5   0:00.47 httpd              
 5570 apache    15   0 33280 9240 3764 S  0.0  3.5   0:00.32 httpd              
 5690 root      17   0  2220 1012  888 S  0.0  0.4   0:00.00 top.sh             
 5699 root      15   0  1940  904  716 R  0.0  0.3   0:00.00 top                
 
httpd total mem: 101.9%
             total       used       free     shared    buffers     cached
Mem:           256        129        126          0          0          0
-/+ buffers/cache:        129        126
Swap:            0          0          0
Total:         256        129        126
Your concept is wrong .

What %MEM indiacates ?

It indicates the task’s currently used share of available physical memory.

Means suppose your MEM is 100 MB and the first task is taking 5% of memory .Now the available memory is 95 MB .Now anothe task is taking 5% ,i.e. not 5% of 100 MB but 5% available memory that is of 95 MB = 4.75 MB .

Now calculate and post , how your memory usage is above 100% ?
 
Old 05-15-2010, 08:32 PM   #6
grob115
Member
 
Registered: Oct 2005
Posts: 540

Original Poster
Rep: Reputation: 32
Quote:
Means suppose your MEM is 100 MB and the first task is taking 5% of memory .Now the available memory is 95 MB .Now anothe task is taking 5% ,i.e. not 5% of 100 MB but 5% available memory that is of 95 MB = 4.75 MB .
Thanks. This is something that I'll never find out from the books. It's a bit too intricate to be described in the books. So thanks for pointing this out.

Can you kindly let me know how did you come to know about this? You must have some great references.

Nevertheless, this is some messed up way of displaying what memory usage a process is consuming. Why would anyone be interested in knowing how much remaining memory was used? The information can be rather unworthy. Afterall, how do we know in which sequence is the memory calculated.
 
Old 05-15-2010, 10:31 PM   #7
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 14,832

Rep: Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820
I doubt that explanation - top just reads the various entries in /proc.
As I said, the memory reported for each process is not just that processes usage. Have a read of this - it discusses "ps", but is equally applicable to "top".
 
Old 05-16-2010, 02:34 AM   #8
divyashree
Senior Member
 
Registered: Apr 2007
Location: bbsr,orissa,India
Distribution: RHEL5 ,RHEL4,CENT OS5,FEDORA,UBUNTU
Posts: 1,362

Rep: Reputation: 135Reputation: 135
Quote:
Originally Posted by grob115 View Post
Thanks. This is something that I'll never find out from the books. It's a bit too intricate to be described in the books. So thanks for pointing this out.

Can you kindly let me know how did you come to know about this? You must have some great references.

Nevertheless, this is some messed up way of displaying what memory usage a process is consuming. Why would anyone be interested in knowing how much remaining memory was used? The information can be rather unworthy. Afterall, how do we know in which sequence is the memory calculated.
You are welcome .

We dont have to bother about the sequence, its the work of OS , which task to start first and assign memory according to the need of that process . You can get them by sequence of PID .
 
Old 05-16-2010, 02:41 AM   #9
grob115
Member
 
Registered: Oct 2005
Posts: 540

Original Poster
Rep: Reputation: 32
syg00, true guru! I wonder if the same is true on what's reported by Task Manager or WMI in Windows.
 
Old 05-16-2010, 02:43 AM   #10
grob115
Member
 
Registered: Oct 2005
Posts: 540

Original Poster
Rep: Reputation: 32
Quote:
We dont have to bother about the sequence, its the work of OS , which task to start first and assign memory according to the need of that process . You can get them by sequence of PID .
Actually, just finished reading the article linked by syg00. I think that's the proper actual workings in explaining why all the httpd processes displayed by ps exceeds 100% of memory. Can you please take a look. It's a good read.
 
Old 05-16-2010, 07:35 AM   #11
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181
Quote:
Originally Posted by divyashree View Post
Means suppose your MEM is 100 MB and the first task is taking 5% of memory .Now the available memory is 95 MB .Now anothe task is taking 5% ,i.e. not 5% of 100 MB but 5% available memory that is of 95 MB = 4.75 MB .
Quote:
Originally Posted by syg00 View Post
I doubt that explanation
Don't leave the OP in doubt by being too polite. divyashree's explanation was total nonsense (sorry I don't know a polite way to say that).

Quote:
Originally Posted by grob115 View Post
just finished reading the article linked by syg00. I think that's the proper actual workings in explaining why all the httpd processes displayed by ps exceeds 100% of memory.
Correct.
 
Old 05-16-2010, 10:09 AM   #12
grob115
Member
 
Registered: Oct 2005
Posts: 540

Original Poster
Rep: Reputation: 32
Quote:
Don't leave the OP in doubt by being too polite. divyashree's explanation was total nonsense (sorry I don't know a polite way to say that).
divyashree, seriously you should read that link about how ps displays the memory and how you can use pmap to see what's happening. It makes no sense for a kernel programmer to add in the additional consideration of how much memory has been used and use the remaining memory for the calculation. The resulting figure will mislead the user of the output and add additional coding logic. So why bother.

Just out of curiosity, does Solaris have an implementation of the WBEM service like the Windows WMI? I've been using Solaris 5.8 and 5.10 but have never seen any WMI like feature whether through command line or GUI. Well we don't use GUI... just putty. But also not awared of such thing being available via CLI. Is there such thing available?
 
Old 05-16-2010, 11:37 AM   #13
avee137
Member
 
Registered: Apr 2010
Location: bangalore,india
Distribution: ubuntu 9.10,CentOS 5
Posts: 120

Rep: Reputation: 16
Yeah,above discussion is correct about psas it displays total memory used by a process which includes shared libraries loaded in memory,which are simultaneously used by other processes too!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
vmstat and top shows wrong free memory ? czezz Solaris / OpenSolaris 15 02-05-2010 09:02 AM
[SOLVED] cpanel and top give different amounts of RAM free qwertyjjj Linux - Newbie 3 08-20-2009 07:56 PM
What does free memory mean in top? blittrell Linux - Newbie 3 08-05-2009 01:10 PM
LXer: Top 10 free Linux 3D games LXer Syndicated Linux News 0 12-10-2007 10:10 AM
505/512 used? free/top reading. nixel Slackware 2 05-13-2004 01:49 AM


All times are GMT -5. The time now is 05:56 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration