Skip to content

Commit 7602d66

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 532ad21 commit 7602d66

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
@@ -1210,6 +1210,53 @@ prepare_luks()
12101210
done
12111211
}
12121212

1213+
get_crashkernel_bounce_buffer_size()
1214+
{
1215+
local lines first_line start_hex end_hex start_dec end_dec size_bytes
1216+
1217+
mapfile -t lines < <(grep "Crash kernel" /proc/iomem)
1218+
1219+
if [ ${#lines[@]} -le 1 ]; then
1220+
echo 0
1221+
return
1222+
fi
1223+
1224+
first_line=${lines[0]}
1225+
# Extract start and end addresses
1226+
start_hex=$(echo "$first_line" | awk '{split($1, a, "-"); print a[1]}')
1227+
end_hex=$(echo "$first_line" | awk '{split($1, a, "-"); print a[2]}')
1228+
# Convert hex to decimal
1229+
start_dec=$((0x$start_hex))
1230+
end_dec=$((0x$end_hex))
1231+
# Calculate size in bytes
1232+
size_bytes=$((end_dec - start_dec + 1))
1233+
echo "$size_bytes"
1234+
}
1235+
1236+
suggest_crashkernel_reset()
1237+
{
1238+
local _crashkernel _recommend_value _actual_value _bounce_buff_size
1239+
1240+
_crashkernel=$(sed -n 's/.*crashkernel=\([^ ]*\).*/\1/p' /proc/cmdline)
1241+
[[ $(kdump_get_conf_val auto_reset_crashkernel) == no ]] && return
1242+
# At present, the crashkernel value for fadump is not dynamic
1243+
is_fadump_capable && return
1244+
1245+
_recommend_value=$(kdump_get_arch_recommend_size)
1246+
# The crashkernel formula does not account for DMA-bounce buffers,
1247+
# unlike kexec_crash_size which does. Systems using DMA-bounce buffers
1248+
# should factor this into the calculation.
1249+
_bounce_buff_size=$(get_crashkernel_bounce_buffer_size)
1250+
_recommend_value=$(memsize_add "$_recommend_value" "$_bounce_buff_size")
1251+
_recommend_value=$(to_bytes "$_recommend_value")
1252+
_actual_value=$(cat /sys/kernel/kexec_crash_size)
1253+
1254+
if [ "$_recommend_value" -lt "$_actual_value" ]; then
1255+
dwarn "The reserved crashkernel is abundant. Using 'kdumpctl reset-crashkernel' to reset kernel cmdline. It will take effect in the next boot"
1256+
dwarn "To release the abundant memory immediately, you can run: 'kdumpctl stop; echo $_recommend_value >/sys/kernel/kexec_crash_size; kdumpctl start'"
1257+
fi
1258+
}
1259+
12131260
start()
12141261
{
12151262
check_dump_feasibility || return
@@ -1243,6 +1290,7 @@ start()
12431290
start_dump || return
12441291

12451292
dinfo "Starting kdump: [OK]"
1293+
suggest_crashkernel_reset
12461294
return 0
12471295
}
12481296

0 commit comments

Comments
 (0)