diff --git a/SOURCES/98-kexec.rules b/SOURCES/98-kexec.rules index 36715d0..4e70325 100644 --- a/SOURCES/98-kexec.rules +++ b/SOURCES/98-kexec.rules @@ -11,6 +11,6 @@ LABEL="kdump_reload" # doing nothing, but it and systemd-run will always generate # extra logs for each call, so trigger the "kdumpctl reload" # only if kdump service is active to avoid unnecessary logs -RUN+="/bin/sh -c '/usr/bin/systemctl is-active kdump.service || exit 0; /usr/bin/systemd-run --quiet /usr/bin/kdumpctl reload'" +RUN+="/bin/sh -c '/usr/bin/systemctl is-active kdump.service || exit 0; /usr/bin/systemd-run --no-block /usr/lib/udev/kdump-udev-throttler'" LABEL="kdump_reload_end" diff --git a/SOURCES/98-kexec.rules.ppc64 b/SOURCES/98-kexec.rules.ppc64 index 9d783a0..8678682 100644 --- a/SOURCES/98-kexec.rules.ppc64 +++ b/SOURCES/98-kexec.rules.ppc64 @@ -10,6 +10,6 @@ LABEL="kdump_reload" # doing nothing, but it and systemd-run will always generate # extra logs for each call, so trigger the "kdumpctl reload" # only if kdump service is active to avoid unnecessary logs -RUN+="/bin/sh -c '/usr/bin/systemctl is-active kdump.service || exit 0; /usr/bin/systemd-run --quiet /usr/bin/kdumpctl reload'" +RUN+="/bin/sh -c '/usr/bin/systemctl is-active kdump.service || exit 0; /usr/bin/systemd-run --quiet /usr/lib/udev/kdump-udev-throttler'" LABEL="kdump_reload_end" diff --git a/SOURCES/kdump-udev-throttler b/SOURCES/kdump-udev-throttler new file mode 100755 index 0000000..cd77a31 --- /dev/null +++ b/SOURCES/kdump-udev-throttler @@ -0,0 +1,42 @@ +#!/bin/bash +# This util helps to reduce the workload of kdump service restarting +# on udev event. When hotplugging memory / CPU, multiple udev +# events may be triggered concurrently, and obviously, we don't want +# to restart kdump service for each event. + +# This script will be called by udev, and make sure kdump service is +# restart after all events we are watching are settled. + +# On each call, this script will update try to aquire the $throttle_lock +# The first instance acquired the file lock will keep waiting for events +# to settle and then reload kdump. Other instances will just exit +# In this way, we can make sure kdump service is restarted immediately +# and for exactly once after udev events are settled. + +throttle_lock="/var/lock/kdump-udev-throttle" + +exec 9>$throttle_lock +if [ $? -ne 0 ]; then + echo "Failed to create the lock file! Fallback to non-throttled kdump service restart" + /bin/kdumpctl reload + exit 1 +fi + +flock -n 9 +if [ $? -ne 0 ]; then + echo "Throttling kdump restart for concurrent udev event" + exit 0 +fi + +# Wait for at least 1 second, at most 4 seconds for udev to settle +# Idealy we will have a less than 1 second lag between udev events settle +# and kdump reload +sleep 1 && udevadm settle --timeout 3 + +# Release the lock, /bin/kdumpctl will block and make the process +# holding two locks at the same time and we might miss some events +exec 9>&- + +/bin/kdumpctl reload + +exit 0 diff --git a/SPECS/kexec-tools.spec b/SPECS/kexec-tools.spec index f327e0f..016ff32 100644 --- a/SPECS/kexec-tools.spec +++ b/SPECS/kexec-tools.spec @@ -1,6 +1,6 @@ Name: kexec-tools Version: 2.0.15 -Release: 51%{?dist}.2 +Release: 51%{?dist}.3 License: GPLv2 Group: Applications/System Summary: The kexec/kdump userspace component. @@ -30,6 +30,7 @@ Source25: kdump-anaconda-addon-003-29-g4c517c5.tar.gz Source26: kdump.sysconfig.ppc64le Source27: kdump.sysconfig.aarch64 Source28: kdumpctl.8 +Source29: kdump-udev-throttler ####################################### # These are sources for mkdumpramfs @@ -275,6 +276,9 @@ install -m 644 %{SOURCE12} $RPM_BUILD_ROOT%{_mandir}/man8/mkdumprd.8 install -m 644 %{SOURCE28} $RPM_BUILD_ROOT%{_mandir}/man8/kdumpctl.8 install -m 755 %{SOURCE20} $RPM_BUILD_ROOT%{_prefix}/lib/kdump/kdump-lib.sh install -m 755 %{SOURCE24} $RPM_BUILD_ROOT%{_prefix}/lib/kdump/kdump-lib-initramfs.sh +%ifnarch s390x +install -m 755 %{SOURCE29} $RPM_BUILD_ROOT%{_udevrulesdir}/../kdump-udev-throttler +%endif %ifnarch s390x ppc64 ppc64le # For s390x the ELF header is created in the kdump kernel and therefore kexec # udev rules are not required @@ -412,6 +416,7 @@ done %config(noreplace,missingok) %verify(not mtime) %{_sysconfdir}/kdump.conf %ifnarch s390x %config %{_udevrulesdir} +%{_udevrulesdir}/../kdump-udev-throttler %endif %{dracutlibdir}/modules.d/* %dir %{_localstatedir}/crash @@ -445,6 +450,9 @@ done %doc %changelog +* Thu Apr 22 2021 Pingfan Liu 2.0.15-51.3 +- Throttle kdump reload request triggered by udev event + * Fri Mar 5 2021 Pingfan Liu 2.0.15-51.2 - kdumpctl: fix a variable expansion in check_fence_kdump_config()