aboutsummaryrefslogtreecommitdiff
path: root/util-linux
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2020-11-22 13:34:07 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2020-11-22 13:34:07 +0100
commita569fd37fec970d8aeebca1c34a964502072d817 (patch)
tree7a8ae81b5db7105c55fb22d04b874988e55acd4c /util-linux
parent3cd55d49a2ee5d74f019b1a4c32ab28a9ce5e1d3 (diff)
downloadbusybox-a569fd37fec970d8aeebca1c34a964502072d817.tar.gz
uevent: increase netlink buffer sizes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'util-linux')
-rw-r--r--util-linux/uevent.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/util-linux/uevent.c b/util-linux/uevent.c
index 57d9328ef..2f1135f0c 100644
--- a/util-linux/uevent.c
+++ b/util-linux/uevent.c
@@ -26,8 +26,6 @@
#include "common_bufsiz.h"
#include <linux/netlink.h>
-#define BUFFER_SIZE 16*1024
-
#define env ((char **)bb_common_bufsiz1)
#define INIT_G() do { setup_common_bufsiz(); } while (0)
enum {
@@ -37,10 +35,16 @@ enum {
*/
};
-#ifndef SO_RCVBUFFORCE
-#define SO_RCVBUFFORCE 33
-#endif
-enum { RCVBUF = 2 * 1024 * 1024 };
+enum {
+ /* socket receive buffer of 2MiB proved to be too small:
+ * http://lists.busybox.net/pipermail/busybox/2019-December/087665.html
+ * Udevd seems to use a whooping 128MiB.
+ * The socket receive buffer size is just a resource limit.
+ * The buffers are allocated lazily so the memory is not wasted.
+ */
+ KERN_RCVBUF = 128 * 1024 * 1024,
+ USER_RCVBUF = 16 * 1024,
+};
int uevent_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int uevent_main(int argc UNUSED_PARAM, char **argv)
@@ -57,7 +61,7 @@ int uevent_main(int argc UNUSED_PARAM, char **argv)
// Reproducer:
// uevent mdev &
// find /sys -name uevent -exec sh -c 'echo add >"{}"' ';'
- fd = create_and_bind_to_netlink(NETLINK_KOBJECT_UEVENT, /*groups:*/ 1 << 0, RCVBUF);
+ fd = create_and_bind_to_netlink(NETLINK_KOBJECT_UEVENT, /*groups:*/ 1 << 0, KERN_RCVBUF);
for (;;) {
char *netbuf;
@@ -69,7 +73,7 @@ int uevent_main(int argc UNUSED_PARAM, char **argv)
// for a new uevent notification to come in.
// We use a fresh mmap so that buffer is not allocated
// until kernel actually starts filling it.
- netbuf = mmap(NULL, BUFFER_SIZE,
+ netbuf = mmap(NULL, USER_RCVBUF,
PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANON,
/* ignored: */ -1, 0);
@@ -77,7 +81,7 @@ int uevent_main(int argc UNUSED_PARAM, char **argv)
bb_simple_perror_msg_and_die("mmap");
// Here we block, possibly for a very long time
- len = safe_read(fd, netbuf, BUFFER_SIZE - 1);
+ len = safe_read(fd, netbuf, USER_RCVBUF - 1);
if (len < 0)
bb_simple_perror_msg_and_die("read");
end = netbuf + len;
@@ -108,7 +112,7 @@ int uevent_main(int argc UNUSED_PARAM, char **argv)
while (env[idx])
bb_unsetenv(env[idx++]);
}
- munmap(netbuf, BUFFER_SIZE);
+ munmap(netbuf, USER_RCVBUF);
}
return 0; // not reached