LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Inconsistencies between top and free (https://www.linuxquestions.org/questions/linux-newbie-8/inconsistencies-between-top-and-free-807929/)

grob115 05-14-2010 09:34 PM

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


brucehinrichs 05-14-2010 09:42 PM

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'.

syg00 05-14-2010 10:12 PM

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.

grob115 05-15-2010 09:22 AM

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.

divyashree 05-15-2010 09:49 AM

Quote:

Originally Posted by grob115 (Post 3969071)
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% ?

grob115 05-15-2010 07:32 PM

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.

syg00 05-15-2010 09:31 PM

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".

divyashree 05-16-2010 01:34 AM

Quote:

Originally Posted by grob115 (Post 3970128)
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 .

grob115 05-16-2010 01:41 AM

syg00, true guru! I wonder if the same is true on what's reported by Task Manager or WMI in Windows.

grob115 05-16-2010 01:43 AM

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.

johnsfine 05-16-2010 06:35 AM

Quote:

Originally Posted by divyashree (Post 3969609)
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 (Post 3970171)
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 (Post 3970284)
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.

grob115 05-16-2010 09:09 AM

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?

avee137 05-16-2010 10:37 AM

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!


All times are GMT -5. The time now is 03:47 PM.