Question

I am using emacs on my mac book pro with Big Sur 11.2.3

And I frequently run into the issue of file descriptors

File watching not possible, no file descriptor left: 975

After several hours of googling the issue I tried several approaches of updating sysctl options. currently, my relevant options are:

kern.maxfiles: 10485760
kern.maxfilesperproc: 1048576
kern.maxproc: 4096
kern.maxfilesperproc: 1048576
kern.maxprocperuid: 8192

and I still get the same error. ulimit -a result:

-t: cpu time (seconds)              unlimited
-f: file size (blocks)              unlimited
-d: data seg size (kbytes)          unlimited
-s: stack size (kbytes)             8192
-c: core file size (blocks)         0
-v: address space (kbytes)          unlimited
-l: locked-in-memory size (kbytes)  unlimited
-u: processes                       2048
-n: file descriptors                1000000
Was it helpful?

Solution

See this code snippet in src/kqueue.c:

  /* Check available file descriptors.  */
#ifdef HAVE_GETRLIMIT
  if (! getrlimit (RLIMIT_NOFILE, &rlim))
    maxfd = rlim.rlim_cur;
  else
#endif /* HAVE_GETRLIMIT  */
    maxfd = 256;

  /* We assume 50 file descriptors are sufficient for the rest of Emacs.  */
  ptrdiff_t watch_list_len = list_length (watch_list);
  if (maxfd - 50 < watch_list_len)
    xsignal2
      (Qfile_notify_error,
       build_string ("File watching not possible, no file descriptor left"),
       make_fixnum (watch_list_len));

I would say that you have registered 975 file notifications in Emacs, which exceeds the maximum number of file descriptors on your system: (975 + 50) > 1024

I have no idea whether you can change this upper limit. However, I believe 975 file notification requests are, hmm, quite high.

Licensed under: CC-BY-SA with attribution
Not affiliated with apple.stackexchange
scroll top