Mitigations/tunables for reducing netlink loss?

Trisha Biswas tbiswas at fastly.com
Tue Sep 21 17:51:25 CEST 2021


Hi all,

We are using the following patch to increase the netlink receive buffer
size to 2 MB. It has certainly helped reduce the instances of buffer
overruns in either kernel async notifications or ack processing. Since more
folks are having the same issue, maybe this patch could be added upstream?

Thanks,
Trisha

diff --git a/lib/socket.h b/lib/socket.h
index 96fedeeb..71fdcc1e 100644
--- a/lib/socket.h
+++ b/lib/socket.h
@@ -93,6 +93,7 @@ void sk_set_rbsize(sock *s, uint val); /* Resize RX
buffer */
 void sk_set_tbsize(sock *s, uint val); /* Resize TX buffer, keeping
content */
 void sk_set_tbuf(sock *s, void *tbuf); /* Switch TX buffer, NULL-> return
to internal */
 void sk_dump_all(void);
+void sk_set_rcvbuf(int fd, int val); /* Set socket receive buffer size */

 int sk_is_ipv4(sock *s); /* True if socket is IPv4 */
 int sk_is_ipv6(sock *s); /* True if socket is IPv6 */
diff --git a/sysdep/linux/netlink.c b/sysdep/linux/netlink.c
index fdf3f2db..89bb5a81 100644
--- a/sysdep/linux/netlink.c
+++ b/sysdep/linux/netlink.c
@@ -131,6 +131,7 @@ struct nl_sock
 };

 #define NL_RX_SIZE 8192
+#define RCVBUF_SIZE 2*1024*1024

 #define NL_OP_DELETE 0
 #define NL_OP_ADD (NLM_F_CREATE|NLM_F_EXCL)
@@ -154,6 +155,7 @@ nl_open_sock(struct nl_sock *nl)
       nl->rx_buffer = xmalloc(NL_RX_SIZE);
       nl->last_hdr = NULL;
       nl->last_size = 0;
+      sk_set_rcvbuf(nl->fd, RCVBUF_SIZE);
     }
 }

@@ -2014,6 +2016,7 @@ nl_open_async(void)
       log(L_ERR "Unable to open asynchronous rtnetlink socket: %m");
       return;
     }
+  sk_set_rcvbuf(fd, RCVBUF_SIZE);

   bzero(&sa, sizeof(sa));
   sa.nl_family = AF_NETLINK;
diff --git a/sysdep/linux/sysio.h b/sysdep/linux/sysio.h
index e21ff487..93b5de7f 100644
--- a/sysdep/linux/sysio.h
+++ b/sysdep/linux/sysio.h
@@ -266,3 +266,10 @@ sk_set_priority(sock *s, int prio)
   return 0;
 }

+void
+sk_set_rcvbuf(int fd, int val)
+{
+  int len = val;
+  if (setsockopt(fd, SOL_SOCKET, SO_RCVBUFFORCE, &len, sizeof(len)) < 0)
+    log(L_WARN "sk_set_rcvbuf: Could not set RCVBUF to %d", len);
+}

On Tue, Sep 21, 2021 at 7:27 AM Alexander <aldem-bird.201704 at nk7.net> wrote:

> On 2021-09-21 09:53, Maria Matejka wrote:
>
> > Here somebody suggests increasing net.core.rmem_default before starting
> > BIRD.
> >
> > https://bird.network.cz/pipermail/bird-users/2017-September/011541.html
>
> Why not add an option with socket buffer size and force for netlink
> socket when specified? Like:
>
>    setsockopt(fd, SOL_SOCKET, SO_RCVBUFFORCE, &buffer_size,
> sizeof(buffer_size));
>
> SO_RCVBUFFORCE (available in kernels since 2.6.14) ignores limits in
> net.core.rmem_max
> so there is no need to mangle with settings, especially default settings
> (rmem_default)
> as it will affect *all* applications.
>
> Those who are lucky enough to run recent kernels without bugs could
> simply start bird
> with custom buffer size.
>
> /Al
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://trubka.network.cz/pipermail/bird-users/attachments/20210921/954167d4/attachment.htm>


More information about the Bird-users mailing list