Attention is currently required from: Arne Schwabe.

Hello Arne Schwabe,

I'd like you to do a code review.
Please visit

    https://gerrit.openvpn.net/c/openvpn/+/2050?usp=email

to review the following change.


Change subject: multi_io: avoid redundant event_ctl() calls in multi_io_wait()
......................................................................

multi_io: avoid redundant event_ctl() calls in multi_io_wait()

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 <[email protected]>
---
M src/openvpn/forward.h
M src/openvpn/multi_io.c
M src/openvpn/multi_io.h
M src/openvpn/socket.h
4 files changed, 12 insertions(+), 6 deletions(-)



  git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/50/2050/1

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 8580d7d..59afb51 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;

--
To view, visit https://gerrit.openvpn.net/c/openvpn/+/2050?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I4379a167419d464c000dca3c5c032aaebb6dac73
Gerrit-Change-Number: 2050
Gerrit-PatchSet: 1
Gerrit-Owner: Gianmarco De Gregori <[email protected]>
Gerrit-Reviewer: Arne Schwabe <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: Arne Schwabe <[email protected]>
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
  • [Openvpn-devel] [S] C... Gianmarco De Gregori (Code Review) via Openvpn-devel

Reply via email to