Skip to content

Commit a79c1c7

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 7bb677b commit a79c1c7

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

kdumpctl

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,83 @@ check_final_action_config()
10511051
esac
10521052
}
10531053

1054+
get_recommend_crashkernel_value()
1055+
{
1056+
local _crashkernel_str=$1
1057+
local _total_mem_kib
1058+
local _total_mem
1059+
1060+
_total_mem_kib=$(grep MemTotal /proc/meminfo | awk '{print $2}')
1061+
_total_mem=$((_total_mem_kib * 1024))
1062+
1063+
# Main loop
1064+
IFS=',' read -ra entries <<< "$_crashkernel_str"
1065+
for entry in "${entries[@]}"; do
1066+
IFS=':' read -r range size <<< "$entry"
1067+
# Parse range
1068+
if [[ $range == *-* ]]; then
1069+
IFS='-' read -r lower upper <<< "$range"
1070+
lower_bytes=$(to_bytes "$lower")
1071+
if [[ -z "$upper" ]]; then
1072+
upper_bytes=$(to_bytes 10T) # for open-ended range (e.g., 2G-)
1073+
else
1074+
upper_bytes=$(to_bytes "$upper")
1075+
fi
1076+
if (( _total_mem >= lower_bytes && _total_mem < upper_bytes )); then
1077+
echo "$size"
1078+
return
1079+
fi
1080+
fi
1081+
done
1082+
}
1083+
1084+
get_crashkernel_low_value()
1085+
{
1086+
mapfile -t lines < <(grep -n "Crash kernel" /proc/iomem)
1087+
1088+
if [ ${#lines[@]} -eq 1 ]; then
1089+
return 0
1090+
fi
1091+
1092+
first_line=$(grep "Crash kernel" /proc/iomem | sed -n '1p')
1093+
# Extract start and end addresses
1094+
start_hex=$(echo "$first_line" | awk '{split($1, a, "-"); print a[1]}')
1095+
end_hex=$(echo "$first_line" | awk '{split($1, a, "-"); print a[2]}')
1096+
# Convert hex to decimal
1097+
start_dec=$((0x$start_hex))
1098+
end_dec=$((0x$end_hex))
1099+
# Calculate size in bytes
1100+
size_bytes=$((end_dec - start_dec + 1))
1101+
echo "$size_bytes"
1102+
}
1103+
1104+
suggest_crashkernel_reset()
1105+
{
1106+
local _crashkernel
1107+
local _recommend
1108+
local _recommend_value
1109+
local _actual_value
1110+
1111+
_crashkernel=$(sed -n 's/.*crashkernel=\([^ ]*\).*/\1/p' /proc/cmdline)
1112+
[[ $(kdump_get_conf_val auto_reset_crashkernel) == no ]] && return
1113+
1114+
if ! echo "$_crashkernel" | grep -q -E "(fadump|fadump=0)"; then
1115+
_recommend=$(kdump_get_arch_recommend_crashkernel "kdump")
1116+
_recommend_value=$(get_recommend_crashkernel_value "$_recommend")
1117+
_low_mem=$(get_crashkernel_low_value)
1118+
# The crashkernel formula does not include the crashkernel low value
1119+
# but the kexec_crash_size does.
1120+
_recommend_value=$(memsize_add "$_recommend_value" "$_low_mem")
1121+
_recommend_value=$(to_bytes "$_recommend_value")
1122+
_actual_value=$(cat /sys/kernel/kexec_crash_size)
1123+
1124+
if [ "$_recommend_value" -lt "$_actual_value" ]; then
1125+
dwarn "The reserved crashkernel is abundant. Using 'kdumpctl reset-crashkernel' to reset kernel cmdline. It will take effect in the next boot"
1126+
dwarn "To release the abundant memory immediately. You can do: 'kdumpctl stop', 'echo $_recommend_value >/sys/kernel/kexec_crash_size', and finally 'kdump start'"
1127+
fi
1128+
fi
1129+
}
1130+
10541131
start()
10551132
{
10561133
check_dump_feasibility || return
@@ -1084,6 +1161,7 @@ start()
10841161
start_dump || return
10851162

10861163
dinfo "Starting kdump: [OK]"
1164+
suggest_crashkernel_reset
10871165
return 0
10881166
}
10891167

0 commit comments

Comments
 (0)