Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This text is the section about OS X Yosemite (which also works for macOS Sierra) from https://docs.basho.com/riak/kv/2.1.4/using/performance/open-files-limit/#mac-os-x

The last time i visited this link it was dead (403), so I cloned it here from the latest snapshot in Archive.org's Wayback Machine https://web.archive.org/web/20170523131633/https://docs.basho.com/riak/kv/2.1.4/using/performance/open-files-limit/

Mac OS X

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

launchctl limit maxfiles

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

Adjusting Open File Limits in Yosemite

To adjust open files limits on a system-wide basis in Mac OS X Yosemite, 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:

<?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>200000</string>
          <string>200000</string>
        </array>
      <key>RunAtLoad</key>
        <true/>
      <key>ServiceIPC</key>
        <false/>
    </dict>
  </plist>

This will set the open files limit to 200000. The second plist configuration file should be stored in /Library/LaunchDaemons/limit.maxproc.plist with the following contents:

<?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>

Both plist files must be owned by root:wheel and have permissions -rw-r--r--. 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.

In addition to setting these limits at the system level, we recommend setting the at the session level as well by appending the following lines to your bashrc, bashprofile, or analogous file:

ulimit -n 200000
ulimit -u 2048

Like the plist files, your bashrc or similar file should have -rw-r--r-- permissions. At this point, you can restart your computer and enter ulimit -n into your terminal. If your system is configured correctly, you should see that maxfiles has been set to 200000.

<?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>524288</string>
<string>524288</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>
#!/bin/sh
# These are the original gist links, linking to my gists now.
# curl -O https://gist.githubusercontent.com/a2ikm/761c2ab02b7b3935679e55af5d81786a/raw/ab644cb92f216c019a2f032bbf25e258b01d87f9/limit.maxfiles.plist
# curl -O https://gist.githubusercontent.com/a2ikm/761c2ab02b7b3935679e55af5d81786a/raw/ab644cb92f216c019a2f032bbf25e258b01d87f9/limit.maxproc.plist
curl -O https://gist.githubusercontent.com/tombigel/d503800a282fcadbee14b537735d202c/raw/ed73cacf82906fdde59976a0c8248cce8b44f906/limit.maxfiles.plist
curl -O https://gist.githubusercontent.com/tombigel/d503800a282fcadbee14b537735d202c/raw/ed73cacf82906fdde59976a0c8248cce8b44f906/limit.maxproc.plist
sudo mv limit.maxfiles.plist /Library/LaunchDaemons
sudo mv limit.maxproc.plist /Library/LaunchDaemons
sudo chown root:wheel /Library/LaunchDaemons/limit.maxfiles.plist
sudo chown root:wheel /Library/LaunchDaemons/limit.maxproc.plist
sudo launchctl load -w /Library/LaunchDaemons/limit.maxfiles.plist
sudo launchctl load -w /Library/LaunchDaemons/limit.maxproc.plist
@devinrhode2

This comment has been minimized.

Copy link

devinrhode2 commented Dec 22, 2017

@devinrhode2

This comment has been minimized.

Copy link

devinrhode2 commented Dec 22, 2017

However... this answer on SuperUser.com claims that this process of adding a file to Library/LaunchDaemons you describe here is now the way you need to update the file limit for Sierra https://superuser.com/a/1171026/88226

@devinrhode2

This comment has been minimized.

Copy link

devinrhode2 commented Dec 28, 2017

@safareli

This comment has been minimized.

Copy link

safareli commented Jun 20, 2018

YOU SHOULD RESTART YOUR COMPUTER FOR THIS TO WORK

@jiapengjun

This comment has been minimized.

Copy link

jiapengjun commented Aug 3, 2018

The plist way works well on macOS 10.13.6.
The bashrc/bashprofile way doesn't work even restarting host. "-bash: ulimit: open files: cannot modify limit: Invalid argument" is reported.

@nhelfer

This comment has been minimized.

Copy link

nhelfer commented Aug 8, 2018

If you don't want to restart your computer, you can launch theses commands :
sudo launchctl load -w /Library/LaunchDaemons/limit.maxfiles.plist sudo launchctl load -w /Library/LaunchDaemons/limit.maxproc.plist

@mjruschak

This comment has been minimized.

Copy link

mjruschak commented Aug 22, 2018

This is great and very helpful. Has anyone been able to get the maxproc limit to stick? I cannot get this one to work but the maxfiles works fine.

@metacritical

This comment has been minimized.

Copy link

metacritical commented Oct 10, 2018

Does this work on OSX Mojave?

@centaur1

This comment has been minimized.

Copy link

centaur1 commented Nov 6, 2018

Has anyone tried this on Mojave yet? (to echo @metacritical)

@Larzack

This comment has been minimized.

Copy link

Larzack commented Nov 11, 2018

Works

@Larzack

This comment has been minimized.

Copy link

Larzack commented Nov 29, 2018

Can't have more than 2048 in maxproc

@wangbourne

This comment has been minimized.

Copy link

wangbourne commented Jan 30, 2019

It works unde Mojave @centaur1

@gautiermichelin

This comment has been minimized.

Copy link

gautiermichelin commented Apr 30, 2019

@nhelfer : I used your comment thanks.
Note : add "&&" between the 2 instructions sudo launchctl load -w /Library/LaunchDaemons/limit.maxfiles.plist && sudo launchctl load -w /Library/LaunchDaemons/limit.maxproc.plist

@rockkoca

This comment has been minimized.

Copy link

rockkoca commented Jun 14, 2019

if you have ever run this command before and want to change to larger values, be sure to unload them. Otherwise, it will not change.

sudo launchctl unload -w /Library/LaunchDaemons/limit.maxfiles.plist
sudo launchctl unload -w /Library/LaunchDaemons/limit.maxproc.plist

Unload before load.

sudo launchctl load -w /Library/LaunchDaemons/limit.maxfiles.plist
sudo launchctl load -w /Library/LaunchDaemons/limit.maxproc.plist

@jessecarbon

This comment has been minimized.

Copy link

jessecarbon commented Sep 18, 2019

This doesn't appear to work on 10.15 Catalina beta:

Sep 18 11:44:16 macos1015beta com.apple.xpc.launchd[1] (limit.maxfiles): The ServiceIPC key is no longer respected. Please remove it.

EDIT: Simply removing ServiceIPC from the plist seems to work fine, nevermind!

@alvistar

This comment has been minimized.

Copy link

alvistar commented Oct 4, 2019

Hi,
I am on Mojave and I have an issue I can't solve after a lot of googling around.
If I manually unload and load the limit.maxfiles.plist it works, but after a reboot maxfiles will be resetted to 10240.
I suspect there is something else setting that limit during the boot process, but I have no idea how to find it.

Anyone experiencing this problem? Clues?

@hongwei1

This comment has been minimized.

Copy link

hongwei1 commented Oct 22, 2019

Hi,
I am on Mojave and I have an issue I can't solve after a lot of googling around.
If I manually unload and load the limit.maxfiles.plist it works, but after a reboot maxfiles will be resetted to 10240.
I suspect there is something else setting that limit during the boot process, but I have no idea how to find it.

Anyone experiencing this problem? Clues?

Same for me ... I am Mojave10.14.6. not work in my side

@WeirdCircumstances

This comment has been minimized.

Copy link

WeirdCircumstances commented Oct 25, 2019

Works for me as described on 10.14. Thanks!

@Bryji

This comment has been minimized.

Copy link

Bryji commented Nov 6, 2019

Worked for me on Mojave 10.14.6

@LuckyMagacian

This comment has been minimized.

Copy link

LuckyMagacian commented Nov 8, 2019

Catalina 10.15.1
kern.maxfiles worked but kern.maxproc not
and kern.maxprocperuid was changed howerver I didn't change it !!!!

@StephPeriquet

This comment has been minimized.

Copy link

StephPeriquet commented Nov 25, 2019

Both of these :
sudo launchctl load -w /Library/LaunchDaemons/limit.maxfiles.plist
sudo launchctl load -w /Library/LaunchDaemons/limit.maxproc.plist
Gives me the following message : /Library/LaunchDaemons/limit.maxfiles.plist: Invalid property list

This even after reboot.

launchctl limit
cpu unlimited unlimited
filesize unlimited unlimited
data unlimited unlimited
stack 8388608 67104768
core 0 unlimited
rss unlimited unlimited
memlock unlimited unlimited
maxproc 1418 2128
maxfiles 10240 10240

Any idea of what to do next?
My issue is coming with adobe Illustrator giving me this error all of the sudden : "Unable to set maximum number of files to be opened", it used to work just fine.
MacMini Mojave 10.14.6

@ledlamp

This comment has been minimized.

Copy link

ledlamp commented Dec 2, 2019

If the launchdaemons are just to run the command launchctl limit maxfiles 200000 then why not just use crontab?

@ledlamp

This comment has been minimized.

Copy link

ledlamp commented Dec 2, 2019

BTW I discovered some things about launchctl limits. If you run launchctl limit maxfiles unlimited it sets it to 10240, even though you can specify a much higher number. While launchctl limit maxproc unlimited does nothing.
And the actual maximums are 2147483647 for maxfiles and 2500 for maxproc.

@ledlamp

This comment has been minimized.

Copy link

ledlamp commented Dec 2, 2019

Apparently setting maxfiles to 2147483647 is not a good idea!! It caused login and lsof (probably others too) to hang at 100% CPU! I couldn't open a terminal because it would hang at login (until timing out after 300 seconds), and Visual Studio Code spawned a ton of lsof's under bash's with grep's, using all CPU, and they orphaned when closing VSC; had to killall lsof.

@flyingfang

This comment has been minimized.

Copy link

flyingfang commented Dec 7, 2019

Catalina 10.15.1
kern.maxfiles worked but kern.maxproc not
and kern.maxprocperuid was changed howerver I didn't change it !!!!

same as you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.