Subject: bug#22814: 25.0.91; Emacs runs out of file descriptors on OS X

From: David Caldwell <[email-masked]>
Date: Fri, 26 Feb 2016 01:05:56 -0800

On 2/26/16 12:34 AM, Michael Albinus wrote:
> David Caldwell <[email-masked]> writes:
>> I have a large emacs desktop file (600+ buffers at the moment). Emacs
>> 24.5 would open all the buffers just fine, but 25.0.91 (and 90)
>> apparently don't close the file after reading the buffer (or maybe it's
>> part of the new kqueue stuff?). By default OS X limits the number of
>> file descriptors per process to 256. So trying to open my large desktop
>> file gets it into a stuck state where it cannot open any more files
>> after it loads the first 240ish buffers.
>
> You are using "global-auto-revert-mode: t". kqueue does not support a
> directory monitor, therefore it starts a new file notification monitor
> for every single file, indeed.

Ah, I see. Maybe the FSEvents API[1] would be better in this case?

> I believe it is questionable to run auto-revert-mode for so many
> files,

> but that's your choice.=20

It's just stat()s, right? Those are really fast, especially on my ssd.
At any rate, I've never noticed any slowdown. I guess I always assumed
it would check only for buffers I was displaying, rather than ones in
the background (because why would I care if a buffer I couldn't see had
stale data in it?).

> In order to suppress kqueue running for auto-revert-mode, you shall 
> set auto-revert-use-notify to nil.

Thanks! That indeed does the trick. I'm back to 24.5 numbers of fds open.

> Maybe there are means in OS X to increase the number of file
> descriptors for Emacs, don't know. I don't use OS X.

`ulimit -u 10000` was my temporary work-around, but I had to remember to
do it every time I booted or emacs would hose itself (I don't think I
ever successfully remembered).

> I will add a note to the Emacs manual.

Thanks.

-David