Skip to contentSkip to conversation

kdump x86: fix total mem size calculation for reservation

PATCH Superseded Dave Young 3 participants 6 messages Mar 9, 2012 – Mar 10, 2012 x86

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Dave Young

author
#0 lore raw

PATCH 1/1 kdump x86: fix total mem size calculation for reservation

crashkernel reservation need know the total memory size. Current get_total_mem simply use max_pfn - min_low_pfn. It is wrong because it will including memory holes in the middle.

Especially for kvm guest with memory > 0xe0000000, there's below in qemu code:
qemu split memory as below:

    if (ram_size >= 0xe0000000 ) {
        above_4g_mem_size = ram_size - 0xe0000000;
        below_4g_mem_size = 0xe0000000;
    } else {
        below_4g_mem_size = ram_size;
    }

So for 4G mem guest, seabios will insert a 512M usable region beyond of 4G. Thus in above case max_pfn - min_low_pfn will be more than original memsize.

Fixing this issue by using memblock_phys_mem_size() to get the total memsize.

---
[Ther's similar code in arm, I'm not sure whether the memblock_phys_mem_size works with arm or not. If it works I can also update that part of code.]

 arch/x86/kernel/setup.c |   12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)
arch/x86/kernel/setup.c +1 -11
@@ -509,16 +509,6 @@ static void __init memblock_x86_reserve_
 
 #ifdef CONFIG_KEXEC
 
-static inline unsigned long long get_total_mem(void)
-{
-	unsigned long long total;
-
-	total = max_pfn - min_low_pfn;
-	printk("hidave: memsize=%llu\n", memblock_phys_mem_size());
-
-	return total << PAGE_SHIFT;
-}
-
 /*
  * Keep the crash kernel below this limit.  On 32 bits earlier kernels
  * would limit the kernel to the low 512 MiB due to mapping restrictions.
@@ -537,7 +527,7 @@ static void __init reserve_crashkernel(v
 	unsigned long long crash_size, crash_base;
 	int ret;
 
-	total_mem = get_total_mem();
+	total_mem = memblock_phys_mem_size();
 
 	ret = parse_crashkernel(boot_command_line, total_mem,
 			&crash_size, &crash_base);
#1 lore raw
Quoted 12 lines · Dave Young

crashkernel reservation need know the total memory size. Current get_total_mem simply use max_pfn - min_low_pfn. It is wrong because it will including memory holes in the middle.

Especially for kvm guest with memory> 0xe0000000, there's below in qemu code:
qemu split memory as below:

     if (ram_size>= 0xe0000000 ) {
         above_4g_mem_size = ram_size - 0xe0000000;
         below_4g_mem_size = 0xe0000000;
     } else {
         below_4g_mem_size = ram_size;
     }
Quoted 5 lines

So for 4G mem guest, seabios will insert a 512M usable region beyond of 4G. Thus in above case max_pfn - min_low_pfn will be more than original memsize.

Fixing this issue by using memblock_phys_mem_size() to get the total memsize.

Makes sense for me!

arch/x86/kernel/setup.c static void __init memblock_x86_reserve_ · line 517

Quoted 6 lines
arch/x86/kernel/setup.c +0 -6
-static inline unsigned long long get_total_mem(void)
-{
-	unsigned long long total;
-
-	total = max_pfn - min_low_pfn;
-	printk("hidave: memsize=%llu\n", memblock_phys_mem_size());

This debugging line does not exist... so this patch can't be applied.

author
#2 lore raw
Quoted 26 lines · Cong Wang
Quoted 14 lines · Dave Young

crashkernel reservation need know the total memory size. Current get_total_mem
simply use max_pfn - min_low_pfn. It is wrong because it will including memory holes in the middle.

Especially for kvm guest with memory> 0xe0000000, there's below in qemu code:
qemu split memory as below:

     if (ram_size>= 0xe0000000 ) {
         above_4g_mem_size = ram_size - 0xe0000000;
         below_4g_mem_size = 0xe0000000;
     } else {
         below_4g_mem_size = ram_size;
     }
Quoted 8 lines

So for 4G mem guest, seabios will insert a 512M usable region beyond of 4G.
Thus in above case max_pfn - min_low_pfn will be more than original memsize.

Fixing this issue by using memblock_phys_mem_size() to get the total memsize.

Makes sense for me!

Quoted 8 lines

arch/x86/kernel/setup.c static void __init memblock_x86_reserve_ · line 517

Quoted 6 lines
arch/x86/kernel/setup.c +0 -6
-static inline unsigned long long get_total_mem(void)
-{
-    unsigned long long total;
-
-    total = max_pfn - min_low_pfn;
-    printk("hidave: memsize=%llu\n", memblock_phys_mem_size());

This debugging line does not exist... so this patch can't be applied.

Yes, good catch, will remove the line and resend.

Signature · 2 lines
Thanks
Dave
author
#3 lore raw

PATCH v2 1/1 kdump x86: fix total mem size calculation for reservation

In reply to Cong Wang

crashkernel reservation need know the total memory size. Current get_total_mem simply use max_pfn - min_low_pfn. It is wrong because it will including memory holes in the middle.

Especially for kvm guest with memory > 0xe0000000, there's below in qemu code:
qemu split memory as below:

    if (ram_size >= 0xe0000000 ) {
        above_4g_mem_size = ram_size - 0xe0000000;
        below_4g_mem_size = 0xe0000000;
    } else {
        below_4g_mem_size = ram_size;
    }

So for 4G mem guest, seabios will insert a 512M usable region beyond of 4G. Thus in above case max_pfn - min_low_pfn will be more than original memsize.

Fixing this issue by using memblock_phys_mem_size() to get the total memsize.

[v1 -> v2]: refresh the patch based on latest linus tree

---
[Ther's similar code in arm, I'm not sure whether the memblock_phys_mem_size works with arm or not. If it works I can also update that part of code.]

 arch/x86/kernel/setup.c |   11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)
arch/x86/kernel/setup.c +1 -10
@@ -509,15 +509,6 @@ static void __init memblock_x86_reserve_
 
 #ifdef CONFIG_KEXEC
 
-static inline unsigned long long get_total_mem(void)
-{
-	unsigned long long total;
-
-	total = max_pfn - min_low_pfn;
-
-	return total << PAGE_SHIFT;
-}
-
 /*
  * Keep the crash kernel below this limit.  On 32 bits earlier kernels
  * would limit the kernel to the low 512 MiB due to mapping restrictions.
@@ -536,7 +527,7 @@ static void __init reserve_crashkernel(v
 	unsigned long long crash_size, crash_base;
 	int ret;
 
-	total_mem = get_total_mem();
+	total_mem = memblock_phys_mem_size();
 
 	ret = parse_crashkernel(boot_command_line, total_mem,
 			&crash_size, &crash_base);
Reviewed-by on v2 1/1
#4 lore raw
Quoted 12 lines · Dave Young

crashkernel reservation need know the total memory size. Current get_total_mem simply use max_pfn - min_low_pfn. It is wrong because it will including memory holes in the middle.

Especially for kvm guest with memory> 0xe0000000, there's below in qemu code:
qemu split memory as below:

     if (ram_size>= 0xe0000000 ) {
         above_4g_mem_size = ram_size - 0xe0000000;
         below_4g_mem_size = 0xe0000000;
     } else {
         below_4g_mem_size = ram_size;
     }
Quoted 7 lines

So for 4G mem guest, seabios will insert a 512M usable region beyond of 4G. Thus in above case max_pfn - min_low_pfn will be more than original memsize.

Fixing this issue by using memblock_phys_mem_size() to get the total memsize.

[v1 -> v2]: refresh the patch based on latest linus tree

Looks good to my eyes,

Can you post the result of crashkernel after this patch to convince people?

Thanks.

#5 lore raw
Quoted 24 lines · Cong Wang
Quoted 23 lines · Dave Young

crashkernel reservation need know the total memory size. Current get_total_mem
simply use max_pfn - min_low_pfn. It is wrong because it will including memory holes in the middle.

Especially for kvm guest with memory>  0xe0000000, there's below in qemu code:
qemu split memory as below:
    if (ram_size>= 0xe0000000 ) {
        above_4g_mem_size = ram_size - 0xe0000000; below_4g_mem_size = 0xe0000000;
    } else {
        below_4g_mem_size = ram_size;
    }
So for 4G mem guest, seabios will insert a 512M usable region beyond of 4G.
Thus in above case max_pfn - min_low_pfn will be more than original memsize.

Fixing this issue by using memblock_phys_mem_size() to get the total memsize.

Quoted 8 lines
Quoted 2 lines

[v1 ->  v2]: refresh the patch based on latest linus tree

Looks good to my eyes,

Can you post the result of crashkernel after this patch to convince people?

Sure, for the qemu 4G vm results below:
-[ 0.000000] Reserving 128MB of memory at 768MB for crashkernel
(System RAM: 4608MB)
+[ 0.000000] Reserving 128MB of memory at 768MB for crashkernel
(System RAM: 4095MB)

Quoted 8 lines

Thanks.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Signature · 2 lines
Regards
Dave