Skip to content

Instantly share code, notes, and snippets.

@tombigel
Forked from a2ikm/limit.maxfiles.plist
Last active November 20, 2024 01:49
Show Gist options
  • Save tombigel/d503800a282fcadbee14b537735d202c to your computer and use it in GitHub Desktop.
Save tombigel/d503800a282fcadbee14b537735d202c 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

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
@viggys
Copy link

viggys commented Jul 2, 2020

Hey @viggys that solution doesn't seem really viable because once you use that command it removes "unlimited" from the Hard limit and then you can never get it back.

Hey @phylaxis, just got to realise that restarting my mac has set back the default limits

Screenshot 2020-07-02 at 7 02 40 PM

So, the launchctl limit maxfiles <LIMIT> set the limits temporarily, which i think is a fair solution.

@evandrix
Copy link

typo in README - one fewer /: <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

@gmahe
Copy link

gmahe commented Jul 27, 2020

Works on Catalina 10.15.6, just make sure you are in /Library/LaunchDaemons/ and not ~/Library/LaunchDaemons/

@uniquepengpeng
Copy link

it works in catalina. but system disable plist after updated...

@iman38
Copy link

iman38 commented Nov 15, 2020

On bigsur 11.0.1, I had to add sudo in the ProgramArguments like this:

<?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>sudo</string>
          <string>launchctl</string>
          <string>limit</string>
          <string>maxfiles</string>
          <string>655360</string>
          <string>1048576</string>
        </array>
      <key>RunAtLoad</key>
        <true />
    </dict>
  </plist>

to get

kern.maxfiles: 1048576
kern.maxfilesperproc: 655360

Ridiculous at looking at how launchd works and I'm still getting Caller not allowed to perform action: launchctl.978, action = modify rlimits, code = 1: Operation not permitted in system.log, but the maxfiles settings changed indeed.

@PRNDA
Copy link

PRNDA commented Apr 25, 2021

Apple Sucks!
Apple changes this behaviour over times, it's seems that they never care about backward compatibility, always.

I'm considering transfer to Manjaro

@prologic
Copy link

prologic commented May 2, 2021

@PRNDA Your comment is not very constructive. Lots of things "suck".

Backwards compatibility is a tradeoff.

@KelseyDH
Copy link

KelseyDH commented May 19, 2021

So is this safe on Big Sur 11.3? Really don't want to brick my 2020 Macbook Pro (w/ 64 gb ram). Currently launchctl limit returns:

	cpu         unlimited      unlimited
	filesize    unlimited      unlimited
	data        unlimited      unlimited
	stack       8388608        67104768
	core        0              unlimited
	rss         unlimited      unlimited
	memlock     unlimited      unlimited
	maxproc     11136          16704
	maxfiles    256            unlimited

If things go badly, are the steps to reverse this just booting into safe mode and deleting the relevant launchctl files?

@alexdeia
Copy link

alexdeia commented May 21, 2021

Now I'm trying to return default values (like @KelseyDH). I do unload and load, it works, but after MacBook restart all limits return to my previous custom values:

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

It is really HURT. On my MacBook all apps (especially chrome and system apps like facetime and notification bar) constantly are crashed with error file descriptors. I don't know what I do else. Is it really serious that Mac OS (I'm a mac user from 2012 and didn't see this problem to 2018/2019) can't open a lot of apps or files??

@b-zurg
Copy link

b-zurg commented Jul 8, 2021

Ok how do you reset this awful change. Now my mac is unusable.

@prologic
Copy link

prologic commented Jul 8, 2021

Ok how do you reset this awful change. Now my mac is unusable.

Fiddling with what amounts to user-space limits shouldn't have an adverse effect on your OS 😳

@pluone
Copy link

pluone commented Nov 13, 2022

1048576

really helpful, when add 'sudo' it works after reboot.

@massisenergy
Copy link

On MacOS 13, sudo launchctl limit maxfiles 1048576.
But how can I make the change persist?

