On Thu, May 12, 2022 at 12:08:46PM +0200, Philipp Rudo wrote:
On Thu, 12 May 2022 12:19:23 +0800
Coiby Xu <coxu(a)redhat.com> wrote:
> This patch rewrites get_recommend_size to get rid of the following
> limitations,
> 1. only supports ranges in crashkernel sorted in increasing order
> 2. the first entry of crashkernel should have only a single digit and
> it's in gigabytes
>
> Suggested-by: Philipp Rudo <prudo(a)redhat.com>
> Signed-off-by: Coiby Xu <coxu(a)redhat.com>
> ---
> kdump-lib.sh | 47 +++++++++++++++++++++++++++--------------------
> 1 file changed, 27 insertions(+), 20 deletions(-)
>
> diff --git a/kdump-lib.sh b/kdump-lib.sh
> index ed28df3..eba2c38 100755
> --- a/kdump-lib.sh
> +++ b/kdump-lib.sh
> @@ -796,33 +796,40 @@ get_system_size()
> echo $(( (sum) / 1024 / 1024 / 1024))
> }
>
> +# Return the recommended size for the reserved crashkernel memory
> +# depending on the system memory size.
> +#
> +# This functions is expected to be consistent with the reserve_crashkernel() in
> +# kernel i.e. how kernel allocates the kdump memory given the crashkernel
> +# parameter crashkernel=range1:size1[,range2:size2,…] and the system memory
> +# size.
the comment is much better now. But I'm still curious why to reference
reserve_crashkernel here. For me this function needs to copy the
behavior of parse_crashkernel_mem. So I would rather reference this
functions.
Yes, parse_crashkernel_mem is better. I referenced it because the
original commit mentioned reserve_crashkernel. I've merged this patch
with your suggestion applied. Thanks!
Anyway, it's only a small nit
Reviewed-by: Philipp Rudo <prudo(a)redhat.com>
> get_recommend_size()
> {
> local mem_size=$1
> local _ck_cmdline=$2
> - local OLDIFS="$IFS"
> + local range start start_unit end end_unit size
>
> - start=${_ck_cmdline::1}
> - if [[ $mem_size -lt $start ]]; then
> - echo "0M"
> - return
> - fi
> - IFS=','
> - for i in $_ck_cmdline; do
> - end=$(echo "$i" | awk -F "-" '{ print $2 }' | awk -F
":" '{ print $1 }')
> - recommend=$(echo "$i" | awk -F "-" '{ print $2 }' |
awk -F ":" '{ print $2 }')
> - size=${end::-1}
> - unit=${end: -1}
> - if [[ $unit == 'T' ]]; then
> - size=$((size * 1024))
> - fi
> - if [[ $mem_size -lt $size ]]; then
> - echo "$recommend"
> - IFS="$OLDIFS"
> + while read -r -d , range; do
> + # need to use non-default IFS as double spaces are used as a
> + # single delimiter while commas aren't...
> + IFS=, read start start_unit end end_unit size <<< \
> + "$(echo "$range" | sed -n
"s/\([0-9]\+\)\([GT]\?\)-\([0-9]*\)\([GT]\?\):\([0-9]\+[MG]\)/\1,\2,\3,\4,\5/p")"
> +
> + # aka. 102400T
> + end=${end:-104857600}
> + [[ "$end_unit" == T ]] && end=$((end * 1024))
> + [[ "$start_unit" == T ]] && start=$((start * 1024))
> +
> + if [[ $mem_size -ge $start ]] && [[ $mem_size -lt $end ]]; then
> + echo "$size"
> return
> fi
> - done
> - IFS="$OLDIFS"
> +
> + # append a ',' as read expects the 'file' to end with a delimiter
> + done <<< "$_ck_cmdline,"
> +
> + # no matching range found
> + echo "0M"
> }
>
> # get default crashkernel
--
Best regards,
Coiby