Skip to content

Commit

Permalink
[watchman] use fsevents on osx
Browse files Browse the repository at this point in the history
Summary:
fseventsd uses some low level OS magic to subscribe to filesystem
changes without needing to hold an open descriptor for everything.

This diff makes us use it on OS/X.  For the most part, this diff
is pretty clear.  There are two things that are worth calling out:

* Discovered that we should have put the root number into the cookie filename
  to avoid the potential for cookie filename collisions when we recrawl and rewind
  the tick counter

* We run fsevents in a thread of its own so that we can filter out ignored items and
  test to see if events are available (there is no native "poll" functionality that I can
  find).  This is begging to be refactored and we'll take care of that in a later diff.

Test Plan: `make integration` passes

Reviewers: sid0, fugalh

Reviewed By: fugalh

CC: royw

Differential Revision: https://phabricator.fb.com/D1031495
  • Loading branch information
wez committed Oct 30, 2013
1 parent 9671e95 commit e0762ed
Show file tree
Hide file tree
Showing 7 changed files with 406 additions and 20 deletions.
8 changes: 4 additions & 4 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ also trigger actions (such as rebuilding assets) when matching files change.
Watchman is known to compile and pass its test suite on:

* Linux systems with `inotify`
* OS X and BSDish systems (FreeBSD 9.1, OpenBSD 5.2) that have the
* OS X (uses FSEvents)
* BSDish systems (FreeBSD 9.1, OpenBSD 5.2) that have the
`kqueue(2)` facility
* Illumos and Solaris style systems that have `port_create(3C)`

Expand Down Expand Up @@ -1093,9 +1094,8 @@ haven't actually changed.
### Max OS File Descriptor Limits

The default per-process descriptor limit on current versions of OS X is
extremely low (256!). Since kqueue() requires an open descriptor for each
watched directory, you will very quickly run into resource limits if your trees
are large or if you do not raise the limits in your system configuration.
extremely low (256!). More recent versions of watchman (2.9.2 and later)
use FSEvents and are not so sensitive to descriptor limits.

Watchman will attempt to raise its descriptor limit to match
`kern.maxfilesperproc` when it starts up, so you shouldn't need to mess
Expand Down
5 changes: 4 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
AC_INIT([watchman], [2.9.1], [], [watchman])
AC_INIT([watchman], [2.9.2], [], [watchman])
AC_CANONICAL_TARGET
AM_INIT_AUTOMAKE([dist-bzip2 subdir-objects])

Expand Down Expand Up @@ -167,6 +167,9 @@ AC_CHECK_HEADERS(sys/types.h inttypes.h locale.h port.h sys/inotify.h sys/event.
AC_CHECK_FUNCS(kqueue port_create inotify_init strtoll localeconv)
AC_CHECK_HEADERS(valgrind/valgrind.h)
AC_CHECK_HEADERS(execinfo.h)
AC_CHECK_HEADERS(CoreServices/CoreServices.h, [
LIBS="$LIBS -framework CoreServices"
])
AC_CHECK_FUNCS(backtrace backtrace_symbols)

# Do this after we've looked for functions
Expand Down
6 changes: 4 additions & 2 deletions listener.c
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ static void wakeme(int signo)
unused_parameter(signo);
}

#ifdef HAVE_KQUEUE
#if defined(HAVE_KQUEUE) || defined(HAVE_FSEVENTS)
#ifdef __OpenBSD__
#include <sys/siginfo.h>
#endif
Expand Down Expand Up @@ -691,7 +691,7 @@ bool w_start_listener(const char *path)
hb = gimli_heartbeat_attach();
#endif

#ifdef HAVE_KQUEUE
#if defined(HAVE_KQUEUE) || defined(HAVE_FSEVENTS)
{
struct rlimit limit;
int mib[2] = { CTL_KERN,
Expand Down Expand Up @@ -730,12 +730,14 @@ bool w_start_listener(const char *path)
}

getrlimit(RLIMIT_NOFILE, &limit);
#ifndef HAVE_FSEVENTS
if (limit.rlim_cur < 10240) {
w_log(W_LOG_ERR,
"Your file descriptor limit is very low (%" PRIu64 "), "
"please consult the watchman docs on raising the limits\n",
limit.rlim_cur);
}
#endif
}
#endif

Expand Down
Loading

0 comments on commit e0762ed

Please sign in to comment.