As of at least macOS Catalina 10.15.3, /etc/sysctl.conf
values are no longer respected and/or the file straight up doesn't exist (confirmed on macOS Monterey 12.4.)
Ran across a fio
shm error: failed to setup shm segment
while benchmarking SSDs. The fix was to set shmmni
to 4096
. The following has to happen:
- Disable SIP
- Disclaimer from Apple
Warning
Disable SIP only temporarily to perform necessary tasks, and reenable it as soon as possible. Failure to reenable SIP when you are done testing leaves your computer vulnerable to malicious code.
- Disclaimer from Apple
- Download
com.startup.sysctl.plist
- Move to
/Library/LaunchDaemons/com.startup.sysctl.plist
- Load the PLIST after a few housekeeping items
# sanity check sysctl -a | grep shm # set permissions sudo chown root:wheel /Library/LaunchDaemons/com.startup.sysctl.plist # validate key-value pairs plutil /Library/LaunchDaemons/com.startup.sysctl.plist # load plist sudo launchctl bootstrap system /Library/LaunchDaemons/com.startup.sysctl.plist # check logs tail -f /tmp/sysctl.out tail -f /tmp/sysctl.err # recheck sysctl values sysctl -a | grep shm
- If the
shmmni
or other values didn't change, a reboot is in order- Known good output when values are changed successfully
λ tail -f /tmp/sysctl.out kern.sysv.shmmax: 4194304 -> 4194304 kern.sysv.shmmin: 1 -> 1 kern.sysv.shmmni: 32 -> 4096 kern.sysv.shmseg: 8 -> 8 kern.sysv.shmall: 1024 -> 1024 λ sysctl -a | grep shm kern.sysv.shmmax: 4194304 kern.sysv.shmmin: 1 kern.sysv.shmmni: 4096 kern.sysv.shmseg: 8 kern.sysv.shmall: 1024 security.mac.posixshm_enforce: 1 security.mac.sysvshm_enforce: 1
- Known good output when values are changed successfully
Setting shared memory in Catalina | Apple Developer Forums
c++ - Shared memory "Too many open files" but ipcs doesn't show many allocations - Stack Overflow
kernel - How do I increase the max open files in macOS Big Sur? - Super User
macos - "No space left on drive" when trying to allocate more shared memory - Stack Overflow