Skip to content

Instantly share code, notes, and snippets.

@dtmrc
Forked from pythoninthegrass/README.md
Created February 13, 2024 18:27
Show Gist options
  • Save dtmrc/a415b5dbe63013e88b232aa51e3f9164 to your computer and use it in GitHub Desktop.
Save dtmrc/a415b5dbe63013e88b232aa51e3f9164 to your computer and use it in GitHub Desktop.

Revisions

  1. @pythoninthegrass pythoninthegrass revised this gist Jul 20, 2022. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -60,3 +60,7 @@ Ran across a `fio` shm error: `failed to setup shm segment` while benchmarking S
    [kernel - How do I increase the max open files in macOS Big Sur? - Super User](https://superuser.com/questions/1634286/how-do-i-increase-the-max-open-files-in-macos-big-sur)
    [A launchd Tutorial](https://www.launchd.info/)
    [macos - Values from sysctl -A don't match /etc/sysctl.conf even after restart - Unix & Linux Stack Exchange](https://unix.stackexchange.com/questions/689295/values-from-sysctl-a-dont-match-etc-sysctl-conf-even-after-restart/710645)

    [macos - "No space left on drive" when trying to allocate more shared memory - Stack Overflow](https://stackoverflow.com/questions/70884304/no-space-left-on-drive-when-trying-to-allocate-more-shared-memory/73058877)
  2. @pythoninthegrass pythoninthegrass revised this gist Jul 20, 2022. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -58,3 +58,5 @@ Ran across a `fio` shm error: `failed to setup shm segment` while benchmarking S
    [c++ - Shared memory "Too many open files" but ipcs doesn't show many allocations - Stack Overflow](https://stackoverflow.com/questions/70988547/shared-memory-too-many-open-files-but-ipcs-doesnt-show-many-allocations)
    [kernel - How do I increase the max open files in macOS Big Sur? - Super User](https://superuser.com/questions/1634286/how-do-i-increase-the-max-open-files-in-macos-big-sur)
    [A launchd Tutorial](https://www.launchd.info/)
  3. @pythoninthegrass pythoninthegrass revised this gist Jul 20, 2022. 1 changed file with 16 additions and 8 deletions.
    24 changes: 16 additions & 8 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -33,14 +33,22 @@ Ran across a `fio` shm error: `failed to setup shm segment` while benchmarking S
    ```
    * If the `shmmni` or other values didn't change, a reboot is in order
    * Known good output when values are changed successfully
    ```bash
    Ξ» 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
    ```
    ```
    Ξ» 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
    ```
    ## Sources
    [macos - Values from sysctl -A don't match /etc/sysctl.conf even after restart - Unix & Linux Stack Exchange](https://unix.stackexchange.com/questions/689295/values-from-sysctl-a-dont-match-etc-sysctl-conf-even-after-restart)
  4. @pythoninthegrass pythoninthegrass revised this gist Jul 20, 2022. 1 changed file with 9 additions and 0 deletions.
    9 changes: 9 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -32,6 +32,15 @@ Ran across a `fio` shm error: `failed to setup shm segment` while benchmarking S
    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
    ```bash
    Ξ» 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
    ```
    ## Sources
    [macos - Values from sysctl -A don't match /etc/sysctl.conf even after restart - Unix & Linux Stack Exchange](https://unix.stackexchange.com/questions/689295/values-from-sysctl-a-dont-match-etc-sysctl-conf-even-after-restart)
  5. @pythoninthegrass pythoninthegrass revised this gist Jul 20, 2022. 1 changed file with 11 additions and 2 deletions.
    13 changes: 11 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@ As of at least macOS Catalina 10.15.3, `/etc/sysctl.conf` values are no longer r

    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](https://developer.apple.com/documentation/security/disabling_and_enabling_system_integrity_protection)
    * Disclaimer from Apple
    * **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.
    @@ -31,4 +31,13 @@ Ran across a `fio` shm error: `failed to setup shm segment` while benchmarking S
    # recheck sysctl values
    sysctl -a | grep shm
    ```
    * If the `shmmni` or other values didn't change, a reboot is in order
    * If the `shmmni` or other values didn't change, a reboot is in order
    ## Sources
    [macos - Values from sysctl -A don't match /etc/sysctl.conf even after restart - Unix & Linux Stack Exchange](https://unix.stackexchange.com/questions/689295/values-from-sysctl-a-dont-match-etc-sysctl-conf-even-after-restart)

    [Setting shared memory in Catalina | Apple Developer Forums](https://developer.apple.com/forums/thread/669625)

    [c++ - Shared memory "Too many open files" but ipcs doesn't show many allocations - Stack Overflow](https://stackoverflow.com/questions/70988547/shared-memory-too-many-open-files-but-ipcs-doesnt-show-many-allocations)
    [kernel - How do I increase the max open files in macOS Big Sur? - Super User](https://superuser.com/questions/1634286/how-do-i-increase-the-max-open-files-in-macos-big-sur)
  6. @pythoninthegrass pythoninthegrass created this gist Jul 20, 2022.
    34 changes: 34 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    # com.startup.sysctl.plist

    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](https://developer.apple.com/documentation/security/disabling_and_enabling_system_integrity_protection)
    * 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.
    * Download `com.startup.sysctl.plist`
    * Move to `/Library/LaunchDaemons/com.startup.sysctl.plist`
    * Load the PLIST after a few housekeeping items
    ```bash
    # 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
    27 changes: 27 additions & 0 deletions com.startup.sysctl.plist
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    <?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">
    <!-- DISABLE SIP TO USE: macOS Recovery > Utilities > Terminal > `csrutil disable` > Reboot -->
    <plist version="1.0">
    <dict>
    <key>Label</key>
    <string>com.startup.sysctl</string>
    <key>LaunchOnlyOnce</key>
    <true/>
    <key>StandardErrorPath</key>
    <string>/private/tmp/sysctl.err</string>
    <key>StandardOutPath</key>
    <string>/private/tmp/sysctl.out</string>
    <key>ProgramArguments</key>
    <array>
    <string>/usr/sbin/sysctl</string>
    <string>-w</string>
    <string>kern.sysv.shmmax=4194304</string>
    <string>kern.sysv.shmmin=1</string>
    <string>kern.sysv.shmmni=32</string>
    <string>kern.sysv.shmseg=8</string>
    <string>kern.sysv.shmall=1024</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    </dict>
    </plist>