Skip to content

Instantly share code, notes, and snippets.

@skylock
Forked from devinrhode2/README.md
Last active September 11, 2023 13:51
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save skylock/0117ec637d468f91260927b43b816eda to your computer and use it in GitHub Desktop.
Save skylock/0117ec637d468f91260927b43b816eda to your computer and use it in GitHub Desktop.
How to Change Open Files Limit on OS X and macOS Sierra (10.8 - 10.12)

How to Change Open Files Limit on OS X and macOS

To check the current limits on your Mac OS X system, run in terminal:

launchctl limit maxfiles
ulimit -a

Steps

  1. Reboot the system and enter recovery mode - keep cmd (⌘) + R pressed
  2. Disable system integrity check from terminal, by typing csrutil disable
  3. Reboot
  4. Create the files below
  5. Reboot
  6. Enable system integrity check, by typing csrutil enable
  7. Reboot the system to complete the changes

The last two columns are the soft and hard limits, respectively.

Adjusting Open File Limits in Sierra

To adjust open files limits on a system-wide basis in Mac OS X Sierra, you must create two configuration files. The first is a property list (aka plist) file in /Library/LaunchDaemons/limit.maxfiles.plist that contains the following XML configuration:

sudo vi /Library/LaunchDaemons/limit.maxfiles.plist
<?xml version="1.0" encoding="UTF-8"?>  
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"  
        "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">  
  <dict>
    <key>Label</key>
    <string>limit.maxfiles</string>
    <key>ProgramArguments</key>
    <array>
      <string>launchctl</string>
      <string>limit</string>
      <string>maxfiles</string>
      <string>64000</string>
      <string>524288</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>ServiceIPC</key>
    <false/>
  </dict>
</plist> 

This will set the open files limit to 64000.

The second plist configuration file should be stored in /Library/LaunchDaemons/limit.maxproc.plist with the following contents:

sudo vi /Library/LaunchDaemons/limit.maxproc.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple/DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  <plist version="1.0">
    <dict>
      <key>Label</key>
        <string>limit.maxproc</string>
      <key>ProgramArguments</key>
        <array>
          <string>launchctl</string>
          <string>limit</string>
          <string>maxproc</string>
          <string>2048</string>
          <string>2048</string>
        </array>
      <key>RunAtLoad</key>
        <true />
      <key>ServiceIPC</key>
        <false />
    </dict>
  </plist>
  1. Change the owner for the created files
sudo chown root:wheel /Library/LaunchDaemons/limit.maxfiles.plist
sudo chown root:wheel /Library/LaunchDaemons/limit.maxproc.plist
  1. Load these new settings:
sudo launchctl load -w /Library/LaunchDaemons/limit.maxfiles.plist
sudo launchctl load -w /Library/LaunchDaemons/limit.maxproc.plist
  1. Reboot & Enable system integrity check
csrutil enable
  1. Finally, check that the limits are correct:
launchctl limit maxfiles
ulimit -a

Returned values should be the same

Both plist files must be owned by root:wheel and have permissions -rw-r--j--. This permissions should be in place by default, but you can ensure that they are in place by running sudo chmod 644 . While the steps explained above will cause system-wide open file limits to be correctly set upon restart, you can apply them manually by running launchctl limit.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>limit.maxfiles</string>
<key>ProgramArguments</key>
<array>
<string>launchctl</string>
<string>limit</string>
<string>maxfiles</string>
<string>10240</string>
<string>12288</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>ServiceIPC</key>
<false/>
</dict>
</plist>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple/DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>limit.maxproc</string>
<key>ProgramArguments</key>
<array>
<string>launchctl</string>
<string>limit</string>
<string>maxproc</string>
<string>2048</string>
<string>2048</string>
</array>
<key>RunAtLoad</key>
<true />
<key>ServiceIPC</key>
<false />
</dict>
</plist>
@ns-mkusper
Copy link

Still works on Ventura 13.0.1

@CyberCr33p
Copy link

It stopped working in 13.5

@paulirish
Copy link

    <key>ServiceIPC</key> 
   <false/>

spotted in my launchd.log earlier:

(limit.maxfiles) : The ServiceIPC key is no longer respected. Please remove it.

@paulirish
Copy link

paulirish commented Aug 17, 2023

It stopped working in 13.5

But yes. Here's another signal from Chromium project that using the sysctl calls from the launchdaemon plists fails as of Venture 13.5 now: https://bugs.chromium.org/p/chromium/issues/detail?id=1467777

and this: https://apple.stackexchange.com/questions/462489/how-to-increase-global-max-opened-files-limit-on-osx-13-5-ventura

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment