From bff439345cafa59a4bd72c2a20591e7bd8441b47 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Fri, 2 May 2025 17:04:50 +0000 Subject: Increase default kbufsz to 1 MiB; don't die on ENOBUFS (but spam) Signed-off-by: Laurent Bercot --- doc/mdevd-coldplug.html | 6 +++--- doc/mdevd.html | 6 +++--- src/mdevd/mdevd-coldplug.c | 4 ++-- src/mdevd/mdevd.c | 2 +- src/mdevd/mdevd_uevent_read.c | 13 +++++++++---- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/doc/mdevd-coldplug.html b/doc/mdevd-coldplug.html index 36654eb..b26d4c9 100644 --- a/doc/mdevd-coldplug.html +++ b/doc/mdevd-coldplug.html @@ -28,7 +28,7 @@ for all these devices.

Interface

-     mdevd-coldplug [ -v verbosity ] [ -s slashsys ] [ -O nlgroup ] [ -b kbufsize ]
+     mdevd-coldplug [ -v verbosity ] [ -s slashsys ] [ -O nlgroup ] [ -b kbufsz ]
 
diff --git a/doc/mdevd.html b/doc/mdevd.html index ca39b02..7c2a869 100644 --- a/doc/mdevd.html +++ b/doc/mdevd.html @@ -119,9 +119,9 @@ cause a loop by chaining two separate instances of mdevd. mdevd will protect you against accidents, not against intentional stupidity.)
  • -b kbufsz : try and reserve a kernel buffer of kbufsz bytes for the netlink queue. Too large a buffer wastes kernel memory; -too small a buffer risks losing events. The default is 512288, -meaning 500 kB, which should be -enough for most systems; if you're getting "No buffer space available" errors +too small a buffer risks losing events. The default is 1048576, +meaning 1 MiB, which should be +enough for most systems; if you're getting "missed events" warnings from mdevd at coldplug time, try increasing this number.
  • -n : dry run. mdevd will not create or delete device nodes, and it will not spawn commands. Instead, it will print to stdout diff --git a/src/mdevd/mdevd-coldplug.c b/src/mdevd/mdevd-coldplug.c index 6b8953f..1dd0982 100644 --- a/src/mdevd/mdevd-coldplug.c +++ b/src/mdevd/mdevd-coldplug.c @@ -15,7 +15,7 @@ #include "mdevd-internal.h" -#define USAGE "mdevd-coldplug [ -v verbosity ] [ -s slashsys ] [ -O nlgroup ] [ -b kbufsize ]" +#define USAGE "mdevd-coldplug [ -v verbosity ] [ -s slashsys ] [ -O nlgroup ] [ -b kbufsz ]" #define dieusage() strerr_dieusage(100, USAGE) static char subsystem[PATH_MAX] = "" ; @@ -95,7 +95,7 @@ int main (int argc, char const *const *argv, char const *const *envp) char const *slashsys = "/sys" ; unsigned int verbosity = 1 ; unsigned int nlgroup = 0 ; - unsigned int kbufsz = 512288 ; + unsigned int kbufsz = 1048576 ; int nlfd = -1 ; PROG = "mdevd-coldplug" ; { diff --git a/src/mdevd/mdevd.c b/src/mdevd/mdevd.c index 6b82874..f5222f7 100644 --- a/src/mdevd/mdevd.c +++ b/src/mdevd/mdevd.c @@ -904,7 +904,7 @@ int main (int argc, char const *const *argv) char const *configfile = "/etc/mdev.conf" ; iopause_fd x[2] = { { .events = IOPAUSE_READ }, { .events = IOPAUSE_READ } } ; unsigned int notif = 0 ; - unsigned int kbufsz = 512288 ; + unsigned int kbufsz = 1048576 ; char const *slashdev = "/dev" ; int docoldplug = 0 ; unsigned int intake = 1 ; diff --git a/src/mdevd/mdevd_uevent_read.c b/src/mdevd/mdevd_uevent_read.c index 1c84f2d..38be5ea 100644 --- a/src/mdevd/mdevd_uevent_read.c +++ b/src/mdevd/mdevd_uevent_read.c @@ -38,10 +38,15 @@ static inline size_t netlink_read (int fd, char *s, uint32_t options, unsigned i .msg_controllen = 0, .msg_flags = 0 } ; - ssize_t r = sanitize_read(fd_recvmsg(fd, &msg)) ; - if (r < 0) - strerr_diefu1sys(111, "receive netlink message") ; - if (!r) return 0 ; + ssize_t r ; + for (;;) + { + r = sanitize_read(fd_recvmsg(fd, &msg)) ; + if (r > 0) break ; + if (!r) return 0 ; + if (errno != ENOBUFS) strerr_diefu1sys(111, "read netlink message") ; + strerr_warnw1x("missed events! you should increase the -b kbufsz value") ; + } if (msg.msg_flags & MSG_TRUNC) strerr_diefu1x(111, "buffer too small for netlink message") ; if (options & 1 && nl.nl_pid) -- cgit v1.3.1