From: Yu Watanabe Date: Mon, 6 Nov 2023 11:39:46 +0000 (+0900) Subject: sd-device-monitor: unconditionally increase buffer size by sd_device_monitor_new() X-Git-Tag: v255-rc2~120^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F29872%2Fhead;p=thirdparty%2Fsystemd.git sd-device-monitor: unconditionally increase buffer size by sd_device_monitor_new() As suggested at https://github.com/systemd/systemd/pull/29872#discussion_r1382932633: > socket memory is these days accounted to the process that owns a socket, > hence we shouldn't be too concerned that this might waste memory. --- diff --git a/src/core/device.c b/src/core/device.c index ffe85bdb298..659e52bf795 100644 --- a/src/core/device.c +++ b/src/core/device.c @@ -1028,11 +1028,6 @@ static void device_enumerate(Manager *m) { goto fail; } - /* This will fail if we are unprivileged, but that - * should not matter much, as user instances won't run - * during boot. */ - (void) sd_device_monitor_set_receive_buffer_size(m->device_monitor, 128*1024*1024); - r = sd_device_monitor_filter_add_match_tag(m->device_monitor, "systemd"); if (r < 0) { log_error_errno(r, "Failed to add udev tag match: %m"); diff --git a/src/libsystemd/sd-device/device-monitor.c b/src/libsystemd/sd-device/device-monitor.c index 15cb8d0774a..bb4f9bd513e 100644 --- a/src/libsystemd/sd-device/device-monitor.c +++ b/src/libsystemd/sd-device/device-monitor.c @@ -215,6 +215,15 @@ int device_monitor_new_full(sd_device_monitor **ret, MonitorNetlinkGroup group, } } + /* Let's bump the receive buffer size, but only if we are not called via socket activation, as in + * that case the service manager sets the receive buffer size for us, and the value in the .socket + * unit should take full effect. */ + if (fd < 0) { + r = sd_device_monitor_set_receive_buffer_size(m, 128*1024*1024); + if (r < 0) + log_monitor_errno(m, r, "Failed to increase receive buffer size, ignoring: %m"); + } + *ret = TAKE_PTR(m); return 0; diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c index e02d0992b41..1ca1d7abe5e 100644 --- a/src/network/networkd-manager.c +++ b/src/network/networkd-manager.c @@ -205,10 +205,6 @@ static int manager_connect_udev(Manager *m) { if (r < 0) return log_error_errno(r, "Failed to initialize device monitor: %m"); - r = sd_device_monitor_set_receive_buffer_size(m->device_monitor, RCVBUF_SIZE); - if (r < 0) - log_warning_errno(r, "Failed to increase buffer size for device monitor, ignoring: %m"); - r = sd_device_monitor_filter_add_match_subsystem_devtype(m->device_monitor, "net", NULL); if (r < 0) return log_error_errno(r, "Could not add device monitor filter for net subsystem: %m"); diff --git a/src/udev/udev-manager.c b/src/udev/udev-manager.c index aca241c0c96..9d86845b5f9 100644 --- a/src/udev/udev-manager.c +++ b/src/udev/udev-manager.c @@ -1225,15 +1225,6 @@ int manager_init(Manager *manager, int fd_ctrl, int fd_uevent) { if (r < 0) return log_error_errno(r, "Failed to initialize device monitor: %m"); - /* Bump receiver buffer, but only if we are not called via socket activation, as in that - * case systemd sets the receive buffer size for us, and the value in the .socket unit - * should take full effect. */ - if (fd_uevent < 0) { - r = sd_device_monitor_set_receive_buffer_size(manager->monitor, 128 * 1024 * 1024); - if (r < 0) - log_warning_errno(r, "Failed to set receive buffer size for device monitor, ignoring: %m"); - } - (void) sd_device_monitor_set_description(manager->monitor, "manager"); r = device_monitor_enable_receiving(manager->monitor); diff --git a/src/udev/udevadm-monitor.c b/src/udev/udevadm-monitor.c index dbe13a8d3b7..138b4be1fd7 100644 --- a/src/udev/udevadm-monitor.c +++ b/src/udev/udevadm-monitor.c @@ -66,8 +66,6 @@ static int setup_monitor(MonitorNetlinkGroup sender, sd_event *event, sd_device_ if (r < 0) return log_error_errno(r, "Failed to create netlink socket: %m"); - (void) sd_device_monitor_set_receive_buffer_size(monitor, 128*1024*1024); - r = sd_device_monitor_attach_event(monitor, event); if (r < 0) return log_error_errno(r, "Failed to attach event: %m"); diff --git a/src/udev/udevadm-trigger.c b/src/udev/udevadm-trigger.c index 20dee175d15..e0f487de073 100644 --- a/src/udev/udevadm-trigger.c +++ b/src/udev/udevadm-trigger.c @@ -526,8 +526,6 @@ int trigger_main(int argc, char *argv[], void *userdata) { if (r < 0) return log_error_errno(r, "Failed to create device monitor object: %m"); - (void) sd_device_monitor_set_receive_buffer_size(m, 128*1024*1024); - r = sd_device_monitor_attach_event(m, event); if (r < 0) return log_error_errno(r, "Failed to attach event to device monitor: %m"); diff --git a/src/udev/udevadm-wait.c b/src/udev/udevadm-wait.c index 7fa9b862634..e6620c25dd1 100644 --- a/src/udev/udevadm-wait.c +++ b/src/udev/udevadm-wait.c @@ -184,8 +184,6 @@ static int setup_monitor(sd_event *event, MonitorNetlinkGroup group, const char if (r < 0) return r; - (void) sd_device_monitor_set_receive_buffer_size(monitor, 128*1024*1024); - r = sd_device_monitor_attach_event(monitor, event); if (r < 0) return r;