diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2020-11-22 13:34:07 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2020-11-22 13:34:07 +0100 |
| commit | a569fd37fec970d8aeebca1c34a964502072d817 (patch) | |
| tree | 7a8ae81b5db7105c55fb22d04b874988e55acd4c | |
| parent | 3cd55d49a2ee5d74f019b1a4c32ab28a9ce5e1d3 (diff) | |
| download | busybox-w32-a569fd37fec970d8aeebca1c34a964502072d817.tar.gz busybox-w32-a569fd37fec970d8aeebca1c34a964502072d817.tar.bz2 busybox-w32-a569fd37fec970d8aeebca1c34a964502072d817.zip | |
uevent: increase netlink buffer sizes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| -rw-r--r-- | util-linux/uevent.c | 24 |
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 @@ | |||
| 26 | #include "common_bufsiz.h" | 26 | #include "common_bufsiz.h" |
| 27 | #include <linux/netlink.h> | 27 | #include <linux/netlink.h> |
| 28 | 28 | ||
| 29 | #define BUFFER_SIZE 16*1024 | ||
| 30 | |||
| 31 | #define env ((char **)bb_common_bufsiz1) | 29 | #define env ((char **)bb_common_bufsiz1) |
| 32 | #define INIT_G() do { setup_common_bufsiz(); } while (0) | 30 | #define INIT_G() do { setup_common_bufsiz(); } while (0) |
| 33 | enum { | 31 | enum { |
| @@ -37,10 +35,16 @@ enum { | |||
| 37 | */ | 35 | */ |
| 38 | }; | 36 | }; |
| 39 | 37 | ||
| 40 | #ifndef SO_RCVBUFFORCE | 38 | enum { |
| 41 | #define SO_RCVBUFFORCE 33 | 39 | /* socket receive buffer of 2MiB proved to be too small: |
| 42 | #endif | 40 | * http://lists.busybox.net/pipermail/busybox/2019-December/087665.html |
| 43 | enum { RCVBUF = 2 * 1024 * 1024 }; | 41 | * Udevd seems to use a whooping 128MiB. |
| 42 | * The socket receive buffer size is just a resource limit. | ||
| 43 | * The buffers are allocated lazily so the memory is not wasted. | ||
| 44 | */ | ||
| 45 | KERN_RCVBUF = 128 * 1024 * 1024, | ||
| 46 | USER_RCVBUF = 16 * 1024, | ||
| 47 | }; | ||
| 44 | 48 | ||
| 45 | int uevent_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 49 | int uevent_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| 46 | int uevent_main(int argc UNUSED_PARAM, char **argv) | 50 | int uevent_main(int argc UNUSED_PARAM, char **argv) |
| @@ -57,7 +61,7 @@ int uevent_main(int argc UNUSED_PARAM, char **argv) | |||
| 57 | // Reproducer: | 61 | // Reproducer: |
| 58 | // uevent mdev & | 62 | // uevent mdev & |
| 59 | // find /sys -name uevent -exec sh -c 'echo add >"{}"' ';' | 63 | // find /sys -name uevent -exec sh -c 'echo add >"{}"' ';' |
| 60 | fd = create_and_bind_to_netlink(NETLINK_KOBJECT_UEVENT, /*groups:*/ 1 << 0, RCVBUF); | 64 | fd = create_and_bind_to_netlink(NETLINK_KOBJECT_UEVENT, /*groups:*/ 1 << 0, KERN_RCVBUF); |
| 61 | 65 | ||
| 62 | for (;;) { | 66 | for (;;) { |
| 63 | char *netbuf; | 67 | char *netbuf; |
| @@ -69,7 +73,7 @@ int uevent_main(int argc UNUSED_PARAM, char **argv) | |||
| 69 | // for a new uevent notification to come in. | 73 | // for a new uevent notification to come in. |
| 70 | // We use a fresh mmap so that buffer is not allocated | 74 | // We use a fresh mmap so that buffer is not allocated |
| 71 | // until kernel actually starts filling it. | 75 | // until kernel actually starts filling it. |
| 72 | netbuf = mmap(NULL, BUFFER_SIZE, | 76 | netbuf = mmap(NULL, USER_RCVBUF, |
| 73 | PROT_READ | PROT_WRITE, | 77 | PROT_READ | PROT_WRITE, |
| 74 | MAP_PRIVATE | MAP_ANON, | 78 | MAP_PRIVATE | MAP_ANON, |
| 75 | /* ignored: */ -1, 0); | 79 | /* ignored: */ -1, 0); |
| @@ -77,7 +81,7 @@ int uevent_main(int argc UNUSED_PARAM, char **argv) | |||
| 77 | bb_simple_perror_msg_and_die("mmap"); | 81 | bb_simple_perror_msg_and_die("mmap"); |
| 78 | 82 | ||
| 79 | // Here we block, possibly for a very long time | 83 | // Here we block, possibly for a very long time |
| 80 | len = safe_read(fd, netbuf, BUFFER_SIZE - 1); | 84 | len = safe_read(fd, netbuf, USER_RCVBUF - 1); |
| 81 | if (len < 0) | 85 | if (len < 0) |
| 82 | bb_simple_perror_msg_and_die("read"); | 86 | bb_simple_perror_msg_and_die("read"); |
| 83 | end = netbuf + len; | 87 | end = netbuf + len; |
| @@ -108,7 +112,7 @@ int uevent_main(int argc UNUSED_PARAM, char **argv) | |||
| 108 | while (env[idx]) | 112 | while (env[idx]) |
| 109 | bb_unsetenv(env[idx++]); | 113 | bb_unsetenv(env[idx++]); |
| 110 | } | 114 | } |
| 111 | munmap(netbuf, BUFFER_SIZE); | 115 | munmap(netbuf, USER_RCVBUF); |
| 112 | } | 116 | } |
| 113 | 117 | ||
| 114 | return 0; // not reached | 118 | return 0; // not reached |
