Virtual memory on Linux doesn't add up?

4

1

I was looking at System Monitor on Linux and noticed that Firefox is using 441 MB of memory, and several other applications are using 274, 257, 232, etc (adding up to over 3 GB of virtual memory). So I switch over to the Resources tab, and it says I'm using 462 MB of memory and not touching swap. I'm confused. What does the virtual memory amount mean then if the programs aren't actually using it. I was thinking maybe memory they've requested but aren't using, but how would the OS know that? I can't think of any "I might need this much memory in the future" function..

Brendan Long

Posted 2010-04-04T23:12:26.113

Reputation: 1 728

Extra credit reading and here.

– Paused until further notice. – 2010-04-05T00:46:53.760

I know how virtual memory works, my question is why does the "virtual memory" size listed not add up (not even close)? My (apparently naive) assumption was that if it said I was using 3 GB of virtual memory, then some combination of memory usage and swap usage should add up to 3 GB.. – Brendan Long – 2010-04-05T02:16:19.600

Is "virtual memory usage" listing cached files? – Brendan Long – 2010-04-05T17:09:21.857

Answers

1

First off, shared memory is not really (?) counted correctly by top. Second, yes, a program asks for rights to memory, and then uses it, but it may never touch any, and the OS knows that. No problem at all for every app to have allocated all the ram and swap, as long as they don't try to use it :-D > We are not in a Mac OS Classic world (in fact, that is how the old Ram Doubler worked, letting you use the difference between allocated and used).

Ronald Pottol

Posted 2010-04-04T23:12:26.113

Reputation: 641

What do you mean by asking for rights to memory and never using it? Like if program uses malloc() but never accesses the pointer, the OS can tell? – Brendan Long – 2010-04-05T02:17:18.243

1Exactly. The program is in user space, and cannot do anything with out permission (that's what the pmmu is for). So yes, the OS tracks that. Back in the days when most of us didn't have systems that would take a gig of RAM, there were a few apps (like object databases) that allocated 3GB of address space, but used only a little of that. – Ronald Pottol – 2010-04-05T20:39:07.487

0

Have you ever tried to fire "vmstat"?? iff not help yourself and fire it from the command line like this :

vmstat

And please RTFM for lessen your owes. I have seen couple of interesting flags there in the man page...which might help you to understand.Plus iff you are really concerned about firefox memory consumption.. then have at look at this solution..here

http://unixbhaskar.blogspot.com/2009/10/firefox-saga-on-opensuse.html

and here

http://unixbhaskar.blogspot.com/2010/02/cleanup-firefox-clogging-by-pruning-its.html

And iff you really interested know the Linux internals for dynamic memory allocation read here

http://www.ibm.com/developerworks/linux/library/l-linux-slab-allocator/index.html

And use one binary called " pmap"..use it like this pmap (process-id) to get to know how that particular application using memory inside.To know more about "man pmap".

I hope I have given you much insight get on.

Cheers!

unixbhaskar

Posted 2010-04-04T23:12:26.113

Reputation: 139

I'm not concerned about Firefox's memory consumption. It's obviously not using that much, since the entire computer was only using 500 MB of memory. – Brendan Long – 2010-04-05T17:05:42.160