From nobody Wed Apr 1 22:33:31 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4fmKWv4tq4z6YfcX for ; Wed, 01 Apr 2026 22:33:31 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R12" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4fmKWv2gxDz3whT for ; Wed, 01 Apr 2026 22:33:31 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1775082811; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=3NtEBc69KgmgeMEcHgHhmI0BSNorT/IbvVPbgZH4PfU=; b=wfrh+ARR8yTbGATjbTCn2EKXyJ8i+t/J91/RW6BEpEaVV6ctb1Nfdi1MdY6lIyDcfp5ZH5 3ZFAUGsimJPs4EeXbp8NjfSIit09L2QBUkx3TUk+SHBZI+vTHBRyvUz26T5BKm6ZCGovNr OTiv5pAlnL72Xg+84iDefKVItm3V13z0nF1wOSbwEJXapGrN1E+sM1rBiXP2WTcdBr9imj a0enLCoFHhLfYjXV/Y4KyY94SXtGUgoqtc6FBSb01PtNAwsvzA/yFz0BkBlWoWB0inY1nm qCIcJnBPiqcZmeHW6qafyPPMv7sqFpGCPTuiCvczzVVJBhV/y8KqJYUjuzM17A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1775082811; a=rsa-sha256; cv=none; b=Cv7HzsymSuWFAVdtbmhJmaYWJf+fiaAaELGQTD9ef2E1ZE48ciOkXohr6ayugNxK79zdee NMry5Avwj2TnfnSb+k162AkRU6CgT0QrGSYgPJs/56HML+NFzRKNnT2RAdCPcscjY5iE3h /urgza/wtkTQOBNMaiX3/Tz8hPIQz3DU/j5HYxproNBzIX92JDIwqDx6hhjfHoSYPikTdP jV+Im8UQKlgiTi50TKgqYufVky288LDGEm56aBAHEKEkfoNEQt0oCSdQGiQvRt/VeLVK2E 4yGApXRET6uee2Er8k2xLTiL67xMAQ87Fvrq61+CyWH1STGpMVxavY53jxLfSg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1775082811; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=3NtEBc69KgmgeMEcHgHhmI0BSNorT/IbvVPbgZH4PfU=; b=Yfat4hWtgulskL8zv2TOVavLfaWJvci37dLJF6u7xyE3oAEA1oZxA8l0RlGKK5LO2LG3a2 UCVFQnFEsGwfyy0V+YQXQgmQIEHThQDyQm4xhpFKdsz8egLia4NDNwQLzRWPjoF6PzIUzG 6jgeHwJiExC5xSvjQa6V4kF8yJOhXEnbQHtLUEkz+/6ICEBlohv3vNhbau/nWYR0sa4Nxk cX6g1p50gxA/Ni3OzZ2Y2bOclzJmcq7FiwHJeMSoPiFgAWNRetflm9HsTzdp6f5iG0Y/0N OMCakgZYHmX4lJpnMaM7OC9KtedqD+Tq1u6kNzA1rQ3Qmkk/uy2mlVheaUR7EQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4fmKWv1L2Yzbpv for ; Wed, 01 Apr 2026 22:33:31 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 43e40 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 01 Apr 2026 22:33:31 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: ff1050d2a366 - main - kqueue: simplify knote_fdclose() List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: ff1050d2a366bd288a6ebbf63f98003272513f92 Auto-Submitted: auto-generated Date: Wed, 01 Apr 2026 22:33:31 +0000 Message-Id: <69cd9d3b.43e40.112feed2@gitrepo.freebsd.org> The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=ff1050d2a366bd288a6ebbf63f98003272513f92 commit ff1050d2a366bd288a6ebbf63f98003272513f92 Author: Kyle Evans AuthorDate: 2026-04-01 22:30:48 +0000 Commit: Kyle Evans CommitDate: 2026-04-01 22:30:48 +0000 kqueue: simplify knote_fdclose() The influx logic in knote_fdclose() is a little misguided, the resulting wakeup() call should always be redundant: knote_drop_detached() will always issue a wakeup before it returns, so anything waiting on *that* knote that had entered fluxwait should have been woken up then. This is the obvious divergence from the other influx/wakeup pattern in the implementation, which will kn_influx-- and then issue the wakeup after it has processed all of the knotes it can make progress on. While we're here, the kq_knlist cannot shrink, so we can avoid that condition in the loop and avoid potentially excessive wakeups from fluxwait on kqueues that we didn't touch. Reviewed by: kib, markj Differential Revision: https://reviews.freebsd.org/D56210 --- sys/kern/kern_event.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/sys/kern/kern_event.c b/sys/kern/kern_event.c index 6af53cf6cd91..485123989319 100644 --- a/sys/kern/kern_event.c +++ b/sys/kern/kern_event.c @@ -2836,7 +2836,6 @@ knote_fdclose(struct thread *td, int fd) struct filedesc *fdp = td->td_proc->p_fd; struct kqueue *kq; struct knote *kn; - int influx; FILEDESC_XLOCK_ASSERT(fdp); @@ -2846,22 +2845,25 @@ knote_fdclose(struct thread *td, int fd) */ TAILQ_FOREACH(kq, &fdp->fd_kqlist, kq_list) { KQ_LOCK(kq); + if (kq->kq_knlistsize <= fd || + SLIST_EMPTY(&kq->kq_knlist[fd])) { + KQ_UNLOCK(kq); + continue; + } -again: - influx = 0; - while (kq->kq_knlistsize > fd && - (kn = SLIST_FIRST(&kq->kq_knlist[fd])) != NULL) { + while ((kn = SLIST_FIRST(&kq->kq_knlist[fd])) != NULL) { if (kn_in_flux(kn)) { - /* someone else might be waiting on our knote */ - if (influx) - wakeup(kq); + /* + * Wait for this knote to stabilize, it could be + * the case that it's in the process of being + * dropped anyways. + */ kq->kq_state |= KQ_FLUXWAIT; msleep(kq, &kq->kq_lock, PSOCK, "kqflxwt", 0); - goto again; + continue; } kn_enter_flux(kn); KQ_UNLOCK(kq); - influx = 1; knote_drop(kn, td); KQ_LOCK(kq); }