Skip to content

Instantly share code, notes, and snippets.

Last active February 13, 2024 18:27
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save pythoninthegrass/8073e5e3b24f385c9d9b712f6f243982 to your computer and use it in GitHub Desktop.
sysctl.conf stand-in on macOS 10.15+


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


      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.

  • 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


macos - Values from sysctl -A don't match /etc/sysctl.conf even after restart - Unix & Linux Stack Exchange

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

A launchd Tutorial

macos - Values from sysctl -A don't match /etc/sysctl.conf even after restart - Unix & Linux Stack Exchange

macos - "No space left on drive" when trying to allocate more shared memory - Stack Overflow

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<!-- DISABLE SIP TO USE: macOS Recovery > Utilities > Terminal > `csrutil disable` > Reboot -->
<plist version="1.0">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment