There is requirement to decide the recommended memory size for the current system.
Implementing a script to achieve it.
Signed-off-by: Pingfan Liu piliu@redhat.com --- kdump-lib-memsz.sh | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ kexec-tools.spec | 2 ++ 2 files changed, 68 insertions(+) create mode 100644 kdump-lib-memsz.sh
diff --git a/kdump-lib-memsz.sh b/kdump-lib-memsz.sh new file mode 100644 index 0000000..d524a9f --- /dev/null +++ b/kdump-lib-memsz.sh @@ -0,0 +1,66 @@ +#!/bin/sh +# kdump-api-memsz.sh +# return recommended size based on current system RAM size + +#get system memory size in the unit of GB +get_system_size() +{ + result=$( cat /proc/iomem | grep "System RAM" | awk -F ":" {' print $1 '} | tr [:lower:] [:upper:] | paste -sd+ ) + result="+$result" + # replace '-' with '+0x' and '+' with '-0x' + sum=$( echo $result | sed -e 's/-/K0x/g' | sed -e 's/+/-0x/g' | sed -e 's/K/+/g' ) + size=$(printf "%d\n" $(($sum))) + let size=$size/1024/1024/1024 + + echo $size +} + +get_recommend_size() +{ + local mem_size=$1 + local _ck_cmdline=$2 + + last_sz="" + last_unit="" + + 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 + let size=$size*1024 + fi + if [ $mem_size -lt $size ]; then + echo $recommend + return + fi + done + unset IFS +} + +. /lib/kdump/kdump-lib.sh + +arch=$( lscpu | grep Architecture | awk -F ":" {' print $2 '} | tr [:lower:] [:upper:] ) + +if [ $arch == "X86_64" ] || [ $arch == "S390" ]; then + ck_cmdline="1G-4G:160M,4G-64G:192M,64G-1T:256M,1T-:512M" +elif [ $arch == "ARM64" ]; then + ck_cmdline="2G-:448M" +elif [ $arch == "PPC64LE" ]; then + if is_fadump_capable; then + ck_cmdline="4G-16G:768M,16G-64G:1G,64G-128G:2G,128G-1T:4G,1T-2T:6G,2T-4T:12G,4T-8T:20G,8T-16T:36G,16T-32T:64G,32T-64T:128G,64T-:180G" + else + ck_cmdline="2G-4G:384M,4G-16G:512M,16G-64G:1G,64G-128G:2G,128G-:4G" + fi +fi + +ck_cmdline=$( echo $ck_cmdline | sed -e 's/-:/-102400T:/g' ) + +sys_mem=$(get_system_size) + +result=$( get_recommend_size $sys_mem "$ck_cmdline" ) + +echo $result diff --git a/kexec-tools.spec b/kexec-tools.spec index 623274c..7f982c6 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -38,6 +38,7 @@ Source28: kdump-udev-throttler Source29: kdump.sysconfig.aarch64 Source30: 60-kdump.install Source31: kdump-logger.sh +Source32: kdump-lib-memsz.sh
####################################### # These are sources for mkdumpramfs @@ -192,6 +193,7 @@ install -m 644 %{SOURCE25} $RPM_BUILD_ROOT%{_mandir}/man8/kdumpctl.8 install -m 755 %{SOURCE20} $RPM_BUILD_ROOT%{_prefix}/lib/kdump/kdump-lib.sh install -m 755 %{SOURCE23} $RPM_BUILD_ROOT%{_prefix}/lib/kdump/kdump-lib-initramfs.sh install -m 755 %{SOURCE31} $RPM_BUILD_ROOT%{_prefix}/lib/kdump/kdump-logger.sh +install -m 755 %{SOURCE32} $RPM_BUILD_ROOT%{_prefix}/lib/kdump/kdump-lib-memsz.sh %ifnarch s390x install -m 755 %{SOURCE28} $RPM_BUILD_ROOT%{_udevrulesdir}/../kdump-udev-throttler %endif
Tested the above patch successfully on PowerPC and x86 architecture with different memory configuration. The new script is able to return/print recommended memory values based on the system memory.
Although the script works fine in most of the cases but I have found two cases where I am not sure whether the script behaviour is intentional or random.
1) for non-root user the System RAM in /proc/iomem is 00000000-00000000 so the script always returns the very first entry in ck_cmdline.
2) There is no defined path for unsupported architectures. Can we avoid calling get_recommend_size function if system architecture is not supported.
Thanks, Sourabh Jain
On 12/21/20 12:16 AM, Sourabh Jain wrote:
Tested the above patch successfully on PowerPC and x86 architecture with different memory configuration. The new script is able to return/print recommended memory values based on the system memory.
Although the script works fine in most of the cases but I have found two cases where I am not sure whether the script behaviour is intentional or random.
- for non-root user the System RAM in /proc/iomem is 00000000-00000000 so the script always returns the very first entry in ck_cmdline.
Yes, it is a challenge. I had thought about something like "lsmem", but hesitate because reserve_crashkernel() evaluates memory size by ioresource, which is present to user space through /proc/iomem.
While lsmem has a coarse grain, and can not realize the actual memory size of non full populated memory block. Also it does not work on RHEL8 arm64 platform. (this API library is not only for FFDC, so we also want it can run on other platforms )
- There is no defined path for unsupported architectures. Can we avoid calling get_recommend_size function if system architecture is not supported.
/proc/iomem is supported on arm64/s390x/powerpc/x86. For other platforms, we just omit them.
Thanks, Pingfan
Thanks, Sourabh Jain _______________________________________________ kexec mailing list -- kexec@lists.fedoraproject.org To unsubscribe send an email to kexec-leave@lists.fedoraproject.org Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/ List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedoraproject.org/archives/list/kexec@lists.fedoraproject.org
Hi Sourabh,
I can not figure out a better way at present, just a trick, see the comment inline.
On 1/6/21 11:40 AM, piliu wrote:
On 12/21/20 12:16 AM, Sourabh Jain wrote:
Tested the above patch successfully on PowerPC and x86 architecture with different memory configuration. The new script is able to return/print recommended memory values based on the system memory.
Although the script works fine in most of the cases but I have found two cases where I am not sure whether the script behaviour is intentional or random.
- for non-root user the System RAM in /proc/iomem is
00000000-00000000 so the script always returns the very first entry in ck_cmdline.
Yes, it is a challenge. I had thought about something like "lsmem", but hesitate because reserve_crashkernel() evaluates memory size by ioresource, which is present to user space through /proc/iomem.
This is the core of the problem, which can not be stepped around easily.
But what about let kdump service runs the script and save the result in a tmp file. Then later FFDC can read from the tmp file. Or if FFDC can ask users to run as root?
Thanks, Pingfan
While lsmem has a coarse grain, and can not realize the actual memory size of non full populated memory block. Also it does not work on RHEL8 arm64 platform. (this API library is not only for FFDC, so we also want it can run on other platforms )
- There is no defined path for unsupported architectures. Can we
avoid callingĀ get_recommend_size function if system architecture is not supported.
/proc/iomem is supported on arm64/s390x/powerpc/x86. For other platforms, we just omit them.
Thanks, Pingfan
Thanks, Sourabh Jain _______________________________________________ kexec mailing list -- kexec@lists.fedoraproject.org To unsubscribe send an email to kexec-leave@lists.fedoraproject.org Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/ List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedoraproject.org/archives/list/kexec@lists.fedoraproject.org
kexec mailing list -- kexec@lists.fedoraproject.org To unsubscribe send an email to kexec-leave@lists.fedoraproject.org Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/ List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedoraproject.org/archives/list/kexec@lists.fedoraproject.org
Hi Sourabh,
I can not figure out a better way at present, just a trick, see the comment inline.
On 1/6/21 11:40 AM, piliu wrote:
This is the core of the problem, which can not be stepped around easily.
But what about let kdump service runs the script and save the result in a tmp file. Then later FFDC can read from the tmp file. Or if FFDC can ask users to run as root?
Thanks, Pingfan Hi Sourabh,
I can not figure out a better way at present, just a trick, see the comment inline.
On 1/6/21 11:40 AM, piliu wrote:
This is the core of the problem, which can not be stepped around easily.
But what about let kdump service runs the script and save the result in a tmp file. Then later FFDC can read from the tmp file. Or if FFDC can ask users to run as root?
This could be a potential solution but I would prefer this script to be a standalone script returning the crashkernel values rather writing it to some file.
I think for the time being let the script handle root and non-root thing the way it is.
Thanks, Sourabh Jain
On 12/21/20 12:16 AM, Sourabh Jain wrote: Yes, it is a challenge. I had thought about something like "lsmem", but hesitate because reserve_crashkernel() evaluates memory size by ioresource, which is present to user space through /proc/iomem.
While lsmem has a coarse grain, and can not realize the actual memory size of non full populated memory block. Also it does not work on RHEL8 arm64 platform. (this API library is not only for FFDC, so we also want it can run on other platforms )
Yeah agree. Just wanted to confirm that the script behaviour for non-root user is expected.
/proc/iomem is supported on arm64/s390x/powerpc/x86. For other platforms, we just omit them.
Agree. But is it possible to have else condition where we find ck_cmdline based on the architecture type and exit if unsupported architecture found? This way we can avoid calling get_system_size and get_recommend_size function because we already know the result generated by this function is anyways not relevant.
Except small optimization on unsupported architecture, the script looks good to me.
Thanks, Sourabh Jain