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>
This commit is contained in:
parent
3d70f8b049
commit
5c23b6ebb7
13
kdump-lib.sh
13
kdump-lib.sh
@ -788,17 +788,12 @@ prepare_cmdline()
|
|||||||
echo "$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()
|
get_system_size()
|
||||||
{
|
{
|
||||||
result=$(grep "System RAM" /proc/iomem | awk -F ":" '{ print $1 }' | tr "[:lower:]" "[:upper:]" | paste -sd+)
|
sum=$(sed -n "s/\s*\([0-9a-fA-F]\+\)-\([0-9a-fA-F]\+\) : System RAM$/+ 0x\2 - 0x\1 + 1/p" $PROC_IOMEM)
|
||||||
result="+$result"
|
echo $(( (sum) / 1024 / 1024 / 1024))
|
||||||
# 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"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get_recommend_size()
|
get_recommend_size()
|
||||||
|
Loading…
Reference in New Issue
Block a user