Page MenuHomeFreeBSD

kqueue: compare against the size in kqueue_expand
ClosedPublic

Authored by kevans on Wed, Apr 1, 3:08 AM.

Details

Summary

This is a cosmetic change, rather than a functional one: comparing the
knlistsize against the fd requires a little bit of mental gymnastics to
confirm that this is fine and not doing unnecessary work in some cases.

Notably, one must consider that kq_knlistsize only grows in KQEXTENT
chunks, which means that concurrent threads trying to grow the kqueue
to consecutive fds will usually not result in the list being replaced
twice. One can also more clearly rule out classes of arithmetic
problems in the final else branch.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

kevans requested review of this revision.Wed, Apr 1, 3:08 AM
kib added inline comments.
sys/kern/kern_event.c
2028

I would add there MPASS(kq->kq_knlistsize > fd); simply because we can.
Might be, not there, but right before KQ_UNLOCK()

This revision is now accepted and ready to land.Wed, Apr 1, 3:20 AM
markj added inline comments.
sys/kern/kern_event.c
2015–2016

I'd feel better if this code was written as:

size = atomic_load_int(&kq->kq_knlistsize);
if (size <= fd) {
    do
        size += KQEXTENT;
    while (size <= fd);
    ...
sys/kern/kern_event.c
2028

I've added one locally before KQ_UNLOCK() and spelled it: error != 0 || kq->kq_knlistsize > fd