How to free up a swap space manually without restart?

As for the workaround, restarting/killing WindowServer process temporarily helped:

# sudo pkill -HUP -u _windowserver

However, this will kill all processes, logs you out and re-open all windows again, so use it only when your system is in a very bad shape. However, it cleaned/removed all the swapfiles without the restart (at least for some time) till it gets out of the control again.


To monitor, what's creating/updating these swap files, run:

$ sudo fs_usage | grep swapfile

Or for page ins/outs, run:

$ sudo fs_usage | grep PAGE_

To see what WindowServer process is doing exactly, run:

$ sudo spindump -reveal $(pgrep WindowServer)

or for kernel_task, run:

$ sudo spindump -reveal 0