From nobody Mon Apr 13 14:43:23 2026 X-Original-To: dev-commits-src-branches@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 4fvVWw2HF1z6ZGJ5 for ; Mon, 13 Apr 2026 14:43:24 +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 4fvVWv6RvBz3vJ7 for ; Mon, 13 Apr 2026 14:43:23 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1776091403; 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=NRFgeYIiTvlkWp+YBNB3lblJS/sBTCU4USsy6Le0TTk=; b=bH0HCU6txz0DL7ve+rIhhGw+KakI6idhAChIe52OC5NyIrt3AlHVWy8IinD8T6nDXuZRFn QayCn7OhtR5I99ftMASUv5oiSIgnA5bw6idUoDav55TJSAWL1kSAFEElnlUJ4mx0ficLga jKL6cPMkYA3poYsj4UhRVjHEYxUX1LiUTAYgUiMUelR093m3y1jbY4WjCCr6+IQkY0ZIWx 11pdMQB/yQEZ0Go/zPXECY8RVKj8YYTiKoc8OlaVUjjkHQVI4E2cJWrbkhqM5vAC/7ENHZ fCTGT7nlJeEeHZ3gz4KW4MW+ggdUV79OiN+YVPIo84mitZNl9ZfbgnDHdD8mpA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1776091403; a=rsa-sha256; cv=none; b=HYdPn+kyd14HAANuekjAJ7DjvA+kNF4g8rafeFB3MP03vLKad576uR5pGEVQ52JdzM/WFj I4IMCePxn7FV58qKQ9MfC13BNRXNtVXa7AWMUZbyAhEnKguCxOXQBKyqfcA5wDv/RM8zQf FoTVKU+RoTPFiIBhpHjE/1htmbbT3WnvRgA0UjgdjVqrH/JDQXAzM2Oa1TyZx3GGQ0nzAU xMtyJVrXFoSV2/7/SDV6FB5UChTE7zN8dxY+bZGUOuy8hLIxCkU3xEXZZETwW4vwiV9fkz U23xScgSVNMDAvoGVXyxdGt6TOXOz7q2BojnJaJwNY85KnUcppYoGkP/4lF3Ag== 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=1776091403; 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=NRFgeYIiTvlkWp+YBNB3lblJS/sBTCU4USsy6Le0TTk=; b=ejcA5t5S8ySKKTHoLfFtRbOZ4Ipa1XrKjH8iZ0hRUJuQU5UYnoJ6ewbVG8nemuiA3xegbk /C0w5MDYY21pIUlyPSJxOLTdxeFWYrLzmofeTJR0mnGtSB+VUlZUDk3Z7nfFe2V+kQiePL BEWbPmZbFeNSXqfePz+dMJBbym0Rt42/N06FQ+ohO6h60/4wo2LhrKP2/CyxxVuoCpask5 P088SVR8X8EriN10J6gKVAjWw44+cRKVwGexv+kr+iibQZaS/ZgjkcTXAuhdpUMHvmmXhO FZlpwZM1B3pk0OVSY+zxI8PNUV4w2LGK2IVS0x6eHnaukQBKD2RcwvUp8jwHGg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4fvVWv5rSzz1758 for ; Mon, 13 Apr 2026 14:43:23 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 1953a by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 13 Apr 2026 14:43:23 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kyle Evans Subject: git: f206751e1280 - stable/14 - kqueue: simplify knote_fdclose() List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@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/stable/14 X-Git-Reftype: branch X-Git-Commit: f206751e1280410a8c911283a92ee9194a3f1ac6 Auto-Submitted: auto-generated Date: Mon, 13 Apr 2026 14:43:23 +0000 Message-Id: <69dd010b.1953a.3480e59e@gitrepo.freebsd.org> The branch stable/14 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=f206751e1280410a8c911283a92ee9194a3f1ac6 commit f206751e1280410a8c911283a92ee9194a3f1ac6 Author: Kyle Evans AuthorDate: 2026-04-01 22:30:48 +0000 Commit: Kyle Evans CommitDate: 2026-04-13 14:43:15 +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 (cherry picked from commit ff1050d2a366bd288a6ebbf63f98003272513f92) --- 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 4e7ad058e144..a8e59ff408a4 100644 --- a/sys/kern/kern_event.c +++ b/sys/kern/kern_event.c @@ -2684,7 +2684,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); @@ -2694,22 +2693,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); }