0

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.

Amal
  • 1
  • What drives do you have and what space is free on them? and how large is the swap file at its peak? – mmmmmm Apr 14 '21 at 11:29
  • Have you tried turning off SIP, running the command, and then turning SIP back on? – Wowfunhappy Apr 14 '21 at 12:52
  • 1
    What problem are you trying to solve by doing this? – Marc Wilson Apr 14 '21 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 Apr 14 '21 at 17:30
  • Why would a RAMdisk help? The swap and RAM will have the simulator cached already if you use it often in a short time. Also how much sppedup do you need to be worth having an odd set up. 1% won't be worth your time reducing from 5 minutes to 4 might not be either. – mmmmmm Apr 14 '21 at 17:35
  • @mmmmmm I had it working on the same machine running Windows 10 with RAMdisk although I had other page file issues with Windows. I don't think its an odd setup. I use the RAMDisk for everything, browser cache, downloads, temp files (Windows TEMP & TMP variable) etc. Also keeps SSD free of too many writes. I think it's extremely useful and an efficient setup. – Amal Apr 14 '21 at 17:44
  • Windows and macOS have different use of swap etc and SSDs last many years now – mmmmmm Apr 14 '21 at 17:45
  • 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 Apr 14 '21 at 18:41
  • I'll guarantee you that the OS has far better things to do with the RAM than put a ramdisk in it. – Marc Wilson Apr 14 '21 at 23:02
  • @Tetsujin I agree Mac doesn't create a swap file till necessary but for me, the moment I start mobile simulator it creates swap. I hope all of u understand that I am not trying to interfere with the way OS works. "sysctl vm.swapfileprefix" is a configurable option provided by macOS. What's the issue if I use it legitimately. @@Marc I do understand OS can use RAM efficiently. I have created a minimal RAMDisk. If I can use some spare RAM which is mostly lying idle for a good duration of system use then what's the harm. – Amal Apr 15 '21 at 13:17

0 Answers0