From patchwork Sat Nov 14 16:54:44 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 5698 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:3119:b0:11a:a05e:cb97 with SMTP id e25csp886329laa; Sat, 14 Nov 2026 08:55:01 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErGjDCi0KYQgFubm9NMjMtsP1GbdczAHiPTb2o8uvmfyd5EXq1nds37cMTtPZ1O7Y921AaxOWs4cYmI=@openvpn.net X-Received: by 2002:a05:6830:4391:b0:81e:bb4b:2324 with SMTP id 46e09a7af769-8628990e21cmr5604326a34.26.1794675300775; Sat, 14 Nov 2026 08:55:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794675300; cv=none; d=google.com; s=arc-20260327; b=YeI4LAs+CJNfGfLb7bkvrXB4LrZ5pY1vIlic7k/rjowF81E2vbAJluCQbOCvvX6yl4 tQ2j30v0n2JOXjE0exL4kpPTB2vJhT7Wl/KYVfvQrZitO/7+R1xm9A98R12vBt/0UQeN 9/Yoeo28UZjjghKTrTd6OfYSt897XeqChdBGDE2TCr5yMso7YT1xcuCRksC5fLsfDtH6 vga+KqnNb9bb/x0tFLOS48BD5oQUd84JsgwjiRpzGGfe2W4o0wnQxbNdS0+Hl1uP89Zh ZgdjR6zv8tOM9H3cKW842jnLPorC7enUvyFvQc1K/JyLNC2kpr+8e7/xV19bd5vsKOU3 NRMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:dkim-signature:dkim-signature; bh=jGZszV3M8ObTRCtn4iGwFA8ody6F2YO9DEo0kxTAh/0=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=lK3T++FyYvg7U8bDRwUpSSh2GycxEc9C2vN1Wy42AqsazeV57NFwrZuqdAgGXFcFh0 vGLJwwWHBmISjr+F+OfwaKqdwffLhyuTsX//6UJbUTmkkKLPI3t0cW9wmdPCgCh7n5rf w2lBbxvQ9NKIsg8/r2RxBz8SCiDMDkWwGU/3SFrEtIYSmN2TCD2swsw9bu/TZ3d1DOPk 3XoasV6jEBV+JWzi1ZifOFnzDHgJSfSHpHdm1GbjE1nf+ntALws/hhM0i9fcRRdZGMo1 FTwI/C6B+Am0qzlUpt5cpx8ltst31xSvGqaJB63OQJr3npzblg85MANHqBj5ssBNbzm8 QJ2Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=A9cWejpU; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=RRIzOgjQ; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=IXQjhGEO; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=muc.de Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id 46e09a7af769-86288218b12si9921808a34.53.2026.11.14.08.55.00 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 14 Nov 2026 08:55:00 -0800 (PST) Received-SPF: pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) client-ip=216.105.38.7; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=A9cWejpU; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=RRIzOgjQ; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=IXQjhGEO; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=muc.de DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.sourceforge.net; s=beta; h=Content-Transfer-Encoding:Content-Type: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Subject:MIME-Version:References:In-Reply-To:Message-ID:Date:To:From:Sender: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=jGZszV3M8ObTRCtn4iGwFA8ody6F2YO9DEo0kxTAh/0=; b=A9cWejpUH6mmmo yEuxDNGlUIhwLWuHbtiYqE5019lUUXZ5jlErDMKDyhK7k9RF2fNb09+y0h9nIiksYzMi11ABTgSH8 zaDthgvlmUB3OJkxw2gxLncHINyxhT0o7bqq012FLvTCJsLAv+qhk+MQtoJhJ3CgovEkfGx60VeQd iuk=; Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.100.1) (envelope-from ) id 1xSH1n-000000005pc-3Jxq; Sat, 14 Nov 2026 16:54:59 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.100.1) (envelope-from ) id 1xSH1m-000000005pN-0JoA for openvpn-devel@lists.sourceforge.net; Sat, 14 Nov 2026 16:54:58 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Unsubscribe-Post:List-Subscribe:List-Post:List-Owner:List-Archive; bh=HQxvjGFWgTiA7rHpxxrTpDmfBcBaILg3ZuXybi0Yevs=; b=RRIzOgjQ38HUWOwXZJiMbXKgt5 f9heY6QxhQR7/kkZXI/1WozoR7Pg6KeOrEwPriTX2cM1gjdVyuyUcpF7VTmkx0kIhz0ra2XXd1ybz TDANGOgjnCjYEZ4bwyZID00bgSPWHvTqDTTBNodwENj7LgFHpUKT8C8BpRJTSi0wbwDg=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Unsubscribe-Post: List-Subscribe:List-Post:List-Owner:List-Archive; bh=HQxvjGFWgTiA7rHpxxrTpDmfBcBaILg3ZuXybi0Yevs=; b=IXQjhGEOlE3/iwRz6aAwi4IaY+ +NZgW/a0tNnwdcB/b6WEPaMX0YUYoyf6bPiMQzmWS9f0fpLGdox1CLwUuiJMFUJ/t6vynYnOKDSmQ ygfj3GsGPEs4y2hYJTgRHlJvukbjekDi09gLM4eKPnkJwMCtCr0uV2XXEVhruapGeFvM=; Received: from [193.149.48.129] (helo=blue.greenie.muc.de) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.100.1) id 1xSH1k-000000002Bn-21Pb for openvpn-devel@lists.sourceforge.net; Sat, 14 Nov 2026 16:54:58 +0000 Received: from blue.greenie.muc.de (localhost [127.0.0.1]) by blue.greenie.muc.de (8.18.1/8.18.1) with ESMTP id 6AEGsnk3008016 for ; Sat, 14 Nov 2026 17:54:50 +0100 Received: (from gert@localhost) by blue.greenie.muc.de (8.18.2/8.18.1/Submit) id 6AEGsnpQ008015 for openvpn-devel@lists.sourceforge.net; Sat, 14 Nov 2026 17:54:49 +0100 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Sat, 14 Nov 2026 17:54:44 +0100 Message-ID: <20261114165449.8002-1-gert@greenie.muc.de> X-Mailer: git-send-email 2.55.0 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Score: 1.3 (+) X-Spam-Report: Spam detection software, running on the system "sfi-spamd-2.hosts.colo.sdot.me", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From: Gianmarco De Gregori multi_io_wait() registered each server UDP socket through multi_io_process_flags(), which calls socket_set() without a persistent cache and tun_set() once more for every UDP socket, also without a cac [...] Content analysis details: (1.3 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 1.3 RDNS_NONE Delivered to internal network by a host with no rDNS X-Headers-End: 1xSH1k-000000002Bn-21Pb Subject: [Openvpn-devel] [PATCH v3] multi_io: avoid redundant event_ctl() calls in multi_io_wait() X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: 1881853448185681260 X-GMAIL-MSGID: 1881853448185681260 From: Gianmarco De Gregori multi_io_wait() registered each server UDP socket through multi_io_process_flags(), which calls socket_set() without a persistent cache and tun_set() once more for every UDP socket, also without a cache. Both ended up in an event_ctl() on every loop iteration even though nothing changed. Now that the UDP sockets and the tun device are only ever armed for reading, set them directly with EVENT_READ, caching the UDP socket rwflags in the new link_socket.rwflags_persistent and the tun ones in multi_io->tun_rwflags. On a server with two UDP and one TCP listener this removes the remaining epoll_ctl() calls from the loop (syscalls per received packet 4.64 -> 3.36, UDP only 5.29 -> 3.77); at saturation the server delivers 2-7% more traffic with UDP and uses 4-13% less CPU at a fixed load. With --enable-async-push the inotify descriptor was also registered on every iteration; register it once (1504 -> 12 epoll_ctl() with deferred auth). Change-Id: I4379a167419d464c000dca3c5c032aaebb6dac73 Signed-off-by: Gianmarco De Gregori Acked-by: Razvan Cojocaru Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2050 --- This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master. Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2050 This mail reflects revision 3 of this Change. Acked-by according to Gerrit (reflected above): Razvan Cojocaru diff --git a/src/openvpn/forward.h b/src/openvpn/forward.h index 375635b..2b29f69 100644 --- a/src/openvpn/forward.h +++ b/src/openvpn/forward.h @@ -73,8 +73,7 @@ * Evaluates the current I/O state (`flags`) and context mode to determine * which READ or WRITE events to register in the event loop. * - * @note This function gets called from client instances from @c io_wait() - * and from p2mp (Point-to-multipoint) instances in @c multi_io_wait(). + * @note This function gets called from @c io_wait(). * * @param c Pointer to the core context. * @param es The event set where descriptors are registered. diff --git a/src/openvpn/multi_io.c b/src/openvpn/multi_io.c index 50c95b5..2a88356d 100644 --- a/src/openvpn/multi_io.c +++ b/src/openvpn/multi_io.c @@ -136,7 +136,6 @@ multi_io_wait(struct multi_context *m) { int status; - unsigned int *persistent = &m->multi_io->tun_rwflags; for (int i = 0; i < m->top.c1.link_sockets_num; i++) { @@ -144,7 +143,7 @@ if (proto_is_dgram(sock->info.proto)) { - multi_io_process_flags(&m->top, m->multi_io->es, sock, IOW_READ | IOW_WAIT_SIGNAL); + socket_set(sock, m->multi_io->es, EVENT_READ, &sock->ev_arg, &sock->rwflags_persistent); } else if (!tuntap_is_dco_win(m->top.c1.tuntap)) { @@ -152,7 +151,7 @@ } } - tun_set(m->top.c1.tuntap, m->multi_io->es, EVENT_READ, MULTI_IO_TUN, persistent); + tun_set(m->top.c1.tuntap, m->multi_io->es, EVENT_READ, MULTI_IO_TUN, &m->multi_io->tun_rwflags); #if defined(ENABLE_DCO) dco_event_set(&m->top.c1.tuntap->dco, m->multi_io->es, MULTI_IO_DCO); #endif @@ -167,7 +166,11 @@ #ifdef ENABLE_ASYNC_PUSH /* arm inotify watcher */ - event_ctl(m->multi_io->es, m->top.c2.inotify_fd, EVENT_READ, MULTI_IO_FILE_CLOSE_WRITE); + if (!m->multi_io->inotify_set) + { + event_ctl(m->multi_io->es, m->top.c2.inotify_fd, EVENT_READ, MULTI_IO_FILE_CLOSE_WRITE); + m->multi_io->inotify_set = true; + } #endif status = diff --git a/src/openvpn/multi_io.h b/src/openvpn/multi_io.h index e178240..6c7fd11 100644 --- a/src/openvpn/multi_io.h +++ b/src/openvpn/multi_io.h @@ -55,6 +55,7 @@ int n_esr; int maxevents; unsigned int tun_rwflags; + bool inotify_set; #ifdef ENABLE_MANAGEMENT unsigned int management_persist_flags; #endif diff --git a/src/openvpn/socket.h b/src/openvpn/socket.h index 52e09c9..e320ff3 100644 --- a/src/openvpn/socket.h +++ b/src/openvpn/socket.h @@ -177,6 +177,9 @@ /* used for long-term queueing of pre-accepted socket listen */ bool listen_persistent_queued; + /* last rwflags set on the shared server-side UDP socket */ + unsigned int rwflags_persistent; + const char *remote_host; const char *remote_port; const char *local_host;