@RoxyFarhad
Copy link

Having this issue as well on MacOS 12.5.0 -- no matter how high I set the limit on maxfiles, I still get the same error trying to run a docker container.

@andy-clapson
Copy link

On MacOS 13, sudo launchctl limit maxfiles 1048576.
But how can I make the change persist?

This does indeed work, but it won't 'stick', so the most effective way is to add it to your .zshrc file.

Something like this:

echo "sudo launchctl limit maxfiles 1048576" >> ~/.zshrc

@9999years
Copy link

It appears that macOS 13.5 has broken this. Now (sometimes?), running sudo launchctl limit maxfiles 524288 fails with Could not set resource limits: 150: Operation not permitted while System Integrity Protection is engaged.

I've had a little bit better luck by explicitly setting the hard limit to unlimited with sudo launchctl limit maxfiles 524288 unlimited, but it doesn't seem to be super consistent and running launchctl limit maxfiles afterwards often shows that the limits are entirely unchanged, even if no error message was printed.

@CyberCr33p
Copy link

CyberCr33p commented Aug 9, 2023

I've had a little bit better luck by explicitly setting the hard limit to unlimited with sudo launchctl limit maxfiles 524288 unlimited, but it doesn't seem to be super consistent and running launchctl limit maxfiles afterwards often shows that the limits are entirely unchanged, even if no error message was printed.

I have the same issue. sudo launchctl limit maxfiles 524288 unlimited doesn't even temporary fix it. Did you found any solution?

@tklinchik
Copy link

tklinchik commented Aug 11, 2023

Having the same issue after last Monterey update to 12.6.8. I think the issue might be unlimited keyword no longer supported or intentionally disallowed.

As per [this post] this seems to have done a trick for me(https://superuser.com/questions/1634286/how-do-i-increase-the-max-open-files-in-macos-big-sur):

sudo launchctl limit maxfiles 9000000 9999999
ulimit -Sn 9000000

@tillydray
Copy link

From the url @tklinchik posted, this answer worked for me on 13.6

sudo sysctl kern.maxfiles=64000 kern.maxfilesperproc=28000

@redeemefy
Copy link

Anyone with Mac Sonoma 14.1.1 with a solution?

@viquu
Copy link

viquu commented Jan 8, 2024

Anyone with Mac Sonoma 14.1.1 with a solution?

I have same problem on sonoma 14.1.1, but I don't know how to solve it.

@Quiark
Copy link

Quiark commented Jan 25, 2024

One funny thing I found is that having ulimit in your profile, .config, fish rc etc files can work against you - if you set a relatively low limit there (I had 1024), any subsequent attempt to increase will fail.

@MDSADABWASIM
Copy link

I'm still looking for a proper solution for Sonoma.

@bingoup886
Copy link

I'm still looking for a proper solution for Sonoma.

me too,any update?

@MDSADABWASIM
Copy link

me too,any update?

No, still looking for a proper solution.

@ccarnero
Copy link

Hi! running :

❯ sudo launchctl limit maxfiles 1024 unlimited

worked for me on sonoma 14.4.1

❯ sudo launchctl limit
	cpu         unlimited      unlimited
	.....
	maxfiles    1024           unlimited

@MDSADABWASIM
Copy link

MDSADABWASIM commented Apr 27, 2024

sudo launchctl limit maxfiles 1024 unlimited

Worked for me as well, thanks.

But it doesn't persist @ccarnero

@NullVoxPopuli
Copy link

❯ sudo launchctl limit maxfiles 1024 unlimited

This requires System Integrity Protection to be disabled...........

@cuga-rajal
Copy link

Works fine on macOS 14.6.1 without disabling SIP. Persists on reboots.

Make sure the plist files go into /Library/LaunchDaemons/ and not ~/Library/LaunchDaemons/.

Make sure you use "chown root:wheel ..." and manually load them with "sudo launchctl load -w ...".

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