diff options
Diffstat (limited to 'util-linux/mdev.c')
-rw-r--r-- | util-linux/mdev.c | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/util-linux/mdev.c b/util-linux/mdev.c index 59dbcf0cd..8b06d3456 100644 --- a/util-linux/mdev.c +++ b/util-linux/mdev.c | |||
@@ -269,10 +269,6 @@ | |||
269 | # define dbg3s(msg) ((void)0) | 269 | # define dbg3s(msg) ((void)0) |
270 | #endif | 270 | #endif |
271 | 271 | ||
272 | |||
273 | #ifndef SO_RCVBUFFORCE | ||
274 | #define SO_RCVBUFFORCE 33 | ||
275 | #endif | ||
276 | static const char keywords[] ALIGN1 = "add\0remove\0"; // "change\0" | 272 | static const char keywords[] ALIGN1 = "add\0remove\0"; // "change\0" |
277 | enum { OP_add, OP_remove }; | 273 | enum { OP_add, OP_remove }; |
278 | 274 | ||
@@ -1152,15 +1148,27 @@ static void initial_scan(char *temp) | |||
1152 | 1148 | ||
1153 | #if ENABLE_FEATURE_MDEV_DAEMON | 1149 | #if ENABLE_FEATURE_MDEV_DAEMON |
1154 | 1150 | ||
1155 | /* uevent applet uses 16k buffer, and mmaps it before every read */ | 1151 | /* |
1156 | # define BUFFER_SIZE (2 * 1024) | 1152 | * The kernel (as of v5.4) will pass up to 32 environment variables with a |
1157 | # define RCVBUF (2 * 1024 * 1024) | 1153 | * total of 2kiB on each event. On top of that the action string and device |
1154 | * path are added. Using a 3kiB buffer for the event should suffice in any | ||
1155 | * case. | ||
1156 | * | ||
1157 | * As far as the socket receive buffer size is concerned 2MiB proved to be too | ||
1158 | * small (see [1]). Udevd seems to use a whooping 128MiB. The socket receive | ||
1159 | * buffer size is just a resource limit. The buffers are allocated lazily so | ||
1160 | * the memory is not wasted. | ||
1161 | * | ||
1162 | * [1] http://lists.busybox.net/pipermail/busybox/2019-December/087665.html | ||
1163 | */ | ||
1164 | # define USER_RCVBUF (3 * 1024) | ||
1165 | # define KERN_RCVBUF (128 * 1024 * 1024) | ||
1158 | # define MAX_ENV 32 | 1166 | # define MAX_ENV 32 |
1159 | 1167 | ||
1160 | static void daemon_loop(char *temp, int fd) | 1168 | static void daemon_loop(char *temp, int fd) |
1161 | { | 1169 | { |
1162 | for (;;) { | 1170 | for (;;) { |
1163 | char netbuf[BUFFER_SIZE]; | 1171 | char netbuf[USER_RCVBUF]; |
1164 | char *env[MAX_ENV]; | 1172 | char *env[MAX_ENV]; |
1165 | char *s, *end; | 1173 | char *s, *end; |
1166 | ssize_t len; | 1174 | ssize_t len; |
@@ -1237,7 +1245,7 @@ int mdev_main(int argc UNUSED_PARAM, char **argv) | |||
1237 | * mdev -d | 1245 | * mdev -d |
1238 | * find /sys -name uevent -exec sh -c 'echo add >"{}"' ';' | 1246 | * find /sys -name uevent -exec sh -c 'echo add >"{}"' ';' |
1239 | */ | 1247 | */ |
1240 | fd = create_and_bind_to_netlink(NETLINK_KOBJECT_UEVENT, 1 << 0, RCVBUF); | 1248 | fd = create_and_bind_to_netlink(NETLINK_KOBJECT_UEVENT, 1 << 0, KERN_RCVBUF); |
1241 | 1249 | ||
1242 | /* | 1250 | /* |
1243 | * Make inital scan after the uevent socket is alive and | 1251 | * Make inital scan after the uevent socket is alive and |