Quote:
Originally Posted by YellowSnowIsBad
I was under the impression that virtual memory and swap are synonymous;
|
Not for any reasonable definition of virtual memory.
Quote:
I have an odd issue with HTOP where the swap space used is only a few MB but the virtual memory in use is well over 10GB. See attachment!
|
If I'm reading that right, the VIRT size of a single process is 10.6GB and you have other processes with large VIRT.
So with your incorrect (common error) assumptions about what virtual memory is, that would obviously not fit.
VIRT counts all mapped portions of the process's address space. The parts of VIRT that is in swap space are only anonymous memory and generally only the part of anonymous memory that is not in that process's RES nor in the system cache.
RES is the portion of VIRT that is physically mapped to ram. Note that VIRT represents logical mappings that page by page might or might not be physically mapped at any given moment.
Logical anonymous mappings are used for the process's stack and heap and any pages of static or global variables that have been modified from compile time initialized values.
But anonymous memory for a process may be much smaller than its logical anonymous mappings. That is primarily because of "demand zero" mapping. A process typically asks for heap in far bigger chunks than it needs at the moment. Heap that has been requested but not yet used exists within VIRT as a demand zero mapping. There are other reasons for demand zero mappings, but heap is typically the big one. The pages represented by demand zero mappings don't physically exist anywhere.
Processes also have non anonymous memory. That is always included in VIRT. Any of that in physical ram it is either in the process's RES or the system wide cache. But when it is not in ram, it is also not in swap. That is a key fact missed by most people who misunderstand Linux swap. The common use for non anonymous memory is the code loaded from the executable file and .so files. So that tends to be a large fraction of VIRT when VIRT is small, but a small fraction when VIRT is large. Large VIRT usually means a lot of anonymous memory. But that isn't always the case. A program could directly map data files creating an enormous non anonymous use of VIRT.
Quote:
Originally Posted by YellowSnowIsBad
Well I read that on the HTOP website; but 11MB/10GB+ is a rather large discrepancy. What's the point in even providing functionality to calculate swap space if it is so far off?
|
Read what on the HTOP website?
Your misunderstanding of VIRT and swap seems to be larger than the typical, since you don't seem to be including RES.
Most people confused by this, understand that RES is a part of VIRT that is in physical ram. And this process's share of the system wide swap usage is a portion of VIRT that is not in physical ram. So they expect those two things to add up to VIRT, because they don't know how many other places parts of VIRT might be.