top or htop? Which one lies?

Nigel Ridley nigel at prayingforisrael.net
Sun Nov 8 15:49:03 UTC 2009


Mark Greenwood wrote:
> On Sunday 08 Nov 2009 08:55:08 Chris Jones wrote:
>> On 7 Nov 2009, at 10:54pm, Mark Greenwood wrote:
>>
>>> I hope someone on here can clear this up.
>>>
>>> According to top my RAM is as follows:
>>> 2060580k total,  1866728k used,  (which seems to me to be a  
>>> ridiculously enormous amount of RAM to run a bare desktop)
>>> According to htop (which I can't copy and paste)
>>> 269/2012MB (which seems to me to be a quite miraculously small  
>>> amount of RAM to run a bare desktop)
>>>
>>> Which one lies? And why the mahoosive discrepancy?
>> Neither. The difference is almost certainly the file cache.
>>
>> ram access is much faster that disk access, and your linux kernel  
>> knows this, so will use any 'unused' ram as a cache of all recently  
>> accessed files, just in case you need them again. This means most  
>> linux system will, after some time of usage, use what might seem like  
>> a surprising large amount of ram, even when you aren't actually  
>> running any applications.
>>
>> The confusion comes because some ways of monitoring memory usage  
>> include the file cache, others don't, since the ram used for the file  
>> cache is only used as long as it is not needed for any other usage. As  
>> soon as it is needed it will be given back. For me, the clearest  
>> utility is the command line 'free' command.
>>
>> So, my bet is your system is using 269MB of ram for real data storage,  
>> and the difference between this and 1867MB is the file cache...
>>
>> Chris
>>
>>
> Thanks Guys, I knew there were never any simple answers :)
> 
> 'free' gives me:
>              total       used       free     shared    buffers     cached
> Mem:       2060580     575336    1485244          0      27332     258848
> -/+ buffers/cache:     289156    1771424
> Swap:      6032368          0    6032368
> 
> Which appears to say I have 575336 (KB?) of RAM used, which is closer to what top is telling me today than to what htop is telling me. Another day, 3 different numbers :) Still at least you've cleared up my concern, I know what all that memory is being used for even if I don't know how much :-D
> 
> Cheers,
> 
> Mark
> 

Does this help:
nigel at nigel:~$ man free

FREE(1)                                                                Linux User's Manual 
                                                         FREE(1)

NAME
        free - Display amount of free and used memory in the system

SYNOPSIS
        free [-b | -k | -m | -g] [-o] [-s delay ] [-t] [-V]

DESCRIPTION
        free  displays  the  total  amount of free and used physical and swap memory in the 
system, as well as the buffers used by the kernel.  The shared memory
        column should be ignored; it is obsolete.

    Options
        The -b switch displays the amount of memory in bytes; the -k switch (set by default) 
displays it in kilobytes; the -m switch displays  it  in  megabytes;
        the -g switch displays it in gigabytes.

        The -t switch displays a line containing the totals.

        The -o switch disables the display of a "buffer adjusted" line.  If the -o option is not 
specified, free subtracts buffer memory from the used memory and
        adds it to the free memory reported.

        The -s switch activates continuous polling delay seconds apart. You may actually specify 
any floating point number  for  delay,  usleep(3)  is  used  for
        microsecond resolution delay times.

        The -V displays version information.

FILES
        /proc/meminfo
               memory information

SEE ALSO
        ps(1), slabtop(1), vmstat(8), top(1)

AUTHORS
        Written by Brian Edmonds.

        Send bug reports to <albert at users.sf.net>

Cohesive Systems                                                          20 Mar 1993 
                                                         FREE(1)
  Manual page free(1) line 1/47 (END)

or in short:
usage: free [-b|-k|-m|-g] [-l] [-o] [-t] [-s delay] [-c count] [-V]
   -b,-k,-m,-g show output in bytes, KB, MB, or GB
   -l show detailed low and high memory statistics
   -o use old format (no -/+buffers/cache line)
   -t display total for RAM + swap
   -s update every [delay] seconds
   -c update [count] times
   -V display version information and exit

Blessings,

Nigel




More information about the kubuntu-users mailing list