From ed82b6bcb349d96fb5eecc44ca3c8f93a3c63cfd Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 2 Dec 2016 14:57:23 +0100 Subject: [PATCH] platform: increase initial buffer size of libnl's nl_recvmsg() to 32K Since commit 9fafb382db273160a5e9e10ff84f8a4d2af220d3, we would explicitly set libnl's socket buffer size to 4*getpagesize(). That is also the default of libnl itself. Additionally, we would workaround too small buffers by increasing the buffer size up to 512K. A too small buffer causes messages to be lost. Usually, that only results in a cache-resync, which isn't too bad. Lost messages are however a problem if the lost message was an ACK that we were waiting for. However, it is rather unlikely to happen, because it's expected that the buffer size gets adjusted already when the cache is filled initially, before any other requests are pending. Still, let's increase the default buffer size to 32K, hoping that this initial value is already large enough to avoid the problem altogether. Note that iproute2 also uses a buffer size of 32K [1] [2]. Alternatively, we could use MSG_PEEK like systemd does [3]. However, that requires two syscalls per message. [1] https://patchwork.ozlabs.org/patch/592178/ [2] https://git.kernel.org/cgit/linux/kernel/git/shemminger/iproute2.git/tree/lib/libnetlink.c?id=f5f760b81250630da23a4021c30e802695be79d2#n274 [3] https://github.com/systemd/systemd/blob/cd66af227416eb7b9f150b92abff4e4a3e92253b/src/libsystemd/sd-netlink/netlink-socket.c#L323 --- src/platform/nm-linux-platform.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index c2404e13c..ab2ab9b01 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -6458,7 +6458,7 @@ constructed (GObject *_object) /* explicitly set the msg buffer size and disable MSG_PEEK. * If we later encounter NLE_MSG_TRUNC, we will adjust the buffer size. */ nl_socket_disable_msg_peek (priv->nlh); - nle = nl_socket_set_msg_buf_size (priv->nlh, 4 * getpagesize ()); + nle = nl_socket_set_msg_buf_size (priv->nlh, 32 * 1024); g_assert (!nle); nle = nl_socket_add_memberships (priv->nlh,