8

I've been getting various "too many files open in system"-type errors on Yosemite (10.10.1). Searching around suggests setting kern.maxfiles and kern.maxfilesperprocess in /etc/sysctl.conf.

I've tried this, and kern.maxfilesperprocess sticks after a reboot, but kern.maxfiles doesn't.

% cat /etc/sysctl.conf 
# NB DO NOT COPY AND PASTE THIS INTO YOUR CONFIG FILE - IT DOESN'T WORK
kern.maxfiles=20480 
kern.maxfilesperproc=18000

(reboot)

% sysctl kern.maxfiles
kern.maxfiles: 12288
% sysctl kern.maxfilesperproc   
kern.maxfilesperproc: 18000

If I set it manually at the command line, it works, so it doesn't seem I'm exceeding any upper limit:

% sudo sysctl -w kern.maxfiles=20480 
kern.maxfiles: 12288 -> 20480
% sysctl kern.maxfiles               
kern.maxfiles: 20480

I have seen warnings about these values being overridden in /etc/launchd.conf but I don't have this file:

% cat /etc/launchd.conf
cat: /etc/launchd.conf: No such file or directory

Spotlight search doesn't find any other mention of kern.maxfiles, so I'm out of ideas. Any other suggestions?

3
  • @w00t I reverted the edit that removed the trailing spaces from the conf file - since these spaces were actually the problem in the first place, I believe it makes more sense to leave them in the question.
    – CupawnTae
    Commented Mar 22, 2016 at 19:07
  • fair enough, edited question instead to indicate this.
    – w00t
    Commented Mar 23, 2016 at 16:38
  • @w00t your last proposed edit was rejected by a diamond mod (not by me) - possibly because I already edited a warning into the text itself after reverting your edit. I should have let you know when I did that - your point was a good one, so after reverting and commenting, I felt it needed something - hopefully my last edit covers it?
    – CupawnTae
    Commented Mar 23, 2016 at 16:58

3 Answers 3

11
+50

Though not directly answering your question you will find two solutions at superuser:

  1. 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>65536</string>
              <string>65536</string>
            </array>
          <key>RunAtLoad</key>
            <true/>
          <key>ServiceIPC</key>
            <false/>
        </dict>
      </plist>
    

    This will set the open files limit to 65536. 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 <filename>. 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 65536
    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 65536.

    Adjust the maxfiles & maxproc limit as you need it

    Sourced from: http://docs.basho.com/riak/latest/ops/tuning/open-files-limit/

  2. Modifying the /etc/launchd.conf per a lot of google queries and SO suggestions didn't seem to work for me in Yosemite (10.10). What did end up working, after numerous change/reboot/test combinations, was modifying (or creating if it doesn't exist) the /etc/sysctl.conf file.

    This is what I had to put in to make it work

    kern.maxfiles=65536
    kern.maxfilesperproc=65536
    

    I'm not sure if 'kern.maxfiles' needs to be in there, but when I had it in there by itself I still had the same issue, when I added the 'kern.maxfilesperproc' everything started working.

If one or both of those solutions work for you, please credit the original posters.

6
  • Let us continue this discussion in chat.
    – klanomath
    Commented Jan 29, 2015 at 22:12
  • Although this didn't resolve the issue, it does provide a workaround (the first plist file). Thanks also for the assistance in hunting down the actual cause. Bounty awarded.
    – CupawnTae
    Commented Jan 30, 2015 at 14:07
  • Do you perhaps know how to set the higher limit to "unlimited' like OS X does by default? I'm specifically looking to adapt this answer to raise the ulimit -n to 1000 and not change any other aspect to run some performance tests for one software package.
    – bmike
    Commented Apr 20, 2015 at 19:15
  • @bmike hmm, which higher limit? -n = 1000 as soft limit and an unlimited hard limit. Which OS? 10.10 or 10.9 and lower?
    – klanomath
    Commented Apr 20, 2015 at 19:36
  • I figured out another way to do what I wanted putting the program under launchctl and using the limits there in a plist. I'll put up a new question once my code changes are reviewed and merged elsewhere.
    – bmike
    Commented Apr 20, 2015 at 20:22
5

Through a combination of safe/verbose boot, console log and google, I found a similar issue which led me to discover a trailing space on the maxfiles line. Removing this space resolved the issue.

Please, double check that the lines in sysctl.conf do not have a trailing space. This seems to be causing a problem with Yosemite whereas it was properly working with previous versions.

Corrected settings (these ones can safely be copied):

kern.maxfiles=20480
kern.maxfilesperproc=18000
1

Removing trailing whitespace takes just one step:

sed -i '~' -e's/[[:space:]]*$//' /etc/sysctl.conf

Command above also saves a backup at /etc/sysctl.conf~.

1
  • 1
    this file doesn't work anymore on newer versions of macOS Commented Dec 15, 2022 at 17:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .