Skip to content

Commit 51b300e

Browse files
rpardiniigorpecovnik
authored andcommitted
armbian-kernel.sh: introduce KERNEL_BTF=no to opt-out of BTF/CO-RE type-info on low-RAM machines
- turns out `pahole` for `vmlinux` can take multiple gigabytes of RAM to run successfully - I can't simply decide based on available RAM, as that would make .config hashes mismatch - thus, introduce: - default is to enable BTF; if on low-ram host, error out unless KERNEL_BTF=yes is passed - if KERNEL_BTF=no is passed, the BTF debug info is always disabled - if KERNEL_BTF=yes is passed, then a warning is produced, but BTF is still enabled - the magic number "6451 MiB" was determined empirically (and is probably bs)
1 parent cb6f2fb commit 51b300e

File tree

1 file changed

+65
-36
lines changed

1 file changed

+65
-36
lines changed

lib/functions/compilation/armbian-kernel.sh

+65-36
Original file line numberDiff line numberDiff line change
@@ -57,51 +57,46 @@ function armbian_kernel_config__disable_various_options() {
5757
fi
5858
}
5959

60-
function armbian_kernel_config__600_enable_ebpf_and_btf_info() {
61-
display_alert "Enabling eBPF and BTF info" "for fully BTF & CO-RE enabled kernel" "info"
62-
60+
function armbian_kernel_config__force_pa_va_48_bits_on_arm64() {
6361
declare -A opts_val=()
64-
declare -a opts_n=("CONFIG_DEBUG_INFO_NONE")
65-
declare -a opts_y=(
66-
"CONFIG_BPF_JIT" "CONFIG_BPF_JIT_DEFAULT_ON" "CONFIG_FTRACE_SYSCALLS" "CONFIG_PROBE_EVENTS_BTF_ARGS" "CONFIG_BPF_KPROBE_OVERRIDE"
67-
"CONFIG_DEBUG_INFO" "CONFIG_DEBUG_INFO_DWARF5"
68-
"CONFIG_DEBUG_INFO_BTF" "CONFIG_DEBUG_INFO_BTF_MODULES"
69-
)
70-
62+
declare -a opts_y=() opts_n=()
7163
if [[ "${ARCH}" == "arm64" ]]; then
7264
opts_y+=("CONFIG_ARM64_VA_BITS_48")
7365
opts_val["CONFIG_ARM64_PA_BITS"]="48"
7466
fi
67+
armbian_kernel_config_apply_opts_from_arrays
68+
}
7569

76-
declare opt_y opt_val opt_n
77-
for opt_n in "${opts_n[@]}"; do
78-
kernel_config_modifying_hashes+=("${opt_n}=n")
79-
done
80-
81-
for opt_y in "${opts_y[@]}"; do
82-
kernel_config_modifying_hashes+=("${opt_y}=y")
83-
done
84-
85-
for opt_val in "${!opts_val[@]}"; do
86-
kernel_config_modifying_hashes+=("${opt_val}=${opts_val[$opt_val]}")
87-
done
88-
89-
if [[ -f .config ]]; then
90-
for opt_n in "${opts_n[@]}"; do
91-
display_alert "Disabling kernel opt" "${opt_n}=n" "debug"
92-
kernel_config_set_n "${opt_n}"
93-
done
70+
function armbian_kernel_config__600_enable_ebpf_and_btf_info() {
71+
declare -A opts_val=()
72+
declare -a opts_y=() opts_n=()
9473

95-
for opt_y in "${opts_y[@]}"; do
96-
display_alert "Enabling kernel opt" "${opt_y}=y" "debug"
97-
kernel_config_set_y "${opt_y}"
98-
done
74+
if [[ "${KERNEL_BTF}" == "no" ]]; then # If user is explicit by passing "KERNEL_BTF=no", then actually disable all debug info.
75+
display_alert "Disabling eBPF and BTF info for kernel" "as requested by KERNEL_BTF=no" "info"
76+
opts_y+=("CONFIG_DEBUG_INFO_NONE") # Enable the "none" option
77+
opts_n+=("CONFIG_DEBUG_INFO" "CONFIG_DEBUG_INFO_DWARF5" "CONFIG_DEBUG_INFO_BTF" "CONFIG_DEBUG_INFO_BTF_MODULES") # BTF & CO-RE == off
78+
# We don't disable the eBPF options, as eBPF itself doesn't require BTF (debug info) and doesnt' consume as much memory during build as BTF debug info does.
79+
else
80+
declare -i available_physical_memory_mib
81+
available_physical_memory_mib=$(($(awk '/MemAvailable/ {print $2}' /proc/meminfo) / 1024)) # MiB
82+
display_alert "Considering available RAM for BTF build" "${available_physical_memory_mib} MiB" "info"
83+
84+
if [[ ${available_physical_memory_mib} -lt 6451 ]]; then # If less than 6451 MiB of RAM is available, then exit with an error, telling the user to avoid pain and set KERNEL_BTF=no ...
85+
if [[ "${KERNEL_BTF}" == "yes" ]]; then # ... except if the user knows better, and has set KERNEL_BTF=yes, then we'll just warn.
86+
display_alert "Not enough RAM available (${available_physical_memory_mib}Mib) for BTF build" "but KERNEL_BTF=yes is set; enabling BTF" "warn"
87+
else
88+
exit_with_error "Not enough RAM available (${available_physical_memory_mib}Mib) for BTF build. Please set 'KERNEL_BTF=no' to avoid running out of memory during the kernel LD/BTF build step; or ignore this check by setting 'KERNEL_BTF=yes' -- that might put a lot of load on your swap disk, if any."
89+
fi
90+
fi
9991

100-
for opt_val in "${!opts_val[@]}"; do
101-
display_alert "Setting kernel opt" "${opt_val}=${opts_val[$opt_val]}" "debug"
102-
kernel_config_set_val "${opt_val}" "${opts_val[$opt_val]}"
103-
done
92+
display_alert "Enabling eBPF and BTF info" "for fully BTF & CO-RE enabled kernel" "info"
93+
opts_n+=("CONFIG_DEBUG_INFO_NONE") # Make sure the "none" option is disabled
94+
opts_y+=(
95+
"CONFIG_BPF_JIT" "CONFIG_BPF_JIT_DEFAULT_ON" "CONFIG_FTRACE_SYSCALLS" "CONFIG_PROBE_EVENTS_BTF_ARGS" "CONFIG_BPF_KPROBE_OVERRIDE" # eBPF == on
96+
"CONFIG_DEBUG_INFO" "CONFIG_DEBUG_INFO_DWARF5" "CONFIG_DEBUG_INFO_BTF" "CONFIG_DEBUG_INFO_BTF_MODULES" # BTF & CO-RE == off
97+
)
10498
fi
99+
armbian_kernel_config_apply_opts_from_arrays
105100

106101
return 0
107102
}
@@ -166,3 +161,37 @@ function kernel_config_set_val() {
166161
display_alert "Setting kernel config/module value" "${config}=${value}" "debug"
167162
run_host_command_logged ./scripts/config --set-val "${config}" "${value}"
168163
}
164+
165+
# This takes opts_n, opts_y, arrays from parent scope; also the opts_val dictionary;
166+
# it and applies them to the hashes and to the .config if it exists.
167+
function armbian_kernel_config_apply_opts_from_arrays() {
168+
declare opt_y opt_val opt_n
169+
for opt_n in "${opts_n[@]}"; do
170+
kernel_config_modifying_hashes+=("${opt_n}=n")
171+
done
172+
173+
for opt_y in "${opts_y[@]}"; do
174+
kernel_config_modifying_hashes+=("${opt_y}=y")
175+
done
176+
177+
for opt_val in "${!opts_val[@]}"; do
178+
kernel_config_modifying_hashes+=("${opt_val}=${opts_val[$opt_val]}")
179+
done
180+
181+
if [[ -f .config ]]; then
182+
for opt_n in "${opts_n[@]}"; do
183+
display_alert "Disabling kernel opt" "${opt_n}=n" "debug"
184+
kernel_config_set_n "${opt_n}"
185+
done
186+
187+
for opt_y in "${opts_y[@]}"; do
188+
display_alert "Enabling kernel opt" "${opt_y}=y" "debug"
189+
kernel_config_set_y "${opt_y}"
190+
done
191+
192+
for opt_val in "${!opts_val[@]}"; do
193+
display_alert "Setting kernel opt" "${opt_val}=${opts_val[$opt_val]}" "debug"
194+
kernel_config_set_val "${opt_val}" "${opts_val[$opt_val]}"
195+
done
196+
fi
197+
}

0 commit comments

Comments
 (0)