Skip to content

Commit ca54f3b

Browse files
author
Pingfan Liu
committed
kdumpctl: Check the recommend value when starting service
The crashkernel value is maximized for a OSTree image. When the image runs on the final platform, kdump-utils has the chance to get the proper reserved memory size and prompts the user to update the crashkernel parameter. Signed-off-by: Pingfan Liu <[email protected]>
1 parent 297273a commit ca54f3b

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

kdumpctl

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,52 @@ prepare_luks()
11291129
done
11301130
}
11311131

1132+
get_crashkernel_low_value()
1133+
{
1134+
local lines first_line start_hex end_hex start_dec end_dec size_bytes
1135+
1136+
mapfile -t lines < <(grep "Crash kernel" /proc/iomem)
1137+
1138+
if [ ${#lines[@]} -le 1 ]; then
1139+
echo 0
1140+
return
1141+
fi
1142+
1143+
first_line=${lines[0]}
1144+
# Extract start and end addresses
1145+
start_hex=$(echo "$first_line" | awk '{split($1, a, "-"); print a[1]}')
1146+
end_hex=$(echo "$first_line" | awk '{split($1, a, "-"); print a[2]}')
1147+
# Convert hex to decimal
1148+
start_dec=$((0x$start_hex))
1149+
end_dec=$((0x$end_hex))
1150+
# Calculate size in bytes
1151+
size_bytes=$((end_dec - start_dec + 1))
1152+
echo "$size_bytes"
1153+
}
1154+
1155+
suggest_crashkernel_reset()
1156+
{
1157+
local _crashkernel _recommend_value _actual_value _low_mem
1158+
1159+
_crashkernel=$(sed -n 's/.*crashkernel=\([^ ]*\).*/\1/p' /proc/cmdline)
1160+
[[ $(kdump_get_conf_val auto_reset_crashkernel) == no ]] && return
1161+
1162+
if ! echo "$_crashkernel" | grep -q -E "(fadump|fadump=0)"; then
1163+
_recommend_value=$(kdump_get_arch_recommend_size)
1164+
_low_mem=$(get_crashkernel_low_value)
1165+
# The crashkernel formula does not include the crashkernel low value
1166+
# but the kexec_crash_size does.
1167+
_recommend_value=$(memsize_add "$_recommend_value" "$_low_mem")
1168+
_recommend_value=$(to_bytes "$_recommend_value")
1169+
_actual_value=$(cat /sys/kernel/kexec_crash_size)
1170+
1171+
if [ "$_recommend_value" -lt "$_actual_value" ]; then
1172+
dwarn "The reserved crashkernel is abundant. Using 'kdumpctl reset-crashkernel' to reset kernel cmdline. It will take effect in the next boot"
1173+
dwarn "To release the abundant memory immediately. You can do: 'kdumpctl stop', 'echo $_recommend_value >/sys/kernel/kexec_crash_size', and finally 'kdump start'"
1174+
fi
1175+
fi
1176+
}
1177+
11321178
start()
11331179
{
11341180
check_dump_feasibility || return
@@ -1162,6 +1208,7 @@ start()
11621208
start_dump || return
11631209

11641210
dinfo "Starting kdump: [OK]"
1211+
suggest_crashkernel_reset
11651212
return 0
11661213
}
11671214

0 commit comments

Comments
 (0)