OSX /private/var/vm disk usage

TL;DR see last paragraph.

I googled around for this answer and found nothing, so THEN I read the man page. This felt backward for OSX answers.
My Mac gave me warning that I was almost out of disk space recently. I ran du -kx / | sort -nr | less and noticed the biggest offender with nearly 10% of my disk space was /var/private/vm, so I started digging.
It turns out this is where OSX stores its swap files if it needs them.
OSX dynamically grows its swap files by adding new files, not by resizing an existing file. It starts off with very small files and as it needs a new one it creates a large one until it gets to 1GB file size and then it continues making 1GB swap files. The process dynamic_pager manages this.
In my case the 5GB of swap didn’t seem like that much until you consider that I have a 64GB MacBook Air. That is a large piece of the disk.
I told the dynamic_pager to clean up after itself, if it could, by running this command:

sudo dynamic_pager -L 1073741824

3 thoughts on “OSX /private/var/vm disk usage”

  1. Thanks for making this public. I just saw it a little to late. My vm folder had grown to 20GB and the remaining diskspace to 60MB. A restart brought it down to 5GB.

    What is the number in the command? It looks kind of random to me. Could you enlighten me?

    Thanks,
    Ben

  2. hi Ben,

    the man page for dynamic_pager says this about the low-water-trigger argument to the -L option.

    -L If there are more than low-water-trigger bytes free in the external paging
    files, the kernel will coalese in-use pages and signal dynamic_pager to dis-
    card an external paging file. Low-water-trigger must be greater than
    high-water-trigger + filesize.

    so basically it is a reasonable size that tells the dynamic pager to cleanup after itself. It might be the case that your page file really is using all that disk and that it cannot clean up.

Comments are closed.