public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86: crash kernel reserve with reserve_early -v2
@ 2009-11-23  1:18 Yinghai Lu
  2009-11-23  2:34 ` Eric W. Biederman
  2009-11-23  8:42 ` [tip:x86/mm] x86: Change crash kernel to reserve via reserve_early() tip-bot for Yinghai Lu
  0 siblings, 2 replies; 5+ messages in thread
From: Yinghai Lu @ 2009-11-23  1:18 UTC (permalink / raw)
  To: Ingo Molnar, Thomas Gleixner, H. Peter Anvin, Eric W. Biederman
  Cc: linux-kernel@vger.kernel.org


use find_e820_area/reserve_early instead.

-v2: address Eric's request, to restore original semantics.
     will fail, if the provided address can not be used.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 arch/x86/kernel/setup.c |   57 ++++++++++++------------------------------------
 1 file changed, 15 insertions(+), 42 deletions(-)

Index: linux-2.6/arch/x86/kernel/setup.c
===================================================================
--- linux-2.6.orig/arch/x86/kernel/setup.c
+++ linux-2.6/arch/x86/kernel/setup.c
@@ -488,42 +488,11 @@ static void __init reserve_early_setup_d
 
 #ifdef CONFIG_KEXEC
 
-/**
- * Reserve @size bytes of crashkernel memory at any suitable offset.
- *
- * @size: Size of the crashkernel memory to reserve.
- * Returns the base address on success, and -1ULL on failure.
- */
-static
-unsigned long long __init find_and_reserve_crashkernel(unsigned long long size)
-{
-	const unsigned long long alignment = 16<<20; 	/* 16M */
-	unsigned long long start = 0LL;
-
-	while (1) {
-		int ret;
-
-		start = find_e820_area(start, ULONG_MAX, size, alignment);
-		if (start == -1ULL)
-			return start;
-
-		/* try to reserve it */
-		ret = reserve_bootmem_generic(start, size, BOOTMEM_EXCLUSIVE);
-		if (ret >= 0)
-			return start;
-
-		start += alignment;
-	}
-}
-
 static inline unsigned long long get_total_mem(void)
 {
 	unsigned long long total;
 
-	total = max_low_pfn - min_low_pfn;
-#ifdef CONFIG_HIGHMEM
-	total += highend_pfn - highstart_pfn;
-#endif
+	total = max_pfn - min_low_pfn;
 
 	return total << PAGE_SHIFT;
 }
