1

Usually on various unix flavours for swap we have Those commands to see swap usage and activation of swap

On Linux

    free
    swapon/off

On Hpux

   swapinfo
   swapon/off

On AIX

   swap
   swapon/off
   lsps

And on Macos? Nothing to activate/deactivate and see swap usage?

1 Answer 1

3

Utilities for viewing swap usage and for managing the swap space are generally OS-specific.

One way to get the swap usage on macOS is through sysctl,

$ sysctl vm.swapusage
vm.swapusage: total = 2048.00M  used = 339.25M  free = 1708.75M  (encrypted)

or to get the virtual memory statistics, use vm_stat,

$ vm_stat
Mach Virtual Memory Statistics: (page size of 4096 bytes)
Pages free:                               22689.
Pages active:                           1293975.
Pages inactive:                         1210689.
Pages speculative:                        90024.
Pages throttled:                              0.
Pages wired down:                       1149514.
Pages purgeable:                          45249.
"Translation faults":                 627071029.
Pages copy-on-write:                   17768756.
Pages zero filled:                    444351056.
Pages reactivated:                     10794611.
Pages purged:                            764381.
File-backed pages:                      1352224.
Anonymous pages:                        1242464.
Pages stored in compressor:             1408501.
Pages occupied by compressor:            427131.
Decompressions:                         6806364.
Compressions:                          10983871.
Pageins:                              102270242.
Pageouts:                               7852274.
Swapins:                                1883954.
Swapouts:                               2043277.

It is generally not advisable to disable swap on macOS, and there's usually no need to manually increase the swap file's size.

This question/answer at the Ask Different site talks about moving the swap file to another disk, but the question is over eight years old, so it may be out of date.

This question on the same site is about disabling swap on macOS, but as one of the answers says:

That said, this is definitely a case of premature optimization. It is almost always a HORRIBLE, HORRIBLE idea to disable your swap file. The swap file is there for when your running programs consume more memory than you have physically installed. If you disable it, you may not be able to run as many programs at the same time (and the limit is far lower than you'd expect) or you may have issues (like freezing and having to hard-reboot the machine) when you run out of memory.

The question states that one may disable swap and delete the swap file using

sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.dynamic_pager.plist
sudo rm /private/var/vm/swapfile*

which I haven't really dared testing as I can't guarantee that I will always have enough RAM available to run without swap.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .