I want to understand the memory usage metrics shown in htop in more detail.
My current understanding is this:
VIRT(virtual memory) - This value shows the quantity of virtual memory used. Since all memory is virtualized, I would assume this is the total memory usage of a process, calculated from the number of allocated virtual pages. These pages might be resident in physical memory, or might be swapped out.RES(resident virtual memory) - This value is the quantity of virtual memory used, but only counting the pages which are physically present in RAM. It is always less than or equal toVIRT.SHR- This is where I get a bit confused. There are two possibilities for a virtual page. It is either present in physical memory, or not (because it has been swapped out/paged out).SHRseems to be unrelated. I am somewhat guessing here - I have read the documentation, but the interpretation isn't totally obvious to me. This is some kind of shared memory metric. I would guess that it is the quantity ofVIRTwhich is shared with other processes.
The reason I find this a bit confusing is that RES and SHR seem to be two different kinds of subtypes of VIRT. RES cannot be greater than VIRT. SHR cannot be greater than VIRT.
The interpretation of RES seems sensible - it tells us something about physical memory usage.
SHR doesn't have such a simple interpretation. It just means "shared". It seems like we don't know or can't know if this memory is physically paged in RAM or swapped out. So it seems like a bit of a weird or difficult to understand metric.
RES= you will get this much physical memory back.VIRT= says nothing about how much memory (physical or swap space) you will get back,SHR= says something about the amount you definitely won't get back fromVIRTSHRback (if the process is the only user of a shared memory mapping, it will be freed when the process exits); butSHRis similar toVIRT, it reflects mappings rather than actual physical use.USS(effectively "nonshared resident") andPSS(effectively "nonshared resident, plus shared divided by number of sharing processes"). However, these apparently rely on something called "smaps", which is expensive to compute and requires root to see stats across users. And while mytophas them, I don't know what htop has. (There is a correspondingRSSthat is "REScomputed from smaps", but given the limitations it seems much less useful thanRES.)