kevent and related stuff

andi payn andi_payn at
Thu Oct 30 07:54:11 PST 2003

First, let me mention that I'm not nearly as experienced coding for *BSD
as for linux, so I may ask some stupid questions.

I've been looking at the fam port, and this has brought up a whole slew
of questions. I'm not sure if all of them are appropriate to this list,
but I don't know who else to ask, so....

First, some background: On Irix and Linux, fam works by asking the
kernel to send it a signal whenever the specified accesses occur. On
FreeBSD, since there is no imon interface and no dnotify fcntl, it
instead works by periodically stating all of the files it's
watching--which is obviously not as good. The fam FAQ suggests that
FreeBSD users should adapt fam to use the kevent interface. 

I looked into kevent, and it seems like there are a number of problems
that lead me to suspect that this is a really stupid idea. And yet, I'd
assume that someone on the fam team at SGI and/or one of the outside fam
developers would know FreeBSD at least as well as me. Therefore, I'm
guessing I'm missing something here. So, any ideas anyone can offer
would be very helpful.

So, here's the questions I have:

* I think (but I'm not sure) that kevent doesn't notify at all if the
only change to a file is its ATIME. If I'm right, this makes kevent
completely useless for fam. Adding a NOTE_ACCESS or something similar
would fix this. Since I'm pretty new to FreeBSD: What process do I go
through to figure out whether anyone else wants this, whether the
interface I've come up with is acceptable, etc.? And, once I write the
code, do I submit it as a pr?

* The kevent mechanism doesn't monitor directories in a sufficient way
to make fam happy. If you change a file in a directory that you're
watching, unlike imon or dnotify, kevent won't see anything worth
reporting at all. This means that for directory monitoring, kevent is
useless as-is. Again, if I wanted to patch kevent to provide this
additional notification, would others want this?

* When two equivalent events appear in the queue, kevent aggregates
them. This means that if there are two updates to a file since the last
time you checked, you'll only see the most recent one. For some uses of
fam (keeping a folder window up to date), this is what you want; for
others (keeping track of how often a file is read), this is useless. The
only solution I can think of is to add an additional flag, or some other
way to specify that you want duplicated events.

* Unlike imon and dnotify, kevent doesn't provide any kind of callback
mechanism; instead, you have to poll the queue for events. Would it be
useful to specify another flag/parameter that would tell the kernel to
signal the monitoring process whenever an event is available? (It would
certainly make the fam code easier to write--but if it's not useful
anywhere else, that's probably not enough.)

* The kevent vnode stuff apparently only works on UFS. And it looks like
it would be a major project to port it to other filesystems. Would this
be useful for anything other than improving fam? What about a port of
the imon kernel interface (and/or the dnotify fcntl) to FreeBSD instead?

* The kqueue doesn't appear to have any maximum size. If this is true,
the dnotify/fam problem where you get hideous errors from overflowing
queues wouldn't be an issue, but you could instead end up wasting
massive amounts of memory in the kernel if you didn't get around to
reading the queue.... Which is it?

Any answers, or pointers to where I can find these answers, would be
greatly appreciated.

More information about the freebsd-hackers mailing list