How is htop "Swp" calculated?
VIRT
does not have anything to do with used memory (virtual or otherwise), but with used address-space, which is not as related as you might think.
Modern operating systems (including OSX) have a feature called demand paging which works by telling the operating system to map a certain region of virtual address space to a file (such as a shared library/DLL). It is only when a program tries to read those virtual addresses that the file is loaded into memory.
If those shared libraries are in fact shared, then the operating system will actually share the physical memory across multiple processes; That is to say that a great deal of those tens of gigabytes are not only file-backed libraries, but also the same file-backed libraries.
Further, if scratch memory is required (for data; settings, bitmaps, sounds, etc), and there aren't any physical pages unused, the operating system will actually discard the contents of these file-backed regions and give them to your application. If those pages are needed again, the operating system can simply reload them from disk.
Swap (SWP
) is a special file-backed region for that scratch memory. Creating swap-space will allow the operating system to move that scratch memory to the disk instead of (utilised by more running process) shared libraries, generally improve performance, and perhaps most surprisingly of all, produce less swapping than having no swap space at all.
You still have memory to spare. The system isn't swapping out cause it hasn't needed to yet... but then again, I notice something odd - from what I can tell, you have no swap space set up. On one of my (linux) systems it reads
CPU[|||||||||||||||||||| 63.2%] Tasks: 89, 114 thr; 1 running
Mem[||||||||||||||||| 167/1001MB] Load average: 0.19 1.13 0.75
Swp[ 0/1021MB] Uptime: 00:06:54
for example.
I'm not sure if this is a quirk of OS X or some other issue - you might want to check this with activity monitor