Skip to content

Instantly share code, notes, and snippets.

@luzfcb
Last active September 12, 2019 14:20
Show Gist options
  • Save luzfcb/ccb5b147827838829c3766eba6d8f96f to your computer and use it in GitHub Desktop.
Save luzfcb/ccb5b147827838829c3766eba6d8f96f to your computer and use it in GitHub Desktop.
curl -L https://git.io/fx8PT -o increase_osx_max_opened_files.sh

chmod +x increase_osx_max_opened_files.sh

sudo ./increase_osx_max_opened_files.sh

before run this:

luzfcb@fabio:~$ ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
file size               (blocks, -f) unlimited
max locked memory       (kbytes, -l) unlimited
max memory size         (kbytes, -m) unlimited
open files                      (-n) 4864
pipe size            (512 bytes, -p) 1
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 1418
virtual memory          (kbytes, -v) unlimited

after:

luzfcb@fabio:~$ ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
file size               (blocks, -f) unlimited
max locked memory       (kbytes, -l) unlimited
max memory size         (kbytes, -m) unlimited
open files                      (-n) 250000
pipe size            (512 bytes, -p) 1
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 1418
virtual memory          (kbytes, -v) unlimited
#!/bin/bash
#
# v2 - 2018-10-12
#
# https://docs.basho.com/riak/kv/2.0.7/using/performance/open-files-limit/#adjusting-open-file-limits-in-yosemite
# https://stackoverflow.com/a/45985042
# https://superuser.com/a/828010
# tested on High Sierra 10.13.6
# MAX OPEN FILES = 524288 - OSX default is 4864
# MAX PROCESSES = 2048 - OSX default is 1418
#
# How to use:
# First, salve all opened files,
# open the terminal, and run
#
#
# curl -L https://git.io/fx8PT -o increase_osx_max_opened_files.sh
# chmod +x increase_osx_max_opened_files.sh
# sudo ./increase_osx_max_opened_files.sh
#
MAX_FILES_SOFT=250000
MAX_FILES_HARD=524288
MAX_PROCESS_SOFT=2048
MAX_PROCESS_HARD=2048
WORK_DIR="$(dirname "$0")"
txtred=$(tput setaf 1) # Red
txtyellow=$(tput setaf 3) # Yellow
txtreset=$(tput sgr0) # Reset the color
echo ""
echo ""
echo " ${txtyellow}WARNING${txtreset}"
echo "${txtred}"
echo "The OSX will restart automatically at the end of the installation."
echo "Please, save all open documents before continue."
echo ""
read -p "Press [Enter] key to continue or press [CRTL] + [C] to cancel..."
echo ""
echo ""
echo "${txtreset}"
if [[ $EUID -ne 0 ]]; then
echo "${txtred}"
cat <<-EOF >&2
You must run this script with root privilege
Please run:
sudo $WORK_DIR/${0##*/} $PARAN
EOF
echo "${txtreset}"
exit 1
fi
curl -L https://gist.githubusercontent.com/luzfcb/ccb5b147827838829c3766eba6d8f96f/raw/limit.maxfiles.plist -o limit.maxfiles.plist
curl -L https://gist.githubusercontent.com/luzfcb/ccb5b147827838829c3766eba6d8f96f/raw/limit.maxproc.plist -o limit.maxproc.plist
sed -i '' "s/MAXFILES_SOFT/${MAX_FILES_SOFT}/g" limit.maxfiles.plist
sed -i '' "s/MAXFILES_HARD/${MAX_FILES_HARD}/g" limit.maxfiles.plist
sed -i '' "s/MAXPROCESS_SOFT/${MAX_PROCESS_SOFT}/g" limit.maxfiles.plist
sed -i '' "s/MAXPROCESS_HARD/${MAX_PROCESS_HARD}/g" limit.maxfiles.plist
mv limit.maxfiles.plist /Library/LaunchDaemons/limit.maxfiles.plist
mv limit.maxproc.plist /Library/LaunchDaemons/limit.maxproc.plist
chmod 644 /Library/LaunchDaemons/limit.maxfiles.plist
chmod 644 /Library/LaunchDaemons/limit.maxproc.plist
chown root:wheel /Library/LaunchDaemons/limit.maxfiles.plist
chown root:wheel /Library/LaunchDaemons/limit.maxproc.plist
launchctl load -w /Library/LaunchDaemons/limit.maxfiles.plist
launchctl load -w /Library/LaunchDaemons/limit.maxproc.plist
echo "Rebooting..."
sleep 2
reboot
exit 0
<?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>MAXFILES_SOFT</string>
<string>MAXFILES_HARD</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>MAXPROCESS_SOFT</string>
<string>MAXPROCESS_HARD</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>ServiceIPC</key>
<false/>
</dict>
</plist>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment