I am using Mobile simulator and virtual machines which memory intensive. There are a few posts on internet about how to change the location of Swap files on macOS versions with System Integrity Protection (SIP). The simplest solution without tinkering with OS internals seems to be running the below shell command after boot:

sysctl vm.swapfileprefix=/Volumes/Swap/s

(here /Volumes/Swap is the new swap directory)

But unless SIP is disabled this command can't be executed. There should be a way to configure this on startup as I can't keep SIP disabled just to execute this command. Does setting this in /etc/sysctl.conf work on macOS? Has anyone of you tried this? This solution is suggested in this post from 2015 for older versions of macOS when SIP didn't exist.

How can I move virtual memory swap files to a different drive or partition?

Open to any other alternative solutions. Sorry for cross posting but I didn't get any constructive replies on Apple forum.

  • What drives do you have and what space is free on them? and how large is the swap file at its peak?
    – mmmmmm
    Commented Apr 14, 2021 at 11:29
  • Have you tried turning off SIP, running the command, and then turning SIP back on? Commented Apr 14, 2021 at 12:52
  • 1
    What problem are you trying to solve by doing this? Commented Apr 14, 2021 at 17:17
  • @mmmmmm I am experimenting, currently with one simulator it uses 1Gb swap. I want to use a Ramdisk to host that. @@Wowfunhappy, I checked, this command works only when SIP is disabled. @@Marc, primarily trying to get better performance if I can get it to use a Ramdisk. Thanks, appreciate your help.
    – Amal
    Commented Apr 14, 2021 at 17:30
  • 1
    As @mmmmmm says, Mac's swap is really efficient. This machine has been up 25 days & swap used is still 0 bytes. If you have enough RAM for the task, swap won't ever be touched. If you don't then you're reducing the available pool by the amount you're stealing as RAMdisk for swap. Catch 22.
    – Tetsujin
    Commented Apr 14, 2021 at 18:41


You must log in to answer this question.

Browse other questions tagged .