<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div>Greetings,</div><div><br></div><div>I'm reaching out because of an issue with the JVM on MacOS that is hitting us a large scale. It started in MacOS 13 but got really worse in 14.1. We basically now need to use -XX:-MaxFDLimit on MacOS for everything with a classpath of more then 10k jars (monolith). That applies to the Java app itself as well as any Java based IDE (Eclipse, IntelliJ) or build tool.</div><div><br></div><div>The reason is that the MaxFDLimit implementation on Mac is broken in the JVM. The JVM is applying a lower limit to itself. We discovered the -XX:-MaxFDLimit solution after our old workarounds of increasing the open files on MacOS stopped working.</div><div><br></div><div>We discovered it in the Bazel repository:</div><div>https://github.com/bazelbuild/bazel/blob/699208763906fbd4b5e46e445b637436ee2293aa/src/main/cpp/startup_options.cc#L589-L597</div><div><br></div><div> // Disable the JVM's own unlimiting of file descriptors. We do this</div><div> // ourselves in blaze.cc so we want our setting to propagate to the JVM.</div><div> //</div><div> // The reason to do this is that the JVM's unlimiting is suboptimal on</div><div> // macOS. Under that platform, the JVM limits the open file descriptors</div><div> // to the OPEN_MAX constant... which is much lower than the per-process</div><div> // kernel allowed limit of kern.maxfilesperproc (which is what we set</div><div> // ourselves to).</div><div><br></div><div><br></div><div>In older versions of macOS we used a launch daemon to increase the limit:</div><div>❯ cat /Library/LaunchDaemons/limit.maxfiles.plist</div><div><?xml version="1.0" encoding="UTF-8"?></div><div><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"></div><div><plist version="1.0"></div><div> <dict></div><div> <key>Label</key></div><div> <string>limit.maxfiles</string></div><div> <key>ProgramArguments</key></div><div> <array></div><div> <string>/bin/bash</string></div><div> <string>-c</string></div><div> <string>launchctl limit maxfiles unlimited unlimited ; launchctl limit maxfiles 1000000 2147483647</string></div><div> </array></div><div> <key>RunAtLoad</key></div><div> <true/></div><div> <key>ServiceIPC</key></div><div> <false/></div><div> </dict></div><div></plist> </div><div><br></div><div><br></div><div>This stopped working in MacOS 14.1</div><div><br></div><div> ❯ sudo launchctl limit maxfiles 1000000 2147483647</div><div>Could not set resource limits: 150: Operation not permitted while System Integrity Protection is engaged</div><div><br></div><div><br></div><div>We got an interesting info from Apple:</div><div><br></div><div>Defaults</div><div>Soft - 65535</div><div>Hard - unlimited</div><div><br></div><div>Per Apple - The unlimited keyword is now an alias for 2147483647 (INT32_MAX) where before it was an alias for 10240 (OPEN_MAX).</div><div><br></div><div>With SIP enabled, the soft limit can be raised, but not lowered once it’s been raised. This is by design and will generate the "Could not set resource limits".</div><div><br></div><div>So perhaps the code in the JVM should be changed to INT32_MAX?</div><div><br></div><div>The thing is, we cannot add the flag uniquely. For example, on older Linux installations (eg., Ubuntu 20) we noticed the <font color="#000000"><span style="caret-color: rgb(0, 0, 0);">-XX:-MaxFDLimit is harmful, i.e. we actually do need the JVM to increase its file handles.</span></font></div><div><span style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);"><br></span></div><div><font color="#000000"><span style="caret-color: rgb(0, 0, 0);">I found a couple old bugs but nothing actionable. Can this issue be revisited? I am not able to open a JDK bug, though.</span></font></div><div><font color="#000000"><span style="caret-color: rgb(0, 0, 0);"><br></span></font></div><div><font color="#000000"><span style="caret-color: rgb(0, 0, 0);">Thanks a lot!</span></font></div><div><font color="#000000"><span style="caret-color: rgb(0, 0, 0);"><br></span></font></div><div><font color="#000000"><span style="caret-color: rgb(0, 0, 0);">-Gunnar</span></font></div><div><br></div><div>
<meta charset="UTF-8"><div><br>-- <br>Gunnar Wagenknecht<br>gunnar@wagenknecht.org, http://guw.io/<br><br><br></div>
</div>
<br></body></html>