The size of the reserved memory in the functions show_reserved_mem, check_crash_mem_reserved, and do_estimate are fetched from the sysfs node `/sys/kernel/kexec_crash_size`. However, in the case of fadump, the reserved area size is instead present in /sys/kernel/fadump/mem_reserved.
For example:
$ kdumpctl showmem kdump: Dump mode is fadump kdump: Reserved 0MB memory for crash kernel
The above command showed 0MB for Reserved memory which is incorrect, the actual reservation was 2048MB.
To resolve this issue a new helper function is introduced to fetch reserved memory size based on the dump mode. For "fadump" mode, it looks in `/sys/kernel/fadump/mem_reserved`, otherwise, it uses `/sys/kernel/kexec_crash_size`. And all functions that previously fetching reserved memory directly from `/sys/kernel/kexec_crash_size` sysfs node are now updated to use this new function to get the reserved memory size.
With the fix in place, the `kdumpctl showmem` command will now display correct reserved memory size.
$ kdumpctl showmem kdump: Dump mode is fadump kdump: Reserved 2048MB memory for crash kernel
Signed-off-by: Sourabh Jain sourabhjain@linux.ibm.com Reported-by: Sachin P Bappalige sachinpb@linux.vnet.ibm.com --- kdump-lib.sh | 15 ++++++++++++++- kdumpctl | 4 ++-- 2 files changed, 16 insertions(+), 3 deletions(-)
--- Changes from V1: * Introduced a helper function to determine reserved memory size based on dump mode. And it is now used in multiple places instead of only do_estimate function.
---
diff --git a/kdump-lib.sh b/kdump-lib.sh index 4290be3..16238c5 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -344,11 +344,24 @@ is_mount_in_dracut_args() [[ " $(kdump_get_conf_val dracut_args)" =~ .*[[:space:]]--mount[=[:space:]].* ]] }
+get_reserved_mem_size() +{ + local reserved_mem_size=0 + + if is_fadump_capable; then + reserved_mem_size=$(< /sys/kernel/fadump/mem_reserved) + else + reserved_mem_size=$(< /sys/kernel/kexec_crash_size) + fi + + echo "$reserved_mem_size" +} + check_crash_mem_reserved() { local mem_reserved
- mem_reserved=$(< /sys/kernel/kexec_crash_size) + mem_reserved=$(get_reserved_mem_size) if [[ $mem_reserved -eq 0 ]]; then derror "No memory reserved for crash kernel" return 1 diff --git a/kdumpctl b/kdumpctl index 7e561fd..1f7f4ce 100755 --- a/kdumpctl +++ b/kdumpctl @@ -856,7 +856,7 @@ show_reserved_mem() local mem local mem_mb
- mem=$(< /sys/kernel/kexec_crash_size) + mem=$(get_reserved_mem_size) mem_mb=$((mem / 1024 / 1024))
dinfo "Reserved ${mem_mb}MB memory for crash kernel" @@ -1270,7 +1270,7 @@ do_estimate() # The default pre-reserved crashkernel value baseline_size=$((baseline * size_mb)) # Current reserved crashkernel size - reserved_size=$(< /sys/kernel/kexec_crash_size) + reserved_size=$(get_reserved_mem_size) # A pre-estimated value for userspace usage and kernel # runtime allocation, 64M should good for most cases runtime_size=$((64 * size_mb)) -- 2.41.0
On Wed, Aug 02, 2023 at 08:36:48PM +0530, Sourabh Jain wrote:
The size of the reserved memory in the functions show_reserved_mem, check_crash_mem_reserved, and do_estimate are fetched from the sysfs node `/sys/kernel/kexec_crash_size`. However, in the case of fadump, the reserved area size is instead present in /sys/kernel/fadump/mem_reserved.
For example:
$ kdumpctl showmem kdump: Dump mode is fadump kdump: Reserved 0MB memory for crash kernel
The above command showed 0MB for Reserved memory which is incorrect, the actual reservation was 2048MB.
To resolve this issue a new helper function is introduced to fetch reserved memory size based on the dump mode. For "fadump" mode, it looks in `/sys/kernel/fadump/mem_reserved`, otherwise, it uses `/sys/kernel/kexec_crash_size`. And all functions that previously fetching reserved memory directly from `/sys/kernel/kexec_crash_size` sysfs node are now updated to use this new function to get the reserved memory size.
With the fix in place, the `kdumpctl showmem` command will now display correct reserved memory size.
$ kdumpctl showmem kdump: Dump mode is fadump kdump: Reserved 2048MB memory for crash kernel
Signed-off-by: Sourabh Jain sourabhjain@linux.ibm.com Reported-by: Sachin P Bappalige sachinpb@linux.vnet.ibm.com
kdump-lib.sh | 15 ++++++++++++++- kdumpctl | 4 ++-- 2 files changed, 16 insertions(+), 3 deletions(-)
Changes from V1:
- Introduced a helper function to determine reserved memory
size based on dump mode. And it is now used in multiple places instead of only do_estimate function.
diff --git a/kdump-lib.sh b/kdump-lib.sh index 4290be3..16238c5 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -344,11 +344,24 @@ is_mount_in_dracut_args() [[ " $(kdump_get_conf_val dracut_args)" =~ .*[[:space:]]--mount[=[:space:]].* ]] }
+get_reserved_mem_size() +{
- local reserved_mem_size=0
- if is_fadump_capable; then
reserved_mem_size=$(< /sys/kernel/fadump/mem_reserved)
- else
reserved_mem_size=$(< /sys/kernel/kexec_crash_size)
- fi
- echo "$reserved_mem_size"
+}
check_crash_mem_reserved() { local mem_reserved
- mem_reserved=$(< /sys/kernel/kexec_crash_size)
- mem_reserved=$(get_reserved_mem_size) if [[ $mem_reserved -eq 0 ]]; then derror "No memory reserved for crash kernel" return 1
diff --git a/kdumpctl b/kdumpctl index 7e561fd..1f7f4ce 100755 --- a/kdumpctl +++ b/kdumpctl @@ -856,7 +856,7 @@ show_reserved_mem() local mem local mem_mb
- mem=$(< /sys/kernel/kexec_crash_size)
mem=$(get_reserved_mem_size) mem_mb=$((mem / 1024 / 1024))
dinfo "Reserved ${mem_mb}MB memory for crash kernel"
@@ -1270,7 +1270,7 @@ do_estimate() # The default pre-reserved crashkernel value baseline_size=$((baseline * size_mb)) # Current reserved crashkernel size
- reserved_size=$(< /sys/kernel/kexec_crash_size)
- reserved_size=$(get_reserved_mem_size) # A pre-estimated value for userspace usage and kernel # runtime allocation, 64M should good for most cases runtime_size=$((64 * size_mb))
Patched merged, thanks!
Reviewed-by: Coiby Xu coxu@redhat.com