Hi Coiby,
On Tue, 21 Jun 2022 14:57:25 +0800
Coiby Xu <coxu(a)redhat.com> wrote:
By default, NetworkManger will manage all the network interfaces and
try to set interface IFF_UP to get carrier state. Regardless of whether
the network interface is connected to a cable or not, the NIC driver
will allocate memory resources for e.g. ring buffers when setting IFF_UP.
This could be a waste of memory. For example it's found i40e consumes ~15GB
on a power machine. On this machine, i40e manages four interfaces but only
one interface is valid. This patch use "managed=false" to tell
NetworkManager to not manage network interfaces that are not needed by
kdump by putting /etc/NetworkManager/conf.d/10-kdump-netif.conf in the
initramfs.
Signed-off-by: Coiby Xu <coxu(a)redhat.com>
---
dracut-module-setup.sh | 34 +++++++++++++++++++++++++++++++++-
1 file changed, 33 insertions(+), 1 deletion(-)
diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh
index 9ae3dd1..2a15e5e 100755
--- a/dracut-module-setup.sh
+++ b/dracut-module-setup.sh
@@ -1,6 +1,7 @@
#!/bin/bash
_DRACUT_KDUMP_NM_TMP_DIR="/tmp/$$-DRACUT_KDUMP_NM"
+_TMP_KDUMP_NETIFS="$_DRACUT_KDUMP_NM_TMP_DIR/kdump_netifs"
Could you use a bash array instead of a file here? That would reduce
the number of file operations.
Thanks
Philipp
cleanup() {
rm -rf $_DRACUT_KDUMP_NM_TMP_DIR
@@ -14,6 +15,7 @@ kdump_module_init() {
fi
mkdir -p "$_DRACUT_KDUMP_NM_TMP_DIR"
+ echo -n > "$_TMP_KDUMP_NETIFS"
. /lib/kdump/kdump-lib.sh
}
@@ -295,6 +297,31 @@ kdump_copy_nmconnection_file() {
# wait-device-timeout=60000 is inserted after "[connection]" so the
# user's custom value could overwrite it
sed -i '/\[connection\]/a wait-device-timeout=60000'
"${initdir}/$_initrd_nmconnection_file_path"
+
+ echo -n " $_dev" >> "$_TMP_KDUMP_NETIFS"
+}
+
+kdump_install_nm_netif_allowlist() {
+ local _netif _except_netif _netif_allowlist _netif_allowlist_nm_conf
+
+ for _netif in $1; do
+ _per_mac=$(kdump_get_perm_addr "$_netif")
+ if [[ "$_per_mac" != 'not set' ]]; then
+ _except_netif="mac:$_per_mac"
+ else
+ _except_netif="interface-name:$_netif"
+ fi
+ _netif_allowlist="${_netif_allowlist}except:${_except_netif};"
+ done
+
+ _netif_allowlist_nm_conf=$_DRACUT_KDUMP_NM_TMP_DIR/netif_allowlist_nm_conf
+ cat <<- EOF > "$_netif_allowlist_nm_conf"
+ [device-others]
+ match-device=${_netif_allowlist}
+ managed=false
+ EOF
+
+ inst "$_netif_allowlist_nm_conf"
"/etc/NetworkManager/conf.d/10-kdump-netif.conf"
}
kdump_setup_bridge() {
@@ -907,7 +934,7 @@ remove_cpu_online_rule() {
}
install() {
- local arch
+ local arch _netifs
kdump_module_init
kdump_install_conf
@@ -966,6 +993,11 @@ install() {
inst "ip"
fi
+ _netifs=$(cat "$_TMP_KDUMP_NETIFS")
+ if [[ -n "$_netif_allowlist" ]]; then
+ kdump_install_nm_netif_allowlist "$_netifs"
+ fi
+
# For the lvm type target under kdump, in /etc/lvm/lvm.conf we can
# safely replace "reserved_memory=XXXX"(default value is 8192) with
# "reserved_memory=1024" to lower memory pressure under kdump. We do