From time to time I see complaints about Emacs having too many open files on macOS. This is because Apple has set the default number of open files for a process at 1024. Sadly, you can’t fix this by upping the limit with ulimit
.
There is, however, a fix although it’s a bit complicated. You have to make adjustments to both macOS and Emacs. Happily Jiacai Liu has a step-by-step procedure for upping the limit. The TL;DR is that you have to add a couple of files to your macOS installation and go through a fussy operation to get them installed. Then you have to recompile Emacs with defines for FD_SETSIZE
and DARWIN_UNLIMITED_SELECT
.
Apparently the problem manifests itself when you’re using Emacs with LSP so if you’re an LSP user, you may have go through the—admittedly painful—process. I haven’t run into this problem yet and part of the reason for this post is to help me remember what to do in case I do. If you’re an Emacs user on macOS, you may want to bookmark Liu’s post in case you run into the problem.