How to calculate Virtual Memory Size in Mavericks
Solution 1:
You can use vm_stat
and sysctl
terminal commands. Although there was no straightforward way or documentation on how to extract the new attributes from these commands, we had to do some trial and error till we discovered the relations between parameters in the commands and the attribute we need to calculate.
The Steps are as the following:
- Run
vm_stat
- Run "sysctl hw.memsize" and "sysctl vm.swapusage".
- The relationship between Memory usage which appears in Activity Monitor and previous commands are described in How to calc Memory usage in Mavericks programmatically.
Sample output from vm_stat
:
Mach Virtual Memory Statistics: (page size of 4096 bytes)
Pages free: 24428.
Pages active: 1039653.
Pages inactive: 626002.
Pages speculative: 184530.
Pages throttled: 0.
Pages wired down: 156244.
Pages purgeable: 9429.
"Translation faults": 14335334.
Pages copy-on-write: 557301.
Pages zero filled: 5682527.
Pages reactivated: 74.
Pages purged: 52633.
File-backed pages: 660167.
Anonymous pages: 1190018.
Pages stored in compressor: 644.
Pages occupied by compressor: 603.
Decompressions: 18.
Compressions: 859.
Pageins: 253589.
Pageouts: 0.
Swapins: 0.
Swapouts: 0.
Solution 2:
I believe between top
and vm_stat
you could get most of that output, though in a less legible form. (Why do you want to read it from the terminal, curiosity?)
top
has most of the physical and virtual memory stats, but vm_stats
has the amount of compressed, and they both have swapping, though thanks to compression that is low.
App Memory and Filecache specifics I could not find, they are included in virtual memory count.
vm_stats:
Mach Virtual Memory Statistics: (page size of 4096 bytes)
Pages free: 262614.
Pages active: 818894.
Pages inactive: 287658.
Pages speculative: 46300.
Pages throttled: 0.
Pages wired down: 411565.
Pages purgeable: 56793.
"Translation faults": 255617431.
Pages copy-on-write: 10812762.
Pages zero filled: 165910381.
Pages reactivated: 3419113.
Pages purged: 2058688.
File-backed pages: 246635.
Anonymous pages: 906217.
Pages stored in compressor: 396258.
Pages occupied by compressor: 269783.
Decompressions: 625574.
Compressions: 1816628.
Pageins: 1693962.
Pageouts: 223513.
Swapins: 0.
Swapouts: 0.
top:
Processes: 253 total, 2 running, 6 stuck, 245 sleeping, 1101 threads 14:53:50
Load Avg: 1.42, 1.43, 1.62 CPU usage: 8.52% user, 5.97% sys, 85.50% idle
SharedLibs: 120M resident, 0B data, 26M linkedit.
MemRegions: 70307 total, 2561M resident, 107M private, 577M shared.
PhysMem: 5919M used (1608M wired), 1218M unused.
VM: 631G vsize, 1312M framework vsize, 0(0) swapins, 0(0) swapouts.
Networks: packets: 7933197/5221M in, 5685549/2563M out.
Disks: 1748536/37G read, 1726987/42G written.
Edit: Ok I looked around for a tool that might find that value of virtual memory. I believe the virtual memory value shown in 'Activity Monitor' is how much memory is really being used. Whereas 'top' shows all virtual memory, and most of it has not been actually placed somewhere. Programs may request a lot more memory then they will use, and since it is virtual memory it doesn't cost anything to let them have a large vm space as long as they don't actually use it. This link has a top replacement tool If you run it with 'sudo' like 'sudo procexp -all' it gives out what virtual memory may be more along the lines of what 'Activity Monitor' shows.
-----------------
Process: 0 Name: kernel_task Parent: 0 Status: runnable
Flags: 64-bit,system,session leader
UID: 0 RUID: 0 SVUID: 0
GID: 0 RGID: 0 SVGID: 0
Virtual size: 7167M (7515574272) Resident size: 752M (789536768)
Time: 58.03 = 00.00 (User) + 58.03 (System)
Syscalls: 0 Mach Traps: 0
Disk I/O: Read 9786K Written: 88547K
#Threads: 96 (Process has no workqueues)