From 12b86202b58e117504f7beda3207b8c7efd5a785 Mon Sep 17 00:00:00 2001 From: WANG Chao Date: Fri, 2 Aug 2013 14:22:21 +0800 Subject: [PATCH] kernel cmdline: Remove hugepage allocations 2nd kernel has very limited memory. Allocating huge pages will probably trigger OOM. So let's remove hugepages and hugepagesz kernel parameters for 2nd kernel when 1st kernel are using them. If user wants huge pages cmdline in 2nd kernel, he/she can still specify it through KERNEL_COMMANDLINE_APPEND in /etc/sysconfig/kdump. This patch adds a new function remove_cmdline_param(). It takes a list of kernel parameters as its arguments and remove them from given kernel cmdline. update: 1. Add description of remove_cmdline_param() per Vivek. 2. Remove_cmdline_param() will take kernel cmdline as $1, then strip it and print the result. Signed-off-by: WANG Chao Acked-by: Vivek Goyal --- kdumpctl | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/kdumpctl b/kdumpctl index 36e969f..aba1e3c 100755 --- a/kdumpctl +++ b/kdumpctl @@ -16,6 +16,23 @@ if [ -f /etc/sysconfig/kdump ]; then . /etc/sysconfig/kdump fi +# remove_cmdline_param [] ... [] +# Remove a list of kernel parameters from a given kernel cmdline and print the result. +# For each "arg" in the removing params list, "arg" and "arg=xxx" will be removed if exists. +function remove_cmdline_param() +{ + local cmdline=$1 + shift + + for arg in $@; do + cmdline=`echo $cmdline | \ + sed -e "s/\b$arg=[^ ]*\b//g" \ + -e "s/\b$arg\b//g" \ + -e "s/\s\+/ /g"` + done + echo $cmdline +} + function save_core() { coredir="/var/crash/`date +"%Y-%m-%d-%H:%M"`" @@ -221,8 +238,8 @@ function load_kdump() then KDUMP_COMMANDLINE=`cat /proc/cmdline` fi + KDUMP_COMMANDLINE=`remove_cmdline_param "$KDUMP_COMMANDLINE" crashkernel hugepages hugepagesz` - KDUMP_COMMANDLINE=`echo $KDUMP_COMMANDLINE | sed -e 's/crashkernel=[^ ]*//'` KDUMP_COMMANDLINE="${KDUMP_COMMANDLINE} ${KDUMP_COMMANDLINE_APPEND}" $KEXEC $KEXEC_ARGS $standard_kexec_args \