Skip to content

Commit 1285d76

Browse files
committed
powerpc: consider CPU count while calculating crashkernel value
The next patch in the series adds more CPUs to the capture kernel, which increases the memory requirement for the capture kernel. Experiments show that powerpc needs 1 MB of additional memory for every CPU added. Therefore, while calculating the crashkernel size, make sure to include an additional 1 MB for every CPU configured in the capture kernel. The changes are implemented in such a way that if the user changes the nr_cpus value in the kdump configuration, the script will adapt accordingly. If other architectures decide to enable more CPUs in the kdump kernel, then defining the _pcpu_area variable in kdump_get_arch_recommend_crashkernel()/kdump-lib.sh function will be sufficient for this solution. Signed-off-by: Sourabh Jain <sourabhjain@linux.ibm.com>
1 parent 063548f commit 1285d76

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

kdump-lib.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1000,10 +1000,13 @@ _crashkernel_add()
10001000
# get default crashkernel
10011001
# $1 dump mode, if not specified, dump_mode will be judged by is_fadump_capable
10021002
# $2 kernel-release, if not specified, got by _get_kdump_kernel_version
1003+
# $3: number of CPUs configured for kdump kernel (nr_cpus)
10031004
# shellcheck disable=SC2120 # kdumpctl will call this func with an argument
10041005
kdump_get_arch_recommend_crashkernel()
10051006
{
10061007
local _arch _ck_cmdline _dump_mode
1008+
local _nr_cpus=$3
1009+
local _pcpu_area=0
10071010
local _delta=0
10081011
10091012
if [[ -z $1 ]]; then
@@ -1047,6 +1050,9 @@ kdump_get_arch_recommend_crashkernel()
10471050
has_mlx5 && ((_delta += 150))
10481051
fi
10491052
elif [[ $_arch == "ppc64le" ]]; then
1053+
# 1MB per CPU
1054+
_pcpu_area=1
1055+
_delta=$(( _delta + _pcpu_area * _nr_cpus ))
10501056
if [[ $_dump_mode == "fadump" ]]; then
10511057
_ck_cmdline="4G-16G:768M,16G-64G:1G,64G-128G:2G,128G-1T:4G,1T-2T:6G,2T-4T:12G,4T-8T:20G,8T-16T:36G,16T-32T:64G,32T-64T:128G,64T-:180G"
10521058
else
@@ -1059,16 +1065,18 @@ kdump_get_arch_recommend_crashkernel()
10591065
10601066
# return recommended size based on current system RAM size
10611067
# $1: kernel version, if not set, will defaults to $(uname -r)
1068+
# $2: number of CPUs configured for kdump kernel (nr_cpus)
10621069
kdump_get_arch_recommend_size()
10631070
{
10641071
local _ck_cmdline _sys_mem
1072+
local _nr_cpus=$2
10651073
10661074
if ! [[ -r "/proc/iomem" ]]; then
10671075
echo "Error, can not access /proc/iomem."
10681076
return 1
10691077
fi
10701078
_sys_mem=$(get_system_size)
1071-
_ck_cmdline=$(kdump_get_arch_recommend_crashkernel)
1079+
_ck_cmdline=$(kdump_get_arch_recommend_crashkernel "" "" "$_nr_cpus")
10721080
_ck_cmdline=${_ck_cmdline//-:/-102400T:}
10731081
get_recommend_size "$_sys_mem" "$_ck_cmdline"
10741082
}

kdumpctl

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ DEFAULT_INITRD_BAK=""
1212
INITRD_CHECKSUM_LOCATION=""
1313
KDUMP_INITRD=""
1414
TARGET_INITRD=""
15+
NR_CPUS=""
1516
#kdump shall be the default dump mode
1617
DEFAULT_DUMP_MODE="kdump"
1718
VMCORE_CREATION_STATUS="/var/lib/kdump/vmcore-creation.status"
@@ -147,6 +148,20 @@ determine_dump_mode()
147148
ddebug "DEFAULT_DUMP_MODE=$DEFAULT_DUMP_MODE"
148149
}
149150

151+
find_nr_cpus()
152+
{
153+
local _cmdline_append
154+
155+
# shellcheck disable=SC2153
156+
if is_fadump_capable; then
157+
_cmdline_append="$FADUMP_COMMANDLINE_APPEND"
158+
else
159+
_cmdline_append="$KDUMP_COMMANDLINE_APPEND"
160+
fi
161+
NR_CPUS=$(echo "$_cmdline_append" | sed -n 's/.*nr_cpus=\([0-9]\+\).*/\1/p')
162+
ddebug "Configured nr_cpus=$NR_CPUS"
163+
}
164+
150165
rebuild_fadump_initrd()
151166
{
152167
if ! $MKFADUMPRD "$DEFAULT_INITRD_BAK" "$TARGET_INITRD" --kver "$KDUMP_KERNELVER"; then
@@ -1360,7 +1375,7 @@ do_estimate()
13601375
esac
13611376

13621377
kdump_mods="$(lsinitrd "$TARGET_INITRD" -f /usr/lib/dracut/hostonly-kernel-modules.txt | tr '\n' ' ')"
1363-
baseline=$(kdump_get_arch_recommend_size)
1378+
baseline=$(kdump_get_arch_recommend_size "" "$NR_CPUS")
13641379
if [[ ${baseline: -1} == "M" ]]; then
13651380
baseline=${baseline%M}
13661381
elif [[ ${baseline: -1} == "G" ]]; then
@@ -1456,7 +1471,7 @@ get_default_crashkernel()
14561471
{
14571472
local _dump_mode=$1
14581473

1459-
kdump_get_arch_recommend_crashkernel "$_dump_mode"
1474+
kdump_get_arch_recommend_crashkernel "$_dump_mode" "" "$NR_CPUS"
14601475
}
14611476

14621477
# Read kernel cmdline parameter for a specific kernel
@@ -1651,7 +1666,7 @@ reset_crashkernel()
16511666
# to repeat it.
16521667
if is_ostree; then
16531668
_old_ck=$(rpm-ostree kargs | sed -n -E 's/.*(^|\s)crashkernel=(\S*).*/\2/p')
1654-
_new_ck=$(kdump_get_arch_recommend_crashkernel kdump)
1669+
_new_ck=$(kdump_get_arch_recommend_crashkernel kdump "" "$NR_CPUS")
16551670
if _update_kernel_cmdline "" crashkernel "$_old_ck" "$_new_ck"; then
16561671
[[ $_reboot == yes ]] && systemctl reboot
16571672
fi
@@ -1675,7 +1690,7 @@ reset_crashkernel()
16751690
_has_changed=""
16761691
if [[ $(uname -m) == ppc64le ]]; then
16771692
if [[ -n $_opt_fadump ]]; then
1678-
_new_ck=$(kdump_get_arch_recommend_crashkernel "$_dump_mode")
1693+
_new_ck=$(kdump_get_arch_recommend_crashkernel "$_dump_mode" "" "$NR_CPUS")
16791694
_old_fadump=$(get_grub_kernel_boot_parameter "$_kernel" fadump)
16801695
_new_fadump="$_opt_fadump"
16811696
[[ $_new_fadump == off ]] && _new_fadump=""
@@ -1688,10 +1703,10 @@ reset_crashkernel()
16881703
fi
16891704
else
16901705
_dump_mode="$(get_dump_mode_by_kernel "$_kernel")"
1691-
_new_ck=$(kdump_get_arch_recommend_crashkernel "$_dump_mode")
1706+
_new_ck=$(kdump_get_arch_recommend_crashkernel "$_dump_mode" "" "$NR_CPUS")
16921707
fi
16931708
else
1694-
_new_ck=$(kdump_get_arch_recommend_crashkernel kdump)
1709+
_new_ck=$(kdump_get_arch_recommend_crashkernel kdump "" "$NR_CPUS")
16951710
fi
16961711

16971712
_old_ck=$(get_grub_kernel_boot_parameter "$_kernel" crashkernel)
@@ -1730,7 +1745,7 @@ _update_crashkernel()
17301745
_old_ck=$(get_grub_kernel_boot_parameter "$_kernel" crashkernel)
17311746
_kver=$(parse_kver_from_path "$_kernel")
17321747
# The second argument is for the case of aarch64, where installing a 64k variant on a 4k kernel, or vice versa
1733-
_new_ck=$(kdump_get_arch_recommend_crashkernel "$_dump_mode" "$_kver")
1748+
_new_ck=$(kdump_get_arch_recommend_crashkernel "$_dump_mode" "$_kver" "$NR_CPUS")
17341749
if _update_kernel_cmdline "$_kernel" crashkernel "$_old_ck" "$_new_ck"; then
17351750
_msg="For kernel=$_kernel, crashkernel=$_new_ck now. Please reboot the system for the change to take effect."
17361751
_msg+=" Note if you don't want kdump-utils to manage the crashkernel kernel parameter, please set auto_reset_crashkernel=no in /etc/kdump.conf."
@@ -1981,6 +1996,7 @@ main()
19811996
{
19821997
# Determine if the dump mode is kdump or fadump
19831998
determine_dump_mode
1999+
find_nr_cpus
19842000

19852001
case "$1" in
19862002
start)

0 commit comments

Comments
 (0)