top or htop? Which one lies?

Michael Hirsch mdhirsch at gmail.com
Tue Nov 10 16:30:00 UTC 2009


On Sun, Nov 8, 2009 at 5:29 AM, Mark Greenwood <fatgerman at ntlworld.com> 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

Actually, it agrees with both top and htop.  The first line tells you
about memory that is being used, just like top does.  The second line
tells you about how much used memory is free for use any time because
it is in the cache.  It says that you are actively using 289156 K of
memory which agrees with htop, and have 1771424 K of RAM ready for use
at any time it is needed.  Much of that RAM is currently being used in
the cache.

This same info is available from top.  If you subtract the amounts
listed as "buffered" and "cached" from the memory listed as "used"
you'll get the amount that is really available.

Michael




More information about the kubuntu-users mailing list