Hello,
I am trying to understand the VIRT field that shows in the TOP command output. I have a users application that appears to be leaking memory. I see that the field VIRT in the top output is showing 55.8g.
The question is where is that getting stored? The disk does not appear to have that much space used on it. An the system only has 24GB of ram. Is this a combination of RAM and DISK? Here is some examples.
ok...in that case, what is the real interpretation of virtual memory value shown with top command ?
man page says:
VIRT -- Virtual Image (kb)
The total amount of virtual memory used by the task. It includes all code, data and shared libraries plus pages that have been swapped out. (Note: you can define the STATSIZE=1 environment variable and
the VIRT will be calculated from the /proc/#/state VmSize field.)
You might be confusing with allocated memory.
Virtual memory as reported by top is the sum of memory present either on disk (mostly SWAP) or on RAM (RES).
My process certainly does not have 1027M resident. It doesn't have it on disk, either -- having not used any of that gig of ram, none of it is actually paged in, resident, or even backed in any form. Other systems might demand sufficient swap to back it but not Linux, which by default has virtual swap.
On a 64-bit system you can also inflate that value by plunking in your entire hard disk as a memory segment via mmap. 300G virtual. I suppose that would count as on disk though.
I stand corrected. Top correctly reports allocated memory including overcommitted one.
The top original manual page (top(1) - The UNIX and Linux Forums ) is confusing as this 1 GiB is not made of pages that have been swapped out but pages that were never used in in the first place.
Debian top manual page has this part corrected:
VIRT -- Virtual Image (kb)
The total amount of virtual memory used by the task. It includes all
code, data and shared libraries plus pages that have been swapped out
and pages that have been mapped but not used.
Linux doesn't have "virtual swap", but by default Linux does overcommit swap space - IMO a REALLY, REALLY BAD IDEA.
Because eventually it's going to get used. Which means the OOM killer is going to wake up and start randomly killing processes, aiming for heavy memory users.
You know - the processes like web servers and databases that are the actual reason you're using the computer in the first place.
"Works most of the time, then goes BOOM!" is an awfully low reliability standard.
That wouldn't usually need swap space because the backing store for the virtual memory would be your hard disk you mmap()'d, but you could probably map it in such a way that if you were to write to it, the changed pages would require swap backing. Maybe by mmap()'ing a read-only file descriptor read/write?
I've heard it referred to as virtual swap, and took it as another term for it...
A gridlocked system with insufficient RAM for kill -9 rameater is a tough nut to crack too, with the same fix as the oom-killer: "Don't let it happen". That's why there's programmable limits for these things.
I'll note that Linux systems tend to be poorly configured for swap in general, it's mostly considered a 'quick fix' for brief low-ram/high load conditions... It gets thrown on the same spindle and forgotten. So if it gets used at all, performance truly goes down the toilet.