@@ -543,21 +512,25 @@ static void __init reserve_crashkernel(v
 
 	/* 0 means: find the address automatically */
 	if (crash_base <= 0) {
-		crash_base = find_and_reserve_crashkernel(crash_size);
+		const unsigned long long alignment = 16<<20;	/* 16M */
+
+		crash_base = find_e820_area(alignment, ULONG_MAX, crash_size,
+				 alignment);
 		if (crash_base == -1ULL) {
-			pr_info("crashkernel reservation failed. "
-				"No suitable area found.\n");
+			pr_info("crashkernel reservation failed - No suitable area found.\n");
 			return;
 		}
 	} else {
-		ret = reserve_bootmem_generic(crash_base, crash_size,
-					BOOTMEM_EXCLUSIVE);
-		if (ret < 0) {
-			pr_info("crashkernel reservation failed - "
-				"memory is in use\n");
+		unsigned long long start;
+
+		start = find_e820_area(crash_base, ULONG_MAX, crash_size,
+				 1<<20);
+		if (start != crash_base) {
+			pr_info("crashkernel reservation failed - memory is in use.\n");
 			return;
 		}
 	}
+	reserve_early(crash_base, crash_base + crash_size, "CRASH KERNEL");
 
 	printk(KERN_INFO "Reserving %ldMB of memory at %ldMB "
 			"for crashkernel (System RAM: %ldMB)\n",
@@ -935,6 +908,8 @@ void __init setup_arch(char **cmdline_p)
 
 	reserve_initrd();
 
+	reserve_crashkernel();
+
 	vsmp_init();
 
 	io_delay_init();
@@ -965,8 +940,6 @@ void __init setup_arch(char **cmdline_p)
 
 	initmem_init(0, max_pfn, acpi, k8);
 
-	reserve_crashkernel();
-
 #ifdef CONFIG_X86_64
 	/*
 	 * dma32_reserve_bootmem() allocates bootmem which may conflict

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

* Re: [PATCH] x86: crash kernel reserve with reserve_early -v2
  2009-11-23  1:18 [PATCH] x86: crash kernel reserve with reserve_early -v2 Yinghai Lu
@ 2009-11-23  2:34 ` Eric W. Biederman
  2009-11-23  3:36   ` Yinghai Lu
  2009-11-23  8:42 ` [tip:x86/mm] x86: Change crash kernel to reserve via reserve_early() tip-bot for Yinghai Lu
  1 sibling, 1 reply; 5+ messages in thread
From: Eric W. Biederman @ 2009-11-23  2:34 UTC (permalink / raw)
  To: Yinghai Lu
  Cc: Ingo Molnar, Thomas Gleixner, H. Peter Anvin,
	linux-kernel@vger.kernel.org

Yinghai Lu <yinghai@kernel.org> writes:

> use find_e820_area/reserve_early instead.
>
> -v2: address Eric's request, to restore original semantics.
>      will fail, if the provided address can not be used.

This patch seems reasonable.

YH what is the benefit of using reserve_early, and moving
reserve_crashkernel earlier?

Eric

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

* Re: [PATCH] x86: crash kernel reserve with reserve_early -v2
  2009-11-23  2:34 ` Eric W. Biederman
@ 2009-11-23  3:36   ` Yinghai Lu
  2009-11-23  5:12     ` Eric W. Biederman
  0 siblings, 1 reply; 5+ messages in thread
From: Yinghai Lu @ 2009-11-23  3:36 UTC (permalink / raw)
  To: Eric W. Biederman
  Cc: Ingo Molnar, Thomas Gleixner, H. Peter Anvin,
	linux-kernel@vger.kernel.org

Eric W. Biederman wrote:
> Yinghai Lu <yinghai@kernel.org> writes:
> 
>> use find_e820_area/reserve_early instead.
>>
>> -v2: address Eric's request, to restore original semantics.
>>      will fail, if the provided address can not be used.
> 
> This patch seems reasonable.
> 
> YH what is the benefit of using reserve_early, and moving
> reserve_crashkernel earlier?

old way mixing find_e820_area and reserve_bootmem like bandit...

also there are some effects to remove bootmem, so we try to reduce bootmem reference.

YH

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

* Re: [PATCH] x86: crash kernel reserve with reserve_early -v2
  2009-11-23  3:36   ` Yinghai Lu
@ 2009-11-23  5:12     ` Eric W. Biederman
  0 siblings, 0 replies; 5+ messages in thread
From: Eric W. Biederman @ 2009-11-23  5:12 UTC (permalink / raw)
  To: Yinghai Lu
  Cc: Ingo Molnar, Thomas Gleixner, H. Peter Anvin,
	linux-kernel@vger.kernel.org

Yinghai Lu <yinghai@kernel.org> writes:

> Eric W. Biederman wrote:
>> Yinghai Lu <yinghai@kernel.org> writes:
>> 
>>> use find_e820_area/reserve_early instead.
>>>
>>> -v2: address Eric's request, to restore original semantics.
>>>      will fail, if the provided address can not be used.
>> 
>> This patch seems reasonable.
>> 
>> YH what is the benefit of using reserve_early, and moving
>> reserve_crashkernel earlier?
>
> old way mixing find_e820_area and reserve_bootmem like bandit...

Sounds like bitrot of the best practices.

> also there are some effects to remove bootmem, so we try to reduce bootmem reference.

Makes sense.  Extent based allocators early allocators are much more efficient.

Eric

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

* [tip:x86/mm] x86: Change crash kernel to reserve via reserve_early()
  2009-11-23  1:18 [PATCH] x86: crash kernel reserve with reserve_early -v2 Yinghai Lu
  2009-11-23  2:34 ` Eric W. Biederman
@ 2009-11-23  8:42 ` tip-bot for Yinghai Lu
  1 sibling, 0 replies; 5+ messages in thread
From: tip-bot for Yinghai Lu @ 2009-11-23  8:42 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, yinghai, tglx, mingo, ebiederm

Commit-ID:  44280733e71ad15377735b42d8538c109c94d7e3
Gitweb:     http://git.kernel.org/tip/44280733e71ad15377735b42d8538c109c94d7e3
Author:     Yinghai Lu <yinghai@kernel.org>
AuthorDate: Sun, 22 Nov 2009 17:18:49 -0800
Committer:  Ingo Molnar <mingo@elte.hu>
CommitDate: Mon, 23 Nov 2009 09:09:23 +0100

x86: Change crash kernel to reserve via reserve_early()

use find_e820_area()/reserve_early() instead.

-v2: address Eric's request, to restore original semantics.
     will fail, if the provided address can not be used.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Acked-by: Eric W. Biederman <ebiederm@xmission.com>
LKML-Reference: <4B09E2F9.7040403@kernel.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 arch/x86/kernel/setup.c |   57 ++++++++++++----------------------------------
 1 files changed, 15 insertions(+), 42 deletions(-)

diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index d2043a0..e3eae59 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -487,42 +487,11 @@ static void __init reserve_early_setup_data(void)
 
 #ifdef CONFIG_KEXEC
 
-/**
- * Reserve @size bytes of crashkernel memory at any suitable offset.
- *
- * @size: Size of the crashkernel memory to reserve.
- * Returns the base address on success, and -1ULL on failure.
- */
-static
-unsigned long long __init find_and_reserve_crashkernel(unsigned long long size)
-{
-	const unsigned long long alignment = 16<<20; 	/* 16M */
-	unsigned long long start = 0LL;
-
-	while (1) {
-		int ret;
-
-		start = find_e820_area(start, ULONG_MAX, size, alignment);
-		if (start == -1ULL)
-			return start;
-
-		/* try to reserve it */
-		ret = reserve_bootmem_generic(start, size, BOOTMEM_EXCLUSIVE);
-		if (ret >= 0)
-			return start;
-
-		start += alignment;
-	}
-}
-
 static inline unsigned long long get_total_mem(void)
 {
 	unsigned long long total;
 
-	total = max_low_pfn - min_low_pfn;
-#ifdef CONFIG_HIGHMEM
-	total += highend_pfn - highstart_pfn;
-#endif
+	total = max_pfn - min_low_pfn;
 
 	return total << PAGE_SHIFT;
 }
@@ -542,21 +511,25 @@ static void __init reserve_crashkernel(void)
 
 	/* 0 means: find the address automatically */
 	if (crash_base <= 0) {
-		crash_base = find_and_reserve_crashkernel(crash_size);
+		const unsigned long long alignment = 16<<20;	/* 16M */
+
+		crash_base = find_e820_area(alignment, ULONG_MAX, crash_size,
+				 alignment);
 		if (crash_base == -1ULL) {
-			pr_info("crashkernel reservation failed. "
-				"No suitable area found.\n");
+			pr_info("crashkernel reservation failed - No suitable area found.\n");
 			return;
 		}
 	} else {
-		ret = reserve_bootmem_generic(crash_base, crash_size,
-					BOOTMEM_EXCLUSIVE);
-		if (ret < 0) {
-			pr_info("crashkernel reservation failed - "
-				"memory is in use\n");
+		unsigned long long start;
+
+		start = find_e820_area(crash_base, ULONG_MAX, crash_size,
+				 1<<20);
+		if (start != crash_base) {
+			pr_info("crashkernel reservation failed - memory is in use.\n");
 			return;
 		}
 	}
+	reserve_early(crash_base, crash_base + crash_size, "CRASH KERNEL");
 
 	printk(KERN_INFO "Reserving %ldMB of memory at %ldMB "
 			"for crashkernel (System RAM: %ldMB)\n",
@@ -927,6 +900,8 @@ void __init setup_arch(char **cmdline_p)
 
 	reserve_initrd();
 
+	reserve_crashkernel();
+
 	vsmp_init();
 
 	io_delay_init();
@@ -957,8 +932,6 @@ void __init setup_arch(char **cmdline_p)
 	 */
 	find_smp_config();
 
-	reserve_crashkernel();
-
 #ifdef CONFIG_X86_64
 	/*
 	 * dma32_reserve_bootmem() allocates bootmem which may conflict

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

end of thread, other threads:[~2009-11-23  8:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-11-23  1:18 [PATCH] x86: crash kernel reserve with reserve_early -v2 Yinghai Lu
2009-11-23  2:34 ` Eric W. Biederman
2009-11-23  3:36   ` Yinghai Lu
2009-11-23  5:12     ` Eric W. Biederman
2009-11-23  8:42 ` [tip:x86/mm] x86: Change crash kernel to reserve via reserve_early() tip-bot for Yinghai Lu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox