All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 3/3] kdump: round up the total memory size to 128M for crashkernel reservation
@ 2017-10-24  5:31 ` dyoung
  0 siblings, 0 replies; 10+ messages in thread
From: dyoung @ 2017-10-24  5:31 UTC (permalink / raw)
  To: kexec, linux-kernel; +Cc: akpm, bhe, vgoyal, yinghai, corbet, dyoung

[-- Attachment #1: kdump-crashkernel-roundup-total-mem.patch --]
[-- Type: text/plain, Size: 2197 bytes --]

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

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 we choose to round up total size to 128M to workaround this problem.
This is a best effort workaround, will improve it when we have better way
in the future. 

Signed-off-by: Dave Young <dyoung@redhat.com>
---
 kernel/crash_core.c |   17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

--- linux.orig/kernel/crash_core.c
+++ linux/kernel/crash_core.c
@@ -42,6 +42,15 @@ static int __init parse_crashkernel_mem(
 {
 	char *cur = cmdline, *tmp;
 	bool infinite_end = false;
+	unsigned long long total_mem = system_ram;
+
+	/*
+	 * Firmware usually reserves some memory regions for it's own use.
+	 * so we get less than actual system memory size.
+	 * We workaround this by round up the total size to 128M which is
+	 * enough for most test cases.
+	 */
+	total_mem = roundup(total_mem, 0x8000000);
 
 	/* for each entry of the comma-separated list */
 	do {
@@ -86,13 +95,13 @@ static int __init parse_crashkernel_mem(
 			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;
 			if (end == ULLONG_MAX)
 				infinite_end = true;
@@ -126,9 +135,9 @@ static int __init parse_crashkernel_mem(
 				pr_warn("Memory reservation scale order expected after '^'\n");
 				return -EINVAL;
 			}
-			size = (system_ram - *crash_size) >> shift;
+			size = (total_mem - *crash_size) >> shift;
 			size = *crash_size + roundup(size, 1ULL << 20);
-			if (size < system_ram)
+			if (size < total_mem)
 				*crash_size = size;
 			cur = tmp;
 		} else

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 3/3] kdump: round up the total memory size to 128M for crashkernel reservation
@ 2017-10-24  5:31 ` dyoung
  0 siblings, 0 replies; 10+ messages in thread
From: dyoung @ 2017-10-24  5:31 UTC (permalink / raw)
  To: kexec, linux-kernel; +Cc: bhe, corbet, yinghai, akpm, dyoung, vgoyal

[-- Attachment #1: kdump-crashkernel-roundup-total-mem.patch --]
[-- Type: text/plain, Size: 2343 bytes --]

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

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 we choose to round up total size to 128M to workaround this problem.
This is a best effort workaround, will improve it when we have better way
in the future. 

Signed-off-by: Dave Young <dyoung@redhat.com>
---
 kernel/crash_core.c |   17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

--- linux.orig/kernel/crash_core.c
+++ linux/kernel/crash_core.c
@@ -42,6 +42,15 @@ static int __init parse_crashkernel_mem(
 {
 	char *cur = cmdline, *tmp;
 	bool infinite_end = false;
+	unsigned long long total_mem = system_ram;
+
+	/*
+	 * Firmware usually reserves some memory regions for it's own use.
+	 * so we get less than actual system memory size.
+	 * We workaround this by round up the total size to 128M which is
+	 * enough for most test cases.
+	 */
+	total_mem = roundup(total_mem, 0x8000000);
 
 	/* for each entry of the comma-separated list */
 	do {
@@ -86,13 +95,13 @@ static int __init parse_crashkernel_mem(
 			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;
 			if (end == ULLONG_MAX)
 				infinite_end = true;
@@ -126,9 +135,9 @@ static int __init parse_crashkernel_mem(
 				pr_warn("Memory reservation scale order expected after '^'\n");
 				return -EINVAL;
 			}
-			size = (system_ram - *crash_size) >> shift;
+			size = (total_mem - *crash_size) >> shift;
 			size = *crash_size + roundup(size, 1ULL << 20);
-			if (size < system_ram)
+			if (size < total_mem)
 				*crash_size = size;
 			cur = tmp;
 		} else



_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 3/3] kdump: round up the total memory size to 128M for crashkernel reservation
  2017-10-24  5:31 ` dyoung
@ 2017-10-24  5:57   ` Baoquan He
  -1 siblings, 0 replies; 10+ messages in thread
From: Baoquan He @ 2017-10-24  5:57 UTC (permalink / raw)
  To: dyoung; +Cc: kexec, linux-kernel, akpm, vgoyal, yinghai, corbet

Hi Dave,

On 10/24/17 at 01:31pm, Dave Young wrote:
> 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
> 
> 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 we choose to round up total size to 128M to workaround this problem.
> This is a best effort workaround, will improve it when we have better way
> in the future. 

Thanks for this posting. While I don't get the point of this patch. So
firmware take piece of memory, then why we need to count it into the
total memory which we want to calculate a crashkernel memory based on.

Not counting that, is there anyting incorrect?

Thanks
Baoquan

> 
> Signed-off-by: Dave Young <dyoung@redhat.com>
> ---
>  kernel/crash_core.c |   17 +++++++++++++----
>  1 file changed, 13 insertions(+), 4 deletions(-)
> 
> --- linux.orig/kernel/crash_core.c
> +++ linux/kernel/crash_core.c
> @@ -42,6 +42,15 @@ static int __init parse_crashkernel_mem(
>  {
>  	char *cur = cmdline, *tmp;
>  	bool infinite_end = false;
> +	unsigned long long total_mem = system_ram;
> +
> +	/*
> +	 * Firmware usually reserves some memory regions for it's own use.
> +	 * so we get less than actual system memory size.
> +	 * We workaround this by round up the total size to 128M which is
> +	 * enough for most test cases.
> +	 */
> +	total_mem = roundup(total_mem, 0x8000000);
>  
>  	/* for each entry of the comma-separated list */
>  	do {
> @@ -86,13 +95,13 @@ static int __init parse_crashkernel_mem(
>  			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;
>  			if (end == ULLONG_MAX)
>  				infinite_end = true;
> @@ -126,9 +135,9 @@ static int __init parse_crashkernel_mem(
>  				pr_warn("Memory reservation scale order expected after '^'\n");
>  				return -EINVAL;
>  			}
> -			size = (system_ram - *crash_size) >> shift;
> +			size = (total_mem - *crash_size) >> shift;
>  			size = *crash_size + roundup(size, 1ULL << 20);
> -			if (size < system_ram)
> +			if (size < total_mem)
>  				*crash_size = size;
>  			cur = tmp;
>  		} else
> 
> 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 3/3] kdump: round up the total memory size to 128M for crashkernel reservation
@ 2017-10-24  5:57   ` Baoquan He
  0 siblings, 0 replies; 10+ messages in thread
From: Baoquan He @ 2017-10-24  5:57 UTC (permalink / raw)
  To: dyoung; +Cc: corbet, kexec, linux-kernel, akpm, yinghai, vgoyal

Hi Dave,

On 10/24/17 at 01:31pm, Dave Young wrote:
> 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
> 
> 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 we choose to round up total size to 128M to workaround this problem.
> This is a best effort workaround, will improve it when we have better way
> in the future. 

Thanks for this posting. While I don't get the point of this patch. So
firmware take piece of memory, then why we need to count it into the
total memory which we want to calculate a crashkernel memory based on.

Not counting that, is there anyting incorrect?

Thanks
Baoquan

> 
> Signed-off-by: Dave Young <dyoung@redhat.com>
> ---
>  kernel/crash_core.c |   17 +++++++++++++----
>  1 file changed, 13 insertions(+), 4 deletions(-)
> 
> --- linux.orig/kernel/crash_core.c
> +++ linux/kernel/crash_core.c
> @@ -42,6 +42,15 @@ static int __init parse_crashkernel_mem(
>  {
>  	char *cur = cmdline, *tmp;
>  	bool infinite_end = false;
> +	unsigned long long total_mem = system_ram;
> +
> +	/*
> +	 * Firmware usually reserves some memory regions for it's own use.
> +	 * so we get less than actual system memory size.
> +	 * We workaround this by round up the total size to 128M which is
> +	 * enough for most test cases.
> +	 */
> +	total_mem = roundup(total_mem, 0x8000000);
>  
>  	/* for each entry of the comma-separated list */
>  	do {
> @@ -86,13 +95,13 @@ static int __init parse_crashkernel_mem(
>  			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;
>  			if (end == ULLONG_MAX)
>  				infinite_end = true;
> @@ -126,9 +135,9 @@ static int __init parse_crashkernel_mem(
>  				pr_warn("Memory reservation scale order expected after '^'\n");
>  				return -EINVAL;
>  			}
> -			size = (system_ram - *crash_size) >> shift;
> +			size = (total_mem - *crash_size) >> shift;
>  			size = *crash_size + roundup(size, 1ULL << 20);
> -			if (size < system_ram)
> +			if (size < total_mem)
>  				*crash_size = size;
>  			cur = tmp;
>  		} else
> 
> 

_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 3/3] kdump: round up the total memory size to 128M for crashkernel reservation
  2017-10-24  5:57   ` Baoquan He
@ 2017-10-24  6:09     ` Dave Young
  -1 siblings, 0 replies; 10+ messages in thread
From: Dave Young @ 2017-10-24  6:09 UTC (permalink / raw)
  To: Baoquan He; +Cc: kexec, linux-kernel, akpm, vgoyal, yinghai, corbet

Hi Baoquan,

On 10/24/17 at 01:57pm, Baoquan He wrote:
> Hi Dave,
> 
> On 10/24/17 at 01:31pm, Dave Young wrote:
> > 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
> > 
> > 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 we choose to round up total size to 128M to workaround this problem.
> > This is a best effort workaround, will improve it when we have better way
> > in the future. 
> 
> Thanks for this posting. While I don't get the point of this patch. So
> firmware take piece of memory, then why we need to count it into the
> total memory which we want to calculate a crashkernel memory based on.
> 
> Not counting that, is there anyting incorrect?

Yes, considering 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..

> 
> Thanks
> Baoquan
> 
> > 
> > Signed-off-by: Dave Young <dyoung@redhat.com>
> > ---
> >  kernel/crash_core.c |   17 +++++++++++++----
> >  1 file changed, 13 insertions(+), 4 deletions(-)
> > 
> > --- linux.orig/kernel/crash_core.c
> > +++ linux/kernel/crash_core.c
> > @@ -42,6 +42,15 @@ static int __init parse_crashkernel_mem(
> >  {
> >  	char *cur = cmdline, *tmp;
> >  	bool infinite_end = false;
> > +	unsigned long long total_mem = system_ram;
> > +
> > +	/*
> > +	 * Firmware usually reserves some memory regions for it's own use.
> > +	 * so we get less than actual system memory size.
> > +	 * We workaround this by round up the total size to 128M which is
> > +	 * enough for most test cases.
> > +	 */
> > +	total_mem = roundup(total_mem, 0x8000000);
> >  
> >  	/* for each entry of the comma-separated list */
> >  	do {
> > @@ -86,13 +95,13 @@ static int __init parse_crashkernel_mem(
> >  			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;
> >  			if (end == ULLONG_MAX)
> >  				infinite_end = true;
> > @@ -126,9 +135,9 @@ static int __init parse_crashkernel_mem(
> >  				pr_warn("Memory reservation scale order expected after '^'\n");
> >  				return -EINVAL;
> >  			}
> > -			size = (system_ram - *crash_size) >> shift;
> > +			size = (total_mem - *crash_size) >> shift;
> >  			size = *crash_size + roundup(size, 1ULL << 20);
> > -			if (size < system_ram)
> > +			if (size < total_mem)
> >  				*crash_size = size;
> >  			cur = tmp;
> >  		} else
> > 
> > 

Thanks
Dave

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 3/3] kdump: round up the total memory size to 128M for crashkernel reservation
@ 2017-10-24  6:09     ` Dave Young
  0 siblings, 0 replies; 10+ messages in thread
From: Dave Young @ 2017-10-24  6:09 UTC (permalink / raw)
  To: Baoquan He; +Cc: corbet, kexec, linux-kernel, akpm, yinghai, vgoyal

Hi Baoquan,

On 10/24/17 at 01:57pm, Baoquan He wrote:
> Hi Dave,
> 
> On 10/24/17 at 01:31pm, Dave Young wrote:
> > 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
> > 
> > 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 we choose to round up total size to 128M to workaround this problem.
> > This is a best effort workaround, will improve it when we have better way
> > in the future. 
> 
> Thanks for this posting. While I don't get the point of this patch. So
> firmware take piece of memory, then why we need to count it into the
> total memory which we want to calculate a crashkernel memory based on.
> 
> Not counting that, is there anyting incorrect?

Yes, considering 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..

> 
> Thanks
> Baoquan
> 
> > 
> > Signed-off-by: Dave Young <dyoung@redhat.com>
> > ---
> >  kernel/crash_core.c |   17 +++++++++++++----
> >  1 file changed, 13 insertions(+), 4 deletions(-)
> > 
> > --- linux.orig/kernel/crash_core.c
> > +++ linux/kernel/crash_core.c
> > @@ -42,6 +42,15 @@ static int __init parse_crashkernel_mem(
> >  {
> >  	char *cur = cmdline, *tmp;
> >  	bool infinite_end = false;
> > +	unsigned long long total_mem = system_ram;
> > +
> > +	/*
> > +	 * Firmware usually reserves some memory regions for it's own use.
> > +	 * so we get less than actual system memory size.
> > +	 * We workaround this by round up the total size to 128M which is
> > +	 * enough for most test cases.
> > +	 */
> > +	total_mem = roundup(total_mem, 0x8000000);
> >  
> >  	/* for each entry of the comma-separated list */
> >  	do {
> > @@ -86,13 +95,13 @@ static int __init parse_crashkernel_mem(
> >  			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;
> >  			if (end == ULLONG_MAX)
> >  				infinite_end = true;
> > @@ -126,9 +135,9 @@ static int __init parse_crashkernel_mem(
> >  				pr_warn("Memory reservation scale order expected after '^'\n");
> >  				return -EINVAL;
> >  			}
> > -			size = (system_ram - *crash_size) >> shift;
> > +			size = (total_mem - *crash_size) >> shift;
> >  			size = *crash_size + roundup(size, 1ULL << 20);
> > -			if (size < system_ram)
> > +			if (size < total_mem)
> >  				*crash_size = size;
> >  			cur = tmp;
> >  		} else
> > 
> > 

Thanks
Dave

_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 3/3] kdump: round up the total memory size to 128M for crashkernel reservation
  2017-10-24  6:09     ` Dave Young
@ 2017-11-01  7:21       ` Baoquan He
  -1 siblings, 0 replies; 10+ messages in thread
From: Baoquan He @ 2017-11-01  7:21 UTC (permalink / raw)
  To: Dave Young; +Cc: kexec, linux-kernel, akpm, vgoyal, yinghai, corbet

On 10/24/17 at 02:09pm, Dave Young wrote:
> Hi Baoquan,
> 
> On 10/24/17 at 01:57pm, Baoquan He wrote:
> > Hi Dave,
> > 
> > On 10/24/17 at 01:31pm, Dave Young wrote:
> > > 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
> > > 
> > > 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 we choose to round up total size to 128M to workaround this problem.
> > > This is a best effort workaround, will improve it when we have better way
> > > in the future. 
> > 
> > Thanks for this posting. While I don't get the point of this patch. So
> > firmware take piece of memory, then why we need to count it into the
> > total memory which we want to calculate a crashkernel memory based on.
> > 
> > Not counting that, is there anyting incorrect?
> 
> Yes, considering 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..

OK, got it. Thanks.

Then I have no objection to this. See what other reviewers will say.

Thanks
Baoquan


> > 
> > > 
> > > Signed-off-by: Dave Young <dyoung@redhat.com>
> > > ---
> > >  kernel/crash_core.c |   17 +++++++++++++----
> > >  1 file changed, 13 insertions(+), 4 deletions(-)
> > > 
> > > --- linux.orig/kernel/crash_core.c
> > > +++ linux/kernel/crash_core.c
> > > @@ -42,6 +42,15 @@ static int __init parse_crashkernel_mem(
> > >  {
> > >  	char *cur = cmdline, *tmp;
> > >  	bool infinite_end = false;
> > > +	unsigned long long total_mem = system_ram;
> > > +
> > > +	/*
> > > +	 * Firmware usually reserves some memory regions for it's own use.
> > > +	 * so we get less than actual system memory size.
> > > +	 * We workaround this by round up the total size to 128M which is
> > > +	 * enough for most test cases.
> > > +	 */
> > > +	total_mem = roundup(total_mem, 0x8000000);
> > >  
> > >  	/* for each entry of the comma-separated list */
> > >  	do {
> > > @@ -86,13 +95,13 @@ static int __init parse_crashkernel_mem(
> > >  			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;
> > >  			if (end == ULLONG_MAX)
> > >  				infinite_end = true;
> > > @@ -126,9 +135,9 @@ static int __init parse_crashkernel_mem(
> > >  				pr_warn("Memory reservation scale order expected after '^'\n");
> > >  				return -EINVAL;
> > >  			}
> > > -			size = (system_ram - *crash_size) >> shift;
> > > +			size = (total_mem - *crash_size) >> shift;
> > >  			size = *crash_size + roundup(size, 1ULL << 20);
> > > -			if (size < system_ram)
> > > +			if (size < total_mem)
> > >  				*crash_size = size;
> > >  			cur = tmp;
> > >  		} else
> > > 
> > > 
> 
> Thanks
> Dave

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 3/3] kdump: round up the total memory size to 128M for crashkernel reservation
@ 2017-11-01  7:21       ` Baoquan He
  0 siblings, 0 replies; 10+ messages in thread
From: Baoquan He @ 2017-11-01  7:21 UTC (permalink / raw)
  To: Dave Young; +Cc: corbet, kexec, linux-kernel, akpm, yinghai, vgoyal

On 10/24/17 at 02:09pm, Dave Young wrote:
> Hi Baoquan,
> 
> On 10/24/17 at 01:57pm, Baoquan He wrote:
> > Hi Dave,
> > 
> > On 10/24/17 at 01:31pm, Dave Young wrote:
> > > 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
> > > 
> > > 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 we choose to round up total size to 128M to workaround this problem.
> > > This is a best effort workaround, will improve it when we have better way
> > > in the future. 
> > 
> > Thanks for this posting. While I don't get the point of this patch. So
> > firmware take piece of memory, then why we need to count it into the
> > total memory which we want to calculate a crashkernel memory based on.
> > 
> > Not counting that, is there anyting incorrect?
> 
> Yes, considering 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..

OK, got it. Thanks.

Then I have no objection to this. See what other reviewers will say.

Thanks
Baoquan


> > 
> > > 
> > > Signed-off-by: Dave Young <dyoung@redhat.com>
> > > ---
> > >  kernel/crash_core.c |   17 +++++++++++++----
> > >  1 file changed, 13 insertions(+), 4 deletions(-)
> > > 
> > > --- linux.orig/kernel/crash_core.c
> > > +++ linux/kernel/crash_core.c
> > > @@ -42,6 +42,15 @@ static int __init parse_crashkernel_mem(
> > >  {
> > >  	char *cur = cmdline, *tmp;
> > >  	bool infinite_end = false;
> > > +	unsigned long long total_mem = system_ram;
> > > +
> > > +	/*
> > > +	 * Firmware usually reserves some memory regions for it's own use.
> > > +	 * so we get less than actual system memory size.
> > > +	 * We workaround this by round up the total size to 128M which is
> > > +	 * enough for most test cases.
> > > +	 */
> > > +	total_mem = roundup(total_mem, 0x8000000);
> > >  
> > >  	/* for each entry of the comma-separated list */
> > >  	do {
> > > @@ -86,13 +95,13 @@ static int __init parse_crashkernel_mem(
> > >  			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;
> > >  			if (end == ULLONG_MAX)
> > >  				infinite_end = true;
> > > @@ -126,9 +135,9 @@ static int __init parse_crashkernel_mem(
> > >  				pr_warn("Memory reservation scale order expected after '^'\n");
> > >  				return -EINVAL;
> > >  			}
> > > -			size = (system_ram - *crash_size) >> shift;
> > > +			size = (total_mem - *crash_size) >> shift;
> > >  			size = *crash_size + roundup(size, 1ULL << 20);
> > > -			if (size < system_ram)
> > > +			if (size < total_mem)
> > >  				*crash_size = size;
> > >  			cur = tmp;
> > >  		} else
> > > 
> > > 
> 
> Thanks
> Dave

_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 3/3 update] kdump: round up the total memory size to 128M for crashkernel reservation
  2017-10-24  5:31 ` dyoung
@ 2017-11-03  2:46   ` Dave Young
  -1 siblings, 0 replies; 10+ messages in thread
From: Dave Young @ 2017-11-03  2:46 UTC (permalink / raw)
  To: kexec, linux-kernel; +Cc: bhe, corbet, yinghai, akpm, vgoyal, bhsharma

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.

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.

Signed-off-by: Dave Young <dyoung@redhat.com>
---
Changes from previous version of 3/3:
1. improve changelog: add examples why this is a problem (comment from
   Baoquan He)
2. change to use SZ_128M (comment from Bhupesh Sharma)

 kernel/crash_core.c |   18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

--- linux-x86.orig/kernel/crash_core.c
+++ linux-x86/kernel/crash_core.c
@@ -9,6 +9,7 @@
 #include <linux/crash_core.h>
 #include <linux/utsname.h>
 #include <linux/vmalloc.h>
+#include <linux/sizes.h>
 
 #include <asm/page.h>
 #include <asm/sections.h>
@@ -42,6 +43,15 @@ static int __init parse_crashkernel_mem(
 {
 	char *cur = cmdline, *tmp;
 	bool infinite_end = false;
+	unsigned long long total_mem = system_ram;
+
+	/*
+	 * Firmware usually reserves some memory regions for it's own use.
+	 * so we get less than actual system memory size.
+	 * We 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 {
@@ -86,13 +96,13 @@ static int __init parse_crashkernel_mem(
 			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;
 			if (end == ULLONG_MAX)
 				infinite_end = true;
@@ -126,9 +136,9 @@ static int __init parse_crashkernel_mem(
 				pr_warn("Memory reservation scale order expected after '^'\n");
 				return -EINVAL;
 			}
-			size = (system_ram - *crash_size) >> shift;
+			size = (total_mem - *crash_size) >> shift;
 			size = *crash_size + roundup(size, 1ULL << 20);
-			if (size < system_ram)
+			if (size < total_mem)
 				*crash_size = size;
 			cur = tmp;
 		} else

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 3/3 update] kdump: round up the total memory size to 128M for crashkernel reservation
@ 2017-11-03  2:46   ` Dave Young
  0 siblings, 0 replies; 10+ messages in thread
From: Dave Young @ 2017-11-03  2:46 UTC (permalink / raw)
  To: kexec, linux-kernel; +Cc: bhe, corbet, bhsharma, akpm, yinghai, vgoyal

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.

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.

Signed-off-by: Dave Young <dyoung@redhat.com>
---
Changes from previous version of 3/3:
1. improve changelog: add examples why this is a problem (comment from
   Baoquan He)
2. change to use SZ_128M (comment from Bhupesh Sharma)

 kernel/crash_core.c |   18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

--- linux-x86.orig/kernel/crash_core.c
+++ linux-x86/kernel/crash_core.c
@@ -9,6 +9,7 @@
 #include <linux/crash_core.h>
 #include <linux/utsname.h>
 #include <linux/vmalloc.h>
+#include <linux/sizes.h>
 
 #include <asm/page.h>
 #include <asm/sections.h>
@@ -42,6 +43,15 @@ static int __init parse_crashkernel_mem(
 {
 	char *cur = cmdline, *tmp;
 	bool infinite_end = false;
+	unsigned long long total_mem = system_ram;
+
+	/*
+	 * Firmware usually reserves some memory regions for it's own use.
+	 * so we get less than actual system memory size.
+	 * We 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 {
@@ -86,13 +96,13 @@ static int __init parse_crashkernel_mem(
 			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;
 			if (end == ULLONG_MAX)
 				infinite_end = true;
@@ -126,9 +136,9 @@ static int __init parse_crashkernel_mem(
 				pr_warn("Memory reservation scale order expected after '^'\n");
 				return -EINVAL;
 			}
-			size = (system_ram - *crash_size) >> shift;
+			size = (total_mem - *crash_size) >> shift;
 			size = *crash_size + roundup(size, 1ULL << 20);
-			if (size < system_ram)
+			if (size < total_mem)
 				*crash_size = size;
 			cur = tmp;
 		} else

_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2017-11-03  2:46 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-24  5:31 [PATCH 3/3] kdump: round up the total memory size to 128M for crashkernel reservation dyoung
2017-10-24  5:31 ` dyoung
2017-10-24  5:57 ` Baoquan He
2017-10-24  5:57   ` Baoquan He
2017-10-24  6:09   ` Dave Young
2017-10-24  6:09     ` Dave Young
2017-11-01  7:21     ` Baoquan He
2017-11-01  7:21       ` Baoquan He
2017-11-03  2:46 ` [PATCH 3/3 update] " Dave Young
2017-11-03  2:46   ` Dave Young

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.