0

I'm on Mac Monterey 12.1 and increased my shared memory limits in /etc/sysctl.conf file:

kern.sysv.shmmax: 16777216
kern.sysv.shmmin: 1
kern.sysv.shmmni: 128
kern.sysv.shmseg: 512
kern.sysv.shmall: 4096
security.mac.posixshm_enforce: 1
security.mac.sysvshm_enforce: 1

and restarted (and shut down) the machine. However, after restarting when i run sysctl -A | grep shm it shows values different to the file:

kern.sysv.shmall: 1024
kern.sysv.shmmax: 4194304
kern.sysv.shmmin: 1
kern.sysv.shmmni: 32
kern.sysv.shmseg: 8
security.mac.posixshm_enforce: 1
security.mac.sysvshm_enforce: 1

even though /etc/sysctl.conf still shows the changes as persisted.

In other words, I have no idea where sysctl -A | grep shm is getting these values from.

Does anyone know where I need to modify them?

2 Answers 2

0
  1. Download file .plist https://anonfiles.com/3eGaR6kfya/com.startup.sysctl_plist
  2. Move the downloaded file to /Library/LaunchDaemons/com.startup.sysctl.plist
  3. Launch the terminal and write two commands in turn: first "sudo chown root:wheel /Library/LaunchDaemons/com.startup.sysctl.plist" and then "sudo launchctl load -w /Library/LaunchDaemons/com.startup.sysctl.plist"
  4. Reboot the system.
1
  • Why reboot? This is not windows...
    – Nils
    Jun 9, 2022 at 21:56
0

Kudos to alexander-dankin for setting me on the right path.

Per OP, I had a similar issue with fio benchmarking and solved it with a modified version of what Alexander posted.

Below are the steps that are somewhat abridged and tailored to user997112's question.

Steps

  • 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.

  • Create /Library/LaunchDaemons/com.startup.sysctl.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">
    <!-- 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=16777216</string>
                <string>kern.sysv.shmmin=1</string>
                <string>kern.sysv.shmmni=128</string>
                <string>kern.sysv.shmseg=512</string>
                <string>kern.sysv.shmall=4096</string>
            </array>
            <key>RunAtLoad</key>
            <true/>
        </dict>
    </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
    

Sources

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .