GitBucket
4.21.2
Toggle navigation
Snippets
Sign in
Files
Branches
1
Releases
Wiki
nigel.stanger
/
Wiki
Compare Revisions
View Page
Back to Page History
Setting macOS system limits.md
The following shows how to increase the `maxfiles` (maximum number of open files) soft limit, but the same process can be applied to any system limit. On Linux these are set using `sysctl`. # Increasing per-process (launchd) If an individual `launchd` process needs a higher soft limit, adding the following to its `.plist` will do nicely: ```xml <key>SoftResourceLimits</key> <dict> <key>NumberOfFiles</key> <integer>10240</integer> </dict> ``` Of course, this may fall apart if the `.plist` can be restored to its default version by a software update. Cunning Plan™: Create a LaunchDaemon or cron job to run a script every night that checks the `.plist` and inserts the above if it’s not there (easy to do using XMLStarlet), then restarts the relevant daemon. # Increasing globally Too low a value of `maxfiles` can cause things like `mysqldump` to fail (no backups for you, although MariaDB seems to set it independently these days). To show the current limit (probably stupidly low, e.g., 256): ```sh launchctl limit maxfiles ``` To set temporarily: ```sh sudo launchctl limit maxfiles 10240 2147483647 ``` The third and fourth arguments are the soft and hard limits, respectively. **Always** set the fourth argument to 2147483647 (= `INT_MAX` = “unlimited”) unless you really want your machine to grind to a halt (https://apple.stackexchange.com/a/366319)! As per the `launchctl` man page (emphasis added): “When a given resource is specified, it prints the limits for that resource. **With a third argument, it sets both the hard and soft limits to that value.** With four arguments, the third and forth *[sic]* argument represent the soft and hard limits respectively.” To set more persistently (https://superuser.com/a/1171028), create `/Library/LaunchDaemons/limit.maxfiles.plist` with the following contents: ```xml <?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>2147483647</string> </array> <key>RunAtLoad</key> <true/> <key>ServiceIPC</key> <false/> </dict> </plist> ``` However, note that this only occurs *somewhere* during the startup sequence, not first, so servers (e.g., MySQL) may start earlier and therefore need to be restarted in order to inherit the new value. # Checking To check the open files limit in MySQL: ```sql select @@open_files_limit; ```
The following shows how to increase the `maxfiles` (maximum number of open files) soft limit, but the same process can be applied to any system limit. On Linux these are set using `sysctl`. # Increasing per-process (launchd) If an individual `launchd` process needs a higher soft limit, adding the following to its `.plist` will do nicely: ```xml <key>SoftResourceLimits</key> <dict> <key>NumberOfFiles</key> <integer>10240</integer> </dict> ``` Of course, this may fall apart if the `.plist` can be restored to its default version by a software update. Cunning Plan™: Create a LaunchDaemon or cron job to run a script every night that checks the `.plist` and inserts the above if it’s not there (easy to do using XMLStarlet), then restarts the relevant daemon. # Increasing globally Too low a value of `maxfiles` can cause things like `mysqldump` to fail (no backups for you). To show the current limit (~~probably stupidly low, e.g., 256~~ **this now seems to be set automatically**): ```sh launchctl limit maxfiles ``` To set temporarily: ```sh sudo launchctl limit maxfiles 10240 2147483647 ``` The third and fourth arguments are the soft and hard limits, respectively. **Always** set the fourth argument to 2147483647 (= `INT_MAX` = “unlimited”) unless you really want your machine to grind to a halt (https://apple.stackexchange.com/a/366319)! As per the `launchctl` man page (emphasis added): “When a given resource is specified, it prints the limits for that resource. **With a third argument, it sets both the hard and soft limits to that value.** With four arguments, the third and forth *[sic]* argument represent the soft and hard limits respectively.” To set more persistently (https://superuser.com/a/1171028), create `/Library/LaunchDaemons/limit.maxfiles.plist` with the following contents: ```xml <?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>2147483647</string> </array> <key>RunAtLoad</key> <true/> <key>ServiceIPC</key> <false/> </dict> </plist> ``` However, note that this only occurs *somewhere* during the startup sequence, not first, so servers (e.g., MySQL) may start earlier and therefore need to be restarted in order to inherit the new value. # Checking To check the open files limit in MySQL: ```sql select @@open_files_limit; ```