Skip to content

Commit 4178970

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 7af341e commit 4178970

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
@@ -1191,6 +1191,53 @@ prepare_luks()
11911191
done
11921192
}
11931193

1194+
get_crashkernel_bounce_buffer_size()
1195+
{
1196+
local lines first_line start_hex end_hex start_dec end_dec size_bytes
1197+
1198+
mapfile -t lines < <(grep "Crash kernel" /proc/iomem)
1199+
1200+
if [ ${#lines[@]} -le 1 ]; then
1201+
echo 0
1202+
return
1203+
fi
1204+
1205+
first_line=${lines[0]}
1206+
# Extract start and end addresses
1207+
start_hex=$(echo "$first_line" | awk '{split($1, a, "-"); print a[1]}')
1208+
end_hex=$(echo "$first_line" | awk '{split($1, a, "-"); print a[2]}')
1209+
# Convert hex to decimal
1210+
start_dec=$((0x$start_hex))
1211+
end_dec=$((0x$end_hex))
1212+
# Calculate size in bytes
1213+
size_bytes=$((end_dec - start_dec + 1))
1214+
echo "$size_bytes"
1215+
}
1216+
1217+
suggest_crashkernel_reset()
1218+
{
1219+
local _crashkernel _recommend_value _actual_value _bounce_buff_size
1220+
1221+
_crashkernel=$(sed -n 's/.*crashkernel=\([^ ]*\).*/\1/p' /proc/cmdline)
1222+
[[ $(kdump_get_conf_val auto_reset_crashkernel) == no ]] && return
1223+
# At present, the crashkernel value for fadump is not dynamic
1224+
is_fadump_capable && return
1225+
1226+
_recommend_value=$(kdump_get_arch_recommend_size)
1227+
# The crashkernel formula does not account for DMA-bounce buffers,
1228+
# unlike kexec_crash_size which does. Systems using DMA-bounce buffers
1229+
# should factor this into the calculation.
1230+
_bounce_buff_size=$(get_crashkernel_bounce_buffer_size)
1231+
_recommend_value=$(memsize_add "$_recommend_value" "$_bounce_buff_size")
1232+
_recommend_value=$(to_bytes "$_recommend_value")
1233+
_actual_value=$(cat /sys/kernel/kexec_crash_size)
1234+
1235+
if [ "$_recommend_value" -lt "$_actual_value" ]; then
1236+
dwarn "The reserved crashkernel is abundant. Using 'kdumpctl reset-crashkernel' to reset kernel cmdline. It will take effect in the next boot"
1237+
dwarn "To release the abundant memory immediately, you can run: 'kdumpctl stop; echo $_recommend_value >/sys/kernel/kexec_crash_size; kdumpctl start'"
1238+
fi
1239+
}
1240+
11941241
start()
11951242
{
11961243
check_dump_feasibility || return
@@ -1224,6 +1271,7 @@ start()
12241271
start_dump || return
12251272

12261273
dinfo "Starting kdump: [OK]"
1274+
suggest_crashkernel_reset
12271275
return 0
12281276
}
12291277

0 commit comments

Comments
 (0)