On Fri, Nov 19, 2021 at 01:10:37PM +0800, Pingfan Liu wrote:
On Fri, Nov 19, 2021 at 11:23:05AM +0800, Coiby Xu wrote:
> Say let's add extra 20M to
> "2G-4G:384M,4G-16G:512M,16G-64G:1G,64G-128G:2G,128G-:4G",
> add_extra_mem_to_crashkernel will cover the above string to
> "2G-4G:406M,4G-16G:534M,16G-64G:1046M,64G-128G:2070M,128G-:4118M"
>
The "crashkernel=" is a practice value. There is no connection between
the scale of the different system memory size.
I do not strongly argue, but maybe let user explictly to set a value is
a better choice.
Thanks for the suggestion! But according to CEE, a significant number of users
want kdump to work out of box i.e. not bothering to set a value by
him/herself. This patch is actually a preparation for reserving extra
memory when SME or SEV is active which has been implemented in the kernel
space in RHEL8.
Thanks,
Pingfan
> Signed-off-by: Coiby Xu <coxu(a)redhat.com>
> ---
> kdump-lib.sh | 35 +++++++++++++++++++++++++++++++++++
> 1 file changed, 35 insertions(+)
>
> diff --git a/kdump-lib.sh b/kdump-lib.sh
> index 94cc8ff..5c79436 100755
> --- a/kdump-lib.sh
> +++ b/kdump-lib.sh
> @@ -822,6 +822,41 @@ get_recommend_size()
> IFS="$OLDIFS"
> }
>
> +# add memory to crashkernel string
> +# $1 extra memory size, unit:M
> +# return crashkernel string (unit=M)
> +add_extra_mem_to_crashkernel()
> +{
> + local _extra_mem="$1" _ck_cmdline="$2" _new_ck_cmdline
> + local _range _mem _size _unit _ele _new_ele
> + local OLDIFS="$IFS"
> +
> + IFS=','
> + for _ele in $_ck_cmdline; do
> + _range=$(awk -F ":" '{print $1}' <<<
"$_ele")
> + _mem=$(awk -F ":" '{print $2}' <<< "$_ele")
> + _size=${_mem::-1}
> + _unit=${_mem: -1}
> + if [[ $_unit != "M" ]] && [[ $_unit != "G" ]]; then
> + perror_exit "can't process $_unit"
> + fi
> +
> + if [[ $_unit == 'G' ]]; then
> + _size=$((_size * 1024))
> + fi
> + _size=$((_size + _extra_mem))
> +
> + _new_ele="${_range}:${_size}M"
> + if [[ -z $_new_ck_cmdline ]]; then
> + _new_ck_cmdline=$_new_ele
> + else
> + _new_ck_cmdline="${_new_ck_cmdline},${_new_ele}"
> + fi
> + done
> + IFS="$OLDIFS"
> + echo -n "$_new_ck_cmdline"
> +}
> +
> # get default crashkernel
> # $1 dump mode, if not specified, dump_mode will be judged by is_fadump_capable
> kdump_get_arch_recommend_crashkernel()
> --
> 2.31.1
>
--
Best regards,
Coiby