9

When I run htop (on OS X 10.6.8), I see something like this :

  1  [|||||||                    20.0%]     Tasks: 70 total, 0 running
  2  [|||                         7.2%]     Load average: 1.11 0.79 0.64 
  3  [|||||||||||||||||||||||||||81.3%]     Uptime: 00:30:42
  4  [||                          5.8%]
  Mem[|||||||||||||||||||||3872/4096MB]
  Swp[                           0/0MB]

  PID USER     PRI  NI  VIRT   RES   SHR S CPU% MEM%   TIME+  Command                                                                      
  284 501       57   0 15.3G 1064M     0 S  0.0  6.5  0:01.26 /Applications/Firefox.app/Contents/MacOS/firefox -psn_0_90134                
  437 501       57   0 14.8G  785M     0 S  0.0  4.8  0:00.18 /Applications/Thunderbird.app/Contents/MacOS/thunderbird -psn_0_114716
  428 501       63   0 12.8G  351M     0 S  1.0  2.1  0:00.51 /Applications/Firefox.app/Contents/MacOS/plugin-container.app/Contents/MacOS/
  696 501       63   0 11.7G  175M     0 S  0.0  1.1  0:00.02 /System/Library/Frameworks/QuickLook.framework/Resources/quicklookd.app/Conte
   38 0         33   0 11.1G  422M     0 S  0.0  2.6  0:00.59 /System/Library/Frameworks/CoreServices.framework/Frameworks/Metadata.framewo
  183 501       48   0 10.9G  137M     0 S  0.0  0.8  0:00.03 /System/Library/CoreServices/Finder.app/Contents/MacOS/Finder

How can I have Processes using Gigabytes of VIRT memory and still 0MB of Swap used ?

Weier
  • 193
  • 1
  • 1
  • 4

2 Answers2

8

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.

geocar
  • 2,307
  • 14
  • 10
  • Well I think this explains why this amount of VIRT memory is huge. Still I don't understand why the swap used is said to be 0/ **0** MB, as @journeyman mentionned. Is this something specific to OS X ? – Weier Sep 30 '12 at 19:58
  • I'm sorry I missed that part. It's probably something specific to OSX. – geocar Sep 30 '12 at 20:14
3

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

Journeyman Geek
  • 6,969
  • 3
  • 31
  • 49
  • Well, I might not have understood the meaning of the "VIRT" column then. I thought this was the amount of virtual memory required by each process, which was either in RAM or on some swap dedicated zone on disk. What's wrong ? – Weier Sep 30 '12 at 09:30
  • Hence my suggestion you check with other tools - that dosen't look quite right, as does the total lack of shared memory between things. – Journeyman Geek Sep 30 '12 at 09:36