svn commit: r287362 - head/sys/kern
Konstantin Belousov
kib at FreeBSD.org
Tue Sep 1 13:21:33 UTC 2015
Author: kib
Date: Tue Sep 1 13:21:32 2015
New Revision: 287362
URL: https://svnweb.freebsd.org/changeset/base/287362
Log:
Clean up the kqueue use of the uma KPI.
Explain why it is fine to not check for M_NOWAIT failures in
kqueue_register(). Remove unneeded check for NULL result from
waitable allocation in kqueue_scan(). uma_free(9) handles NULL
argument correctly, remove checks for NULL. Remove useless cast and
adjust style in knote_alloc().
Sponsored by: The FreeBSD Foundation
MFC after: 2 weeks
Modified:
head/sys/kern/kern_event.c
Modified: head/sys/kern/kern_event.c
==============================================================================
--- head/sys/kern/kern_event.c Tue Sep 1 13:07:27 2015 (r287361)
+++ head/sys/kern/kern_event.c Tue Sep 1 13:21:32 2015 (r287362)
@@ -1105,10 +1105,16 @@ kqueue_register(struct kqueue *kq, struc
if (fops == NULL)
return EINVAL;
- if (kev->flags & EV_ADD)
- tkn = knote_alloc(waitok); /* prevent waiting with locks */
- else
+ if (kev->flags & EV_ADD) {
+ /*
+ * Prevent waiting with locks. Non-sleepable
+ * allocation failures are handled in the loop, only
+ * if the spare knote appears to be actually required.
+ */
+ tkn = knote_alloc(waitok);
+ } else {
tkn = NULL;
+ }
findkn:
if (fops->f_isfd) {
@@ -1310,8 +1316,7 @@ done:
FILEDESC_XUNLOCK(td->td_proc->p_fd);
if (fp != NULL)
fdrop(fp, td);
- if (tkn != NULL)
- knote_free(tkn);
+ knote_free(tkn);
if (fops != NULL)
kqueue_fo_release(filt);
return (error);
@@ -1507,10 +1512,6 @@ kqueue_scan(struct kqueue *kq, int maxev
} else
asbt = 0;
marker = knote_alloc(1);
- if (marker == NULL) {
- error = ENOMEM;
- goto done_nl;
- }
marker->kn_status = KN_MARKER;
KQ_LOCK(kq);
@@ -2385,15 +2386,16 @@ SYSINIT(knote, SI_SUB_PSEUDO, SI_ORDER_A
static struct knote *
knote_alloc(int waitok)
{
- return ((struct knote *)uma_zalloc(knote_zone,
- (waitok ? M_WAITOK : M_NOWAIT)|M_ZERO));
+
+ return (uma_zalloc(knote_zone, (waitok ? M_WAITOK : M_NOWAIT) |
+ M_ZERO));
}
static void
knote_free(struct knote *kn)
{
- if (kn != NULL)
- uma_zfree(knote_zone, kn);
+
+ uma_zfree(knote_zone, kn);
}
/*
More information about the svn-src-head
mailing list