Skip to content

Commit a3bcf79

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 <piliu@redhat.com>
1 parent 7e1da7e commit a3bcf79

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

kdumpctl

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

1132+
get_crashkernel_bounce_buffer_size()
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 _bounce_buff_size
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+
# The crashkernel formula does not account for DMA-bounce buffers,
1165+
# unlike kexec_crash_size which does. Systems using DMA-bounce buffers
1166+
# should factor this into the calculation.
1167+
_bounce_buff_size=$(get_crashkernel_bounce_buffer_size)
1168+
_recommend_value=$(_crashkernel_add "$_recommend_value" "$_bounce_buff_size" 1)
1169+
_recommend_value=$(to_bytes "$_recommend_value")
1170+
_actual_value=$(cat /sys/kernel/kexec_crash_size)
1171+
1172+
if [ "$_recommend_value" -lt "$_actual_value" ]; then
1173+
dwarn "The reserved crashkernel is abundant. Using 'kdumpctl reset-crashkernel' to reset kernel cmdline. It will take effect in the next boot"
1174+
dwarn "To release the abundant memory immediately. You can do: 'kdumpctl stop', 'echo $_recommend_value >/sys/kernel/kexec_crash_size', and finally 'kdumpctl start'"
1175+
fi
1176+
fi
1177+
}
1178+
11321179
start()
11331180
{
11341181
check_dump_feasibility || return
@@ -1162,6 +1209,7 @@ start()
11621209
start_dump || return
11631210

11641211
dinfo "Starting kdump: [OK]"
1212+
suggest_crashkernel_reset
11651213
return 0
11661214
}
11671215

0 commit comments

Comments
 (0)