fix a calculation error in get_system_size

Resolves: bz2074473
Upstream: Fedora
Conflict: None

commit 5c23b6ebb79c5e06ff713d437cb54fb2843aa12d
Author: Coiby Xu <coxu@redhat.com>
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 <ruqin@redhat.com>
    Fixes: 1813189 ("kdump-lib.sh: introduce functions to return recommened mem size")
    Suggested-by: Philipp Rudo <prudo@redhat.com>
    Signed-off-by: Coiby Xu <coxu@redhat.com>
    Reviewed-by: Philipp Rudo <prudo@redhat.com>

Signed-off-by: Coiby Xu <coxu@redhat.com>
This commit is contained in:
Coiby Xu 2022-05-13 11:22:05 +08:00
parent 23f151d7b5
commit 6439997b49
1 changed files with 4 additions and 9 deletions

View File

@ -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()