Skip to contentSkip to conversation

kdump: round up the total memory size to 128M for crashkernel reservation

PATCH Superseded Tao Liu 2 participants 2 messages Jun 16, 2022 – Jun 22, 2022

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Tao Liu

author
#0 lore raw

PATCH 1/1 kdump: round up the total memory size to 128M for crashkernel reservation

The total memory size we get in kernel is usually slightly less than 2G with a 2G memory module machine. The main reason is bios/firmware reserve some area it will not export all memory as usable to Linux.

2G memory X86 kvm guest test result of the total_mem value:
UEFI boot with ovmf: 0x7ef10000
Legacy boot kvm guest: 0x7ff7cc00
This is also a problem on arm64 UEFI booted system according to my test.

Thus for example crashkernel=1G-2G:128M, if we have a 1G memory machine, we get total size 1023M from firmware then it will not fall into 1G-2G thus no memory reserved. User will never know that, it is hard to let user to know the exact total value we get in kernel

An option is to use dmi/smbios to get physical memory size, but it's not reliable as well. According to Prarit hardware vendors sometimes screw this up. Thus round up total size to 128M to workaround this problem.

This patch is a resend of [1] and rebased onto v5.19-rc2, and the original credit goes to Dave Young <[email protected]>.

[1]: http://lists.infradead.org/pipermail/kexec/2018-April/020568.html

---
 kernel/crash_core.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
kernel/crash_core.c +12 -2
index 71122e01623c..f6c1ffce9d5a 100644
@@ -9,6 +9,7 @@
 #include <linux/init.h>
 #include <linux/utsname.h>
 #include <linux/vmalloc.h>
+#include <linux/sizes.h>
 
 #include <asm/page.h>
 #include <asm/sections.h>
@@ -43,6 +44,15 @@ static int __init parse_crashkernel_mem(char *cmdline,
 					unsigned long long *crash_base)
 {
 	char *cur = cmdline, *tmp;
+	unsigned long long total_mem = system_ram;
+
+	/*
+	 * Firmware sometimes reserves some memory regions for it's own use.
+	 * so we get less than actual system memory size.
+	 * Workaround this by round up the total size to 128M which is
+	 * enough for most test cases.
+	 */
+	total_mem = roundup(total_mem, SZ_128M);
 
 	/* for each entry of the comma-separated list */
 	do {
@@ -87,13 +97,13 @@ static int __init parse_crashkernel_mem(char *cmdline,
 			return -EINVAL;
 		}
 		cur = tmp;
-		if (size >= system_ram) {
+		if (size >= total_mem) {
 			pr_warn("crashkernel: invalid size\n");
 			return -EINVAL;
 		}
 
 		/* match ? */
-		if (system_ram >= start && system_ram < end) {
+		if (total_mem >= start && total_mem < end) {
 			*crash_size = size;
 			break;
 		}
Signature · 1 line
2.33.1
#1 lore raw

Hi Tao,

Quoted 9 lines · Tao Liu

The total memory size we get in kernel is usually slightly less than 2G with a 2G memory module machine. The main reason is bios/firmware reserve some area it will not export all memory as usable to Linux.

2G memory X86 kvm guest test result of the total_mem value:
UEFI boot with ovmf: 0x7ef10000
Legacy boot kvm guest: 0x7ff7cc00
This is also a problem on arm64 UEFI booted system according to my test.

Quoted 4 lines

Thus for example crashkernel=1G-2G:128M, if we have a 1G memory machine, we get total size 1023M from firmware then it will not fall into 1G-2G thus no memory reserved. User will never know that, it is hard to let user to know the exact total value we get in kernel

The code change looks good to me, while the patch log need be improved. I rewrite it at below. However, here, the crashkernel=1G-2G:128M exmaple, above it there has been a 2G memory kvm guest example, then we get here to give an crashkernel=1G-2G:128M case. The logic looks not so smooth.

Could you rethink about this, e.g using the crashkernel=2G-3G:192M, or trying on kvm guest with 1G meory and getting its total_mem value? I mean unifying the examples based on your testing.

And also see inline comment about the code comment part.

......

Rewritten log:
===
The total memory size we get in kernel is usually slightly less than the actual memory size because BIOS/firmware will reserve some meory region. So it won't export all memory as usable.

E.g, on my kvm guest with 2G meory, the total_mem value shows:
UEFI boot with ovmf: 0x7ef10000
Legacy boot kvm guest: 0x7ff7cc00

When specifying crashkernel=1G-2G:128M, if we have a 1G memory machine, we get total size 1023M from firmware. Then it will not fall into 1G-2G, thus no memory reserved. User will never know this, it is hard to let user know the exact total value in kernel

One way is to use dmi/smbios to get physical memory size, but it's not reliable as well. According to Prarit hardware vendors sometimes screw this up. Thus round up total size to 128M to work around this problem.

This patch is a resend of [1] and rebased onto v5.19-rc2, and the original credit goes to Dave Young <[email protected]>.
===

Quoted 36 lines

[1]: http://lists.infradead.org/pipermail/kexec/2018-April/020568.html

---
 kernel/crash_core.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
kernel/crash_core.c +0 -1
index 71122e01623c..f6c1ffce9d5a 100644
--- a/kernel/crash_core.c

[1]: http://lists.infradead.org/pipermail/kexec/2018-April/020568.html

---
 kernel/crash_core.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
kernel/crash_core.c +1 -0
index 71122e01623c..f6c1ffce9d5a 100644
@@ -9,6 +9,7 @@
 #include <linux/init.h>
 #include <linux/utsname.h>
 #include <linux/vmalloc.h>
+#include <linux/sizes.h>
 
 #include <asm/page.h>
 #include <asm/sections.h>

kernel/crash_core.c static int __init parse_crashkernel_mem(char *cmdline, · line 50

Quoted 7 lines
kernel/crash_core.c +4 -0
@@ -43,6 +44,15 @@ static int __init parse_crashkernel_mem(char *cmdline,
 					unsigned long long *crash_base)
 {
 	char *cur = cmdline, *tmp;
+	unsigned long long total_mem = system_ram;
+
+	/*
+	 * Firmware sometimes reserves some memory regions for it's own use.
                                                               ~~~ its, typo

kernel/crash_core.c static int __init parse_crashkernel_mem(char *cmdline, · line 51

Quoted 1 line
kernel/crash_core.c +1 -0
+	 * so we get less than actual system memory size.

so the system memory size is less than the actual physical memory size.

kernel/crash_core.c static int __init parse_crashkernel_mem(char *cmdline, · line 52

Quoted 1 line
kernel/crash_core.c +1 -0
+	 * Workaround this by round up the total size to 128M which is

s/Work around/Workaround/, workaround is an noun. s/round up/rounding up/

Quoted 25 lines
kernel/crash_core.c +5 -2
+	 * enough for most test cases.
+	 */
+	total_mem = roundup(total_mem, SZ_128M);
 
 	/* for each entry of the comma-separated list */
 	do {
@@ -87,13 +97,13 @@ static int __init parse_crashkernel_mem(char *cmdline,
 			return -EINVAL;
 		}
 		cur = tmp;
-		if (size >= system_ram) {
+		if (size >= total_mem) {
 			pr_warn("crashkernel: invalid size\n");
 			return -EINVAL;
 		}
 
 		/* match ? */
-		if (system_ram >= start && system_ram < end) {
+		if (total_mem >= start && total_mem < end) {
 			*crash_size = size;
 			break;
 		}
Signature · 1 line
2.33.1

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec