From 6439997b493cbb3bddb5f1deff0fb3e13460049c Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: May 13 2022 03:22:05 +0000 Subject: fix a calculation error in get_system_size Resolves: bz2074473 Upstream: Fedora Conflict: None commit 5c23b6ebb79c5e06ff713d437cb54fb2843aa12d Author: Coiby Xu Date: Sat May 7 16:30:39 2022 +0800 fix a calculation error in get_system_size Recently, it's found 'kdumpctl estimate' returns 512M while the system reserves 1024M kdump memory in a case. This happens because the ranges in /proc/iomem are inclusively. For example, "0-1: System RAM" means 2 bytes of system memory other than 1 byte. Fix this error by adding one more byte. Note 1. the function has been simplified as well. 2. define PROC_IOMEM as /proc/iomem for the sake of unit tests Reported-by: Ruowen Qin Fixes: 1813189 ("kdump-lib.sh: introduce functions to return recommened mem size") Suggested-by: Philipp Rudo Signed-off-by: Coiby Xu Reviewed-by: Philipp Rudo Signed-off-by: Coiby Xu --- diff --git a/kdump-lib.sh b/kdump-lib.sh index 4d9fed7..b6a5afd 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -785,17 +785,12 @@ prepare_cmdline() echo "$cmdline" } -#get system memory size in the unit of GB +PROC_IOMEM=/proc/iomem +#get system memory size i.e. memblock.memory.total_size in the unit of GB get_system_size() { - result=$(grep "System RAM" /proc/iomem | 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' -e 's/+/-0x/g' -e 's/K/+/g') - size=$(printf "%d\n" $((sum))) - size=$((size / 1024 / 1024 / 1024)) - - echo "$size" + sum=$(sed -n "s/\s*\([0-9a-fA-F]\+\)-\([0-9a-fA-F]\+\) : System RAM$/+ 0x\2 - 0x\1 + 1/p" $PROC_IOMEM) + echo $(( (sum) / 1024 / 1024 / 1024)) } get_recommend_size()