public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [Patch 3/8] ia64: add CONFIG_KEXEC_AUTO_RESERVE
  2009-08-12  8:15 [Patch 0/8] V3 Implement crashkernel=auto Amerigo Wang
@ 2009-08-12  8:15 ` Amerigo Wang
  0 siblings, 0 replies; 21+ messages in thread
From: Amerigo Wang @ 2009-08-12  8:15 UTC (permalink / raw)
  To: linux-kernel
  Cc: tony.luck, linux-ia64, Neil Horman, Eric W. Biederman, Andi Kleen,
	Amerigo Wang, akpm, bernhard.walle, Fenghua Yu, Ingo Molnar,
	Anton Vorontsov


Introduce a new config option KEXEC_AUTO_RESERVE for ia64.

Signed-off-by: WANG Cong <amwang@redhat.com>
Acked-by: Neil Horman <nhorman@tuxdriver.com>

---

Index: linux-2.6/arch/ia64/Kconfig
===================================================================
--- linux-2.6.orig/arch/ia64/Kconfig
+++ linux-2.6/arch/ia64/Kconfig
@@ -582,6 +582,20 @@ config KEXEC
 	  support.  As of this writing the exact hardware interface is
 	  strongly in flux, so no good recommendation can be made.
 
+config KEXEC_AUTO_RESERVE
+	bool "automatically reserve memory for kexec kernel"
+	depends on KEXEC
+	default y
+	---help---
+	  Automatically reserve memory for a kexec kernel, so that you don't
+	  need to specify numbers for the "crashkernel=X@Y" boot option,
+	  instead you can use "crashkernel=auto". To make this work, you need
+	  to have more than 4G memory.
+
+	  The reserved memory size is different depends on how much memory
+	  you actually have. Please check Documentation/kdump/kdump.txt.
+	  If you doubt, say N.
+
 config CRASH_DUMP
 	  bool "kernel crash dumps"
 	  depends on IA64_MCA_RECOVERY && !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)

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

* [Patch 0/8] V5 Implement crashkernel=auto
@ 2009-08-27  3:15 Amerigo Wang
  2009-08-27  3:15 ` [Patch 1/8] x86: add CONFIG_KEXEC_AUTO_RESERVE Amerigo Wang
                   ` (8 more replies)
  0 siblings, 9 replies; 21+ messages in thread
From: Amerigo Wang @ 2009-08-27  3:15 UTC (permalink / raw)
  To: linux-kernel
  Cc: tony.luck, linux-ia64, Neil Horman, Eric W. Biederman,
	kamezawa.hiroyu, Andi Kleen, Michael Ellerman, Amerigo Wang,
	M. Mohan Kumar, akpm, bernhard.walle, Fenghua Yu, Ingo Molnar,
	Anton Vorontsov

V4 -> V5:
 - Rename the global functions, as suggested by Andrew.
 - Save some macros, as suggested by Andrew.
 - Change the high threshold, from 32G to 4G.
 - Change the low threshold on ppc, suggested by ppc developers.
 - Make the mm part as a seperate function, suggest by Eric.
 - Make the IA64 code more readable.
 - Reorder the patchset again, since review from mm people is done.

V3 -> V4:
 - Reorder the patches.
 - Really free the reserved memory, instead of remapping it.
   (Thanks to KAMEZAWA Hiroyuki!)
 - Release the reserved memory resource when the size is 0.
 - Use strict_strtoul() instead of simple_strtoul().

V2 -> V3:
 - Use more clever way to calculate reserved memory size, especially for IA64.
 - Add that patch that implements shrinking reserved memory

V1 -> V2:
 - Use include/asm-generic/kexec.h, suggested by Neil.
 - Rename a local variable, suggested by Fenghua.
 - Fix some style problems found by checkpatch.pl.
 - Unify the Kconfig docs.

This series of patch implements automatically reserved memory for crashkernel,
by introducing a new boot option "crashkernel=auto". This idea is from Neil.

In case of breaking user-space applications, it modifies this boot option after
it decides how much memory should be reserved.

On different arch, the threshold and reserved memory size is different. Please
refer patch 7/8 which contains an update for the documentation.

Patch 8/8 implements shrinking reserved memory at run-time, which is useful
when more than enough memory is reserved automatically.

This patchset _is_ already tested on x86_64, IA64 and ppc64.

Cc: Neil Horman <nhorman@redhat.com>
Cc: M. Mohan Kumar <mohan@in.ibm.com>
Cc: Michael Ellerman <michael@ellerman.id.au>
Cc: Eric W. Biederman <ebiederm@xmission.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Tony Luck <tony.luck@intel.com>
Cc: Anton Vorontsov <avorontsov@ru.mvista.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: Bernhard Walle <bernhard.walle@gmx.de>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Signed-off-by: WANG Cong <amwang@redhat.com>

---
 Documentation/kdump/kdump.txt    |   29 +++++++++
 arch/ia64/Kconfig                |   14 ++++
 arch/ia64/include/asm/kexec.h    |   44 +++++++++++++
 arch/powerpc/Kconfig             |   11 +++
 arch/powerpc/include/asm/kexec.h |   39 ++++++++++++
 arch/x86/Kconfig                 |   13 ++++
 arch/x86/include/asm/kexec.h     |    1 
 include/asm-generic/kexec.h      |   16 +++++
 include/linux/kexec.h            |    2 
 kernel/kexec.c                   |  124 +++++++++++++++++++++++++++++++++++++++
 kernel/ksysfs.c                  |   21 ++++++
 11 files changed, 314 insertions(+)


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

* [Patch 1/8] x86: add CONFIG_KEXEC_AUTO_RESERVE
  2009-08-27  3:15 [Patch 0/8] V5 Implement crashkernel=auto Amerigo Wang
@ 2009-08-27  3:15 ` Amerigo Wang
  2009-08-27  3:15 ` [Patch 2/8] x86: implement crashkernel=auto Amerigo Wang
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 21+ messages in thread
From: Amerigo Wang @ 2009-08-27  3:15 UTC (permalink / raw)
  To: linux-kernel
  Cc: Anton Vorontsov, tony.luck, linux-ia64, Neil Horman,
	Eric W. Biederman, Andi Kleen, Ingo Molnar, Michael Ellerman,
	M. Mohan Kumar, akpm, bernhard.walle, Fenghua Yu, kamezawa.hiroyu,
	Amerigo Wang


Introduce a new config option KEXEC_AUTO_RESERVE for x86.

Signed-off-by: WANG Cong <amwang@redhat.com>
Acked-by: Neil Horman <nhorman@tuxdriver.com>

---

Index: linux-2.6/arch/x86/Kconfig
===================================================================
--- linux-2.6.orig/arch/x86/Kconfig
+++ linux-2.6/arch/x86/Kconfig
@@ -1482,6 +1482,19 @@ config KEXEC
 	  support.  As of this writing the exact hardware interface is
 	  strongly in flux, so no good recommendation can be made.
 
+config KEXEC_AUTO_RESERVE
+	bool "automatically reserve memory for kexec kernel"
+	depends on KEXEC
+	default y
+	---help---
+	  Automatically reserve memory for a kexec kernel, so that you don't
+	  need to specify numbers for the "crashkernel=X@Y" boot option,
+	  instead you can use "crashkernel=auto". To make this work, you need
+	  to have more than 4G memory.
+
+	  On x86_32, 128M is reserved, on x86_64 1/32 of your memory is
+	  reserved, but it will not exceed 4G.
+
 config CRASH_DUMP
 	bool "kernel crash dumps"
 	depends on X86_64 || (X86_32 && HIGHMEM)

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

* [Patch 2/8] x86: implement crashkernel=auto
  2009-08-27  3:15 [Patch 0/8] V5 Implement crashkernel=auto Amerigo Wang
  2009-08-27  3:15 ` [Patch 1/8] x86: add CONFIG_KEXEC_AUTO_RESERVE Amerigo Wang
@ 2009-08-27  3:15 ` Amerigo Wang
  2009-08-27  3:16 ` [Patch 3/8] ia64: add CONFIG_KEXEC_AUTO_RESERVE Amerigo Wang
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 21+ messages in thread
From: Amerigo Wang @ 2009-08-27  3:15 UTC (permalink / raw)
  To: linux-kernel
  Cc: tony.luck, linux-ia64, Neil Horman, Eric W. Biederman,
	kamezawa.hiroyu, Andi Kleen, Amerigo Wang, Michael Ellerman,
	M. Mohan Kumar, akpm, bernhard.walle, Fenghua Yu, Ingo Molnar,
	Anton Vorontsov


Implement "crashkernel=auto" for x86 first, other arch will be added in the
following patches.

The kernel will modify this command line with the actually reserved size,
in case of breaking any user-space programs.

Signed-off-by: WANG Cong <amwang@redhat.com>
Cc: Eric W. Biederman <ebiederm@xmission.com>
Cc: Ingo Molnar <mingo@elte.hu>

---

Index: linux-2.6/kernel/kexec.c
===================================================================
--- linux-2.6.orig/kernel/kexec.c
+++ linux-2.6/kernel/kexec.c
@@ -37,6 +37,7 @@
 #include <asm/io.h>
 #include <asm/system.h>
 #include <asm/sections.h>
+#include <asm/setup.h>
 
 /* Per cpu memory for storing cpu states in case of system crash. */
 note_buf_t* crash_notes;
@@ -1269,6 +1270,37 @@ static int __init parse_crashkernel_simp
 	return 0;
 }
 
+#ifdef CONFIG_KEXEC_AUTO_RESERVE
+#ifndef arch_default_crash_size
+unsigned long long arch_default_crash_size(unsigned long long total_size)
+{
+	if (total_size < KEXEC_AUTO_THRESHOLD)
+		return 0;
+	else {
+#ifdef CONFIG_64BIT
+		if (total_size > (1ULL<<37)) /* 128G */
+			return KEXEC_AUTO_RESERVED_SIZE
+				* ((1ULL<<37) / KEXEC_AUTO_THRESHOLD);
+		return 1ULL<<ilog2(roundup(total_size/32, 1ULL<<21));
+#else
+		return KEXEC_AUTO_RESERVED_SIZE;
+#endif
+	}
+}
+#define arch_default_crash_size arch_default_crash_size
+#endif
+
+#ifndef arch_default_crash_base
+unsigned long long arch_default_crash_base(void)
+{
+	/* 0 means find the base address automatically. */
+	return 0;
+}
+#define arch_default_crash_base arch_default_crash_base
+#endif
+
+#endif /*CONFIG_KEXEC_AUTO_RESERVE*/
+
 /*
  * That function is the entry point for command line parsing and should be
  * called from the arch-specific code.
@@ -1297,6 +1329,39 @@ int __init parse_crashkernel(char 		 *cm
 
 	ck_cmdline += 12; /* strlen("crashkernel=") */
 
+#ifdef CONFIG_KEXEC_AUTO_RESERVE
+	if (strncmp(ck_cmdline, "auto", 4) == 0) {
+		unsigned long long size;
+		int len;
+		char tmp[32];
+
+		size = arch_default_crash_size(system_ram);
+		if (size != 0) {
+			*crash_size = size;
+			*crash_base = arch_default_crash_base();
+			len = scnprintf(tmp, sizeof(tmp), "%luM@%luM",
+					(unsigned long)(*crash_size)>>20,
+					(unsigned long)(*crash_base)>>20);
+			/* 'len' can't be <= 4. */
+			if (likely((len - 4 + strlen(cmdline))
+					< COMMAND_LINE_SIZE - 1)) {
+				memmove(ck_cmdline + len, ck_cmdline + 4,
+					strlen(cmdline) - (ck_cmdline + 4 - cmdline) + 1);
+				memcpy(ck_cmdline, tmp, len);
+			}
+			return 0;
+		} else {
+			/*
+			 * We can't reserve memory auotmatcally,
+			 * remove "crashkernel=auto" from cmdline.
+			 */
+			ck_cmdline += 4; /* strlen("auto") */
+			memmove(ck_cmdline - 16, ck_cmdline,
+				strlen(cmdline) - (ck_cmdline - cmdline) + 1);
+			return -ENOMEM;
+		}
+	}
+#endif
 	/*
 	 * if the commandline contains a ':', then that's the extended
 	 * syntax -- if not, it must be the classic syntax
Index: linux-2.6/arch/x86/include/asm/kexec.h
===================================================================
--- linux-2.6.orig/arch/x86/include/asm/kexec.h
+++ linux-2.6/arch/x86/include/asm/kexec.h
@@ -23,6 +23,7 @@
 
 #include <asm/page.h>
 #include <asm/ptrace.h>
+#include <asm-generic/kexec.h>
 
 /*
  * KEXEC_SOURCE_MEMORY_LIMIT maximum page get_free_page can return.
Index: linux-2.6/include/asm-generic/kexec.h
===================================================================
--- /dev/null
+++ linux-2.6/include/asm-generic/kexec.h
@@ -0,0 +1,16 @@
+#ifndef _ASM_GENERIC_KEXEC_H
+#define _ASM_GENERIC_KEXEC_H
+
+#ifdef CONFIG_KEXEC_AUTO_RESERVE
+
+#ifndef KEXEC_AUTO_RESERVED_SIZE
+#define KEXEC_AUTO_RESERVED_SIZE (1ULL<<27) /* 128M */
+#endif
+#ifndef KEXEC_AUTO_THRESHOLD
+#define KEXEC_AUTO_THRESHOLD (1ULL<<32) /* 4G */
+#endif
+
+
+#endif /* CONFIG_KEXEC_AUTO_RESERVE */
+
+#endif

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

* [Patch 3/8] ia64: add CONFIG_KEXEC_AUTO_RESERVE
  2009-08-27  3:15 [Patch 0/8] V5 Implement crashkernel=auto Amerigo Wang
  2009-08-27  3:15 ` [Patch 1/8] x86: add CONFIG_KEXEC_AUTO_RESERVE Amerigo Wang
  2009-08-27  3:15 ` [Patch 2/8] x86: implement crashkernel=auto Amerigo Wang
@ 2009-08-27  3:16 ` Amerigo Wang
  2009-08-27  3:16 ` [Patch 4/8] ia64: implement crashkernel=auto Amerigo Wang
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 21+ messages in thread
From: Amerigo Wang @ 2009-08-27  3:16 UTC (permalink / raw)
  To: linux-kernel
  Cc: tony.luck, linux-ia64, Neil Horman, Eric W. Biederman, Andi Kleen,
	Ingo Molnar, Michael Ellerman, Amerigo Wang, M. Mohan Kumar, akpm,
	bernhard.walle, Fenghua Yu, kamezawa.hiroyu, Anton Vorontsov


Introduce a new config option KEXEC_AUTO_RESERVE for ia64.

Signed-off-by: WANG Cong <amwang@redhat.com>
Acked-by: Neil Horman <nhorman@tuxdriver.com>

---

Index: linux-2.6/arch/ia64/Kconfig
===================================================================
--- linux-2.6.orig/arch/ia64/Kconfig
+++ linux-2.6/arch/ia64/Kconfig
@@ -582,6 +582,20 @@ config KEXEC
 	  support.  As of this writing the exact hardware interface is
 	  strongly in flux, so no good recommendation can be made.
 
+config KEXEC_AUTO_RESERVE
+	bool "automatically reserve memory for kexec kernel"
+	depends on KEXEC
+	default y
+	---help---
+	  Automatically reserve memory for a kexec kernel, so that you don't
+	  need to specify numbers for the "crashkernel=X@Y" boot option,
+	  instead you can use "crashkernel=auto". To make this work, you need
+	  to have more than 4G memory.
+
+	  The reserved memory size is different depends on how much memory
+	  you actually have. Please check Documentation/kdump/kdump.txt.
+	  If you doubt, say N.
+
 config CRASH_DUMP
 	  bool "kernel crash dumps"
 	  depends on IA64_MCA_RECOVERY && !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)

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

* [Patch 4/8] ia64: implement crashkernel=auto
  2009-08-27  3:15 [Patch 0/8] V5 Implement crashkernel=auto Amerigo Wang
                   ` (2 preceding siblings ...)
  2009-08-27  3:16 ` [Patch 3/8] ia64: add CONFIG_KEXEC_AUTO_RESERVE Amerigo Wang
@ 2009-08-27  3:16 ` Amerigo Wang
  2009-08-27  4:19   ` Yu, Fenghua
  2009-08-27  3:16 ` [Patch 5/8] powerpc: add CONFIG_KEXEC_AUTO_RESERVE Amerigo Wang
                   ` (4 subsequent siblings)
  8 siblings, 1 reply; 21+ messages in thread
From: Amerigo Wang @ 2009-08-27  3:16 UTC (permalink / raw)
  To: linux-kernel
  Cc: Anton Vorontsov, tony.luck, linux-ia64, Neil Horman,
	Eric W. Biederman, kamezawa.hiroyu, Andi Kleen, Michael Ellerman,
	M. Mohan Kumar, akpm, bernhard.walle, Fenghua Yu, Ingo Molnar,
	Amerigo Wang


Since in patch 2/8 we already implement the generic part, this will
add the rest part for ia64.

Signed-off-by: WANG Cong <amwang@redhat.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: Tony Luck <tony.luck@intel.com>

---

Index: linux-2.6/arch/ia64/include/asm/kexec.h
===================================================================
--- linux-2.6.orig/arch/ia64/include/asm/kexec.h
+++ linux-2.6/arch/ia64/include/asm/kexec.h
@@ -1,6 +1,7 @@
 #ifndef _ASM_IA64_KEXEC_H
 #define _ASM_IA64_KEXEC_H
 
+#include <asm-generic/kexec.h>
 
 /* Maximum physical address we can use pages from */
 #define KEXEC_SOURCE_MEMORY_LIMIT (-1UL)
@@ -19,6 +20,49 @@
                 flush_icache_range(page_addr, page_addr + PAGE_SIZE); \
         } while(0)
 
+#ifdef CONFIG_KEXEC_AUTO_RESERVE
+#define MBYTES(n) ((n)*1024*1024ULL)
+#define GBYTES(n) ((n)*1024*1024*1024ULL)
+/*
+       Memory size     Reserved memory
+       ===========     ===============
+       [4G, 12G)       256M
+       [12G, 128G)     512M
+       [128G, 256G)    768M
+       [256G, 378G)    1024M
+       [378G, 512G)    1536M
+       [512G, 768G)    2048M
+       [768G, )        3072M
+ */
+static inline
+unsigned long long arch_default_crash_size(unsigned long long total_size)
+{
+	unsigned long long ret;
+
+	if (total_size >= GBYTES(4) && total_size < GBYTES(12))
+		ret = MBYTES(256);
+	else if (total_size >= GBYTES(12) && total_size < GBYTES(128))
+		ret = MBYTES(512);
+	else if (total_size >= GBYTES(128) && total_size < GBYTES(256))
+		ret = MBYTES(768);
+	else if (total_size >= GBYTES(256) && total_size < GBYTES(378))
+		ret = MBYTES(1024);
+	else if (total_size >= GBYTES(318) && total_size < GBYTES(512))
+		ret = MBYTES(1536);
+	else if (total_size >= GBYTES(512) && total_size < GBYTES(768))
+		ret = MBYTES(2048);
+	else
+		ret = MBYTES(3072);
+	if (!ia64_platform_is("sn2") && !ia64_platform_is("uv"))
+		if (ret > GBYTES(4))
+			ret = ret / GBYTES(4) * MBYTES(256);
+	return ret;
+}
+#undef GBYTES
+#undef MBYTES
+#define arch_default_crash_size arch_default_crash_size
+#endif
+
 extern struct kimage *ia64_kimage;
 extern const unsigned int relocate_new_kernel_size;
 extern void relocate_new_kernel(unsigned long, unsigned long,

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

* [Patch 5/8] powerpc: add CONFIG_KEXEC_AUTO_RESERVE
  2009-08-27  3:15 [Patch 0/8] V5 Implement crashkernel=auto Amerigo Wang
                   ` (3 preceding siblings ...)
  2009-08-27  3:16 ` [Patch 4/8] ia64: implement crashkernel=auto Amerigo Wang
@ 2009-08-27  3:16 ` Amerigo Wang
  2009-08-27  3:16 ` [Patch 6/8] powerpc: implement crashkernel=auto Amerigo Wang
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 21+ messages in thread
From: Amerigo Wang @ 2009-08-27  3:16 UTC (permalink / raw)
  To: linux-kernel
  Cc: tony.luck, linux-ia64, Neil Horman, Eric W. Biederman, Andi Kleen,
	Ingo Molnar, Amerigo Wang, Michael Ellerman, M. Mohan Kumar, akpm,
	bernhard.walle, Fenghua Yu, kamezawa.hiroyu, Anton Vorontsov


Introduce a new config option KEXEC_AUTO_RESERVE for powerpc.

Signed-off-by: WANG Cong <amwang@redhat.com>
Acked-by: Neil Horman <nhorman@tuxdriver.com>

---

Index: linux-2.6/arch/powerpc/Kconfig
===================================================================
--- linux-2.6.orig/arch/powerpc/Kconfig
+++ linux-2.6/arch/powerpc/Kconfig
@@ -346,6 +346,17 @@ config KEXEC
 	  support.  As of this writing the exact hardware interface is
 	  strongly in flux, so no good recommendation can be made.
 
+config KEXEC_AUTO_RESERVE
+	bool "automatically reserve memory for kexec kernel"
+	depends on KEXEC
+	default y
+	---help---
+	  Automatically reserve memory for a kexec kernel, so that you don't
+	  need to specify numbers for the "crashkernel=X@Y" boot option,
+	  instead you can use "crashkernel=auto". To make this work, you need
+	  to have more than 2G memory. On PPC, 128M or 256M is reserved, on
+	  PPC64 1/32 of your physical memory, but it will not exceed 4G.
+
 config CRASH_DUMP
 	bool "Build a kdump crash kernel"
 	depends on PPC64 || 6xx

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

* [Patch 6/8] powerpc: implement crashkernel=auto
  2009-08-27  3:15 [Patch 0/8] V5 Implement crashkernel=auto Amerigo Wang
                   ` (4 preceding siblings ...)
  2009-08-27  3:16 ` [Patch 5/8] powerpc: add CONFIG_KEXEC_AUTO_RESERVE Amerigo Wang
@ 2009-08-27  3:16 ` Amerigo Wang
  2009-08-27 18:22   ` Yu, Fenghua
  2009-08-27  3:16 ` [Patch 7/8] doc: update the kdump document Amerigo Wang
                   ` (2 subsequent siblings)
  8 siblings, 1 reply; 21+ messages in thread
From: Amerigo Wang @ 2009-08-27  3:16 UTC (permalink / raw)
  To: linux-kernel
  Cc: tony.luck, linux-ia64, Neil Horman, Eric W. Biederman,
	kamezawa.hiroyu, Andi Kleen, Michael Ellerman, Amerigo Wang,
	M. Mohan Kumar, akpm, bernhard.walle, Fenghua Yu, Ingo Molnar,
	Anton Vorontsov


Since in patch 2/8 we already implement the generic part, this will
add the rest part for powerpc.

Signed-off-by: WANG Cong <amwang@redhat.com>
Cc: Anton Vorontsov <avorontsov@ru.mvista.com>
Cc: M. Mohan Kumar <mohan@in.ibm.com>
Cc: Michael Ellerman <michael@ellerman.id.au>

---

Index: linux-2.6/arch/powerpc/include/asm/kexec.h
===================================================================
--- linux-2.6.orig/arch/powerpc/include/asm/kexec.h
+++ linux-2.6/arch/powerpc/include/asm/kexec.h
@@ -39,6 +39,45 @@ typedef void (*crash_shutdown_t)(void);
 
 #ifdef CONFIG_KEXEC
 
+#ifdef CONFIG_KEXEC_AUTO_RESERVE
+
+#ifndef KEXEC_AUTO_THRESHOLD
+#define KEXEC_AUTO_THRESHOLD (1ULL<<31) /* 2G */
+#endif
+
+#ifndef arch_default_crash_base
+static inline
+unsigned long long arch_default_crash_base(void)
+{
+	return KDUMP_KERNELBASE;
+}
+#define arch_default_crash_base arch_default_crash_base
+#endif
+
+#ifndef arch_default_crash_size
+static inline
+unsigned long long arch_default_crash_size(unsigned long long total_size)
+{
+	if (total_size < KEXEC_AUTO_THRESHOLD)
+		return 0;
+	if (total_size < (1ULL<<32))
+		return 1ULL<<27;
+	else {
+#ifdef CONFIG_64BIT
+		if (total_size > (1ULL<<37)) /* 128G */
+			return 1ULL<<32; /* 4G */
+		return 1ULL<<ilog2(roundup(total_size/32, 1ULL<<21));
+#else
+		return 1ULL<<28;
+#endif
+	}
+}
+#define arch_default_crash_size arch_default_crash_size
+#endif
+
+#endif
+#include <asm-generic/kexec.h>
+
 /*
  * This function is responsible for capturing register states if coming
  * via panic or invoking dump using sysrq-trigger.

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

* [Patch 7/8] doc: update the kdump document
  2009-08-27  3:15 [Patch 0/8] V5 Implement crashkernel=auto Amerigo Wang
                   ` (5 preceding siblings ...)
  2009-08-27  3:16 ` [Patch 6/8] powerpc: implement crashkernel=auto Amerigo Wang
@ 2009-08-27  3:16 ` Amerigo Wang
  2009-08-27  3:17 ` [Patch 8/8] kexec: allow to shrink reserved memory Amerigo Wang
  2009-08-31  0:54 ` [Patch 0/8] V5 Implement crashkernel=auto Michael Ellerman
  8 siblings, 0 replies; 21+ messages in thread
From: Amerigo Wang @ 2009-08-27  3:16 UTC (permalink / raw)
  To: linux-kernel
  Cc: Anton Vorontsov, tony.luck, linux-ia64, Neil Horman,
	Eric W. Biederman, Andi Kleen, Ingo Molnar, Michael Ellerman,
	M. Mohan Kumar, akpm, bernhard.walle, Fenghua Yu, kamezawa.hiroyu,
	Amerigo Wang


Update the document for kdump.

Signed-off-by: WANG Cong <amwang@redhat.com>

---

Index: linux-2.6/Documentation/kdump/kdump.txt
===================================================================
--- linux-2.6.orig/Documentation/kdump/kdump.txt
+++ linux-2.6/Documentation/kdump/kdump.txt
@@ -147,6 +147,15 @@ System kernel config options
    analysis tools require a vmlinux with debug symbols in order to read
    and analyze a dump file.
 
+4) Enable "automatically reserve memory for kexec kernel" in
+   "Processor type and features."
+
+   CONFIG_KEXEC_AUTO_RESERVE=y
+
+   This will let you to use "crashkernel=auto", instead of specifying
+   numbers for "crashkernel=". Note, you need to have enough memory.
+   The threshold and reserved memory size are arch-dependent.
+
 Dump-capture kernel config options (Arch Independent)
 -----------------------------------------------------
 
@@ -266,6 +275,26 @@ This would mean:
     2) if the RAM size is between 512M and 2G (exclusive), then reserve 64M
     3) if the RAM size is larger than 2G, then reserve 128M
 
+Or you can use:
+
+    crashkernel=auto
+
+if you have enough memory. The threshold is 4G on ia64 and x86, 2G on powerpc,
+below which this won't work.
+
+The automatically reserved memory size would be 128M on x86_32, 128M or 256M
+on ppc, 1/32 of your physical memory size on x86_64 and ppc64 (but it will not
+grow if you have more than 128G memory). IA64 has its own policy, shown below:
+
+	Memory size	Reserved memory
+	===========	===============
+	[4G, 12G)	256M
+	[12G, 128G)	512M
+	[128G, 256G)	768M
+	[256G, 378G)	1024M
+	[378G, 512G)	1536M
+	[512G, 768G)	2048M
+	[768G, )	3072M
 
 
 Boot into System Kernel

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

* [Patch 8/8] kexec: allow to shrink reserved memory
  2009-08-27  3:15 [Patch 0/8] V5 Implement crashkernel=auto Amerigo Wang
                   ` (6 preceding siblings ...)
  2009-08-27  3:16 ` [Patch 7/8] doc: update the kdump document Amerigo Wang
@ 2009-08-27  3:17 ` Amerigo Wang
  2009-08-31  0:54 ` [Patch 0/8] V5 Implement crashkernel=auto Michael Ellerman
  8 siblings, 0 replies; 21+ messages in thread
From: Amerigo Wang @ 2009-08-27  3:17 UTC (permalink / raw)
  To: linux-kernel
  Cc: tony.luck, linux-ia64, Neil Horman, Eric W. Biederman,
	kamezawa.hiroyu, Andi Kleen, Amerigo Wang, Michael Ellerman,
	M. Mohan Kumar, akpm, bernhard.walle, Fenghua Yu, Ingo Molnar,
	Anton Vorontsov

This patch implements shrinking the reserved memory for crash kernel,
if it is more than enough.

For example, if you have already reserved 128M, now you just want 100M,
you can do:

# echo $((100*1024*1024)) > /sys/kernel/kexec_crash_size

Note, you can only do this before loading the crash kernel.

Cc: Neil Horman <nhorman@redhat.com>
Cc: Eric W. Biederman <ebiederm@xmission.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Signed-off-by: WANG Cong <amwang@redhat.com>

---

Index: linux-2.6/include/linux/kexec.h
===================================================================
--- linux-2.6.orig/include/linux/kexec.h
+++ linux-2.6/include/linux/kexec.h
@@ -206,6 +206,8 @@ extern size_t vmcoreinfo_max_size;
 
 int __init parse_crashkernel(char *cmdline, unsigned long long system_ram,
 		unsigned long long *crash_size, unsigned long long *crash_base);
+int crash_shrink_memory(unsigned long new_size);
+size_t crash_get_memory_size(void);
 
 #else /* !CONFIG_KEXEC */
 struct pt_regs;
Index: linux-2.6/kernel/kexec.c
===================================================================
--- linux-2.6.orig/kernel/kexec.c
+++ linux-2.6/kernel/kexec.c
@@ -31,6 +31,7 @@
 #include <linux/cpu.h>
 #include <linux/console.h>
 #include <linux/vmalloc.h>
+#include <linux/swap.h>
 
 #include <asm/page.h>
 #include <asm/uaccess.h>
@@ -1083,6 +1084,64 @@ void crash_kexec(struct pt_regs *regs)
 	}
 }
 
+size_t crash_get_memory_size(void)
+{
+	size_t size;
+	mutex_lock(&kexec_mutex);
+	size = crashk_res.end - crashk_res.start + 1;
+	mutex_unlock(&kexec_mutex);
+	return size;
+}
+
+static void free_reserved_phys_range(unsigned long begin, unsigned long end)
+{
+	unsigned long addr;
+
+	for (addr = begin; addr < end; addr += PAGE_SIZE) {
+		ClearPageReserved(pfn_to_page(addr >> PAGE_SHIFT));
+		init_page_count(pfn_to_page(addr >> PAGE_SHIFT));
+		free_page((unsigned long)__va(addr));
+		totalram_pages++;
+	}
+}
+
+int crash_shrink_memory(unsigned long new_size)
+{
+	int ret = 0;
+	unsigned long start, end;
+
+	mutex_lock(&kexec_mutex);
+
+	if (kexec_crash_image) {
+		ret = -ENOENT;
+		goto unlock;
+	}
+	start = crashk_res.start;
+	end = crashk_res.end;
+
+	if (new_size >= end - start + 1) {
+		ret = -EINVAL;
+		if (new_size == end - start + 1)
+			ret = 0;
+		goto unlock;
+	}
+
+	start = roundup(start, PAGE_SIZE);
+	end = roundup(start + new_size, PAGE_SIZE);
+
+	free_reserved_phys_range(end, crashk_res.end);
+
+	if (start == end) {
+		crashk_res.end = end;
+		release_resource(&crashk_res);
+	} else
+		crashk_res.end = end - 1;
+
+unlock:
+	mutex_unlock(&kexec_mutex);
+	return ret;
+}
+
 static u32 *append_elf_note(u32 *buf, char *name, unsigned type, void *data,
 			    size_t data_len)
 {
Index: linux-2.6/kernel/ksysfs.c
===================================================================
--- linux-2.6.orig/kernel/ksysfs.c
+++ linux-2.6/kernel/ksysfs.c
@@ -100,6 +100,26 @@ static ssize_t kexec_crash_loaded_show(s
 }
 KERNEL_ATTR_RO(kexec_crash_loaded);
 
+static ssize_t kexec_crash_size_show(struct kobject *kobj,
+				       struct kobj_attribute *attr, char *buf)
+{
+	return sprintf(buf, "%lu\n", crash_get_memory_size());
+}
+static ssize_t kexec_crash_size_store(struct kobject *kobj,
+				   struct kobj_attribute *attr,
+				   const char *buf, size_t count)
+{
+	unsigned long cnt;
+	int ret;
+
+	if (strict_strtoul(buf, 0, &cnt))
+		return -EINVAL;
+
+	ret = crash_shrink_memory(cnt);
+	return ret < 0 ? ret : count;
+}
+KERNEL_ATTR_RW(kexec_crash_size);
+
 static ssize_t vmcoreinfo_show(struct kobject *kobj,
 			       struct kobj_attribute *attr, char *buf)
 {
@@ -147,6 +167,7 @@ static struct attribute * kernel_attrs[]
 #ifdef CONFIG_KEXEC
 	&kexec_loaded_attr.attr,
 	&kexec_crash_loaded_attr.attr,
+	&kexec_crash_size_attr.attr,
 	&vmcoreinfo_attr.attr,
 #endif
 	NULL

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

* RE: [Patch 4/8] ia64: implement crashkernel=auto
  2009-08-27  3:16 ` [Patch 4/8] ia64: implement crashkernel=auto Amerigo Wang
@ 2009-08-27  4:19   ` Yu, Fenghua
  2009-08-27 10:26     ` Amerigo Wang
  0 siblings, 1 reply; 21+ messages in thread
From: Yu, Fenghua @ 2009-08-27  4:19 UTC (permalink / raw)
  To: 'Amerigo Wang', 'linux-kernel@vger.kernel.org'
  Cc: 'Anton Vorontsov', Luck, Tony,
	'linux-ia64@vger.kernel.org', 'Neil Horman',
	'Eric W. Biederman',
	'kamezawa.hiroyu@jp.fujitsu.com', 'Andi Kleen',
	'Michael Ellerman', 'M. Mohan Kumar',
	'akpm@linux-foundation.org',
	'bernhard.walle@gmx.de', 'Ingo Molnar'

>
>Since in patch 2/8 we already implement the generic part, this will
>add the rest part for ia64.
>
>Signed-off-by: WANG Cong <amwang@redhat.com>
>Cc: Fenghua Yu <fenghua.yu@intel.com>
>Cc: Tony Luck <tony.luck@intel.com>
>
>---
>
>Index: linux-2.6/arch/ia64/include/asm/kexec.h
>===================================================================
>--- linux-2.6.orig/arch/ia64/include/asm/kexec.h
>+++ linux-2.6/arch/ia64/include/asm/kexec.h
>@@ -1,6 +1,7 @@
> #ifndef _ASM_IA64_KEXEC_H
> #define _ASM_IA64_KEXEC_H
>
>+#include <asm-generic/kexec.h>
>
> /* Maximum physical address we can use pages from */
> #define KEXEC_SOURCE_MEMORY_LIMIT (-1UL)
>@@ -19,6 +20,49 @@
>                 flush_icache_range(page_addr, page_addr + PAGE_SIZE); \
>         } while(0)
>
>+#ifdef CONFIG_KEXEC_AUTO_RESERVE
>+#define MBYTES(n) ((n)*1024*1024ULL)
>+#define GBYTES(n) ((n)*1024*1024*1024ULL)
>+/*
>+       Memory size     Reserved memory
>+       ===========     ===============
>+       [4G, 12G)       256M
>+       [12G, 128G)     512M
>+       [128G, 256G)    768M
>+       [256G, 378G)    1024M
>+       [378G, 512G)    1536M
>+       [512G, 768G)    2048M
>+       [768G, )        3072M
>+ */
>+static inline
>+unsigned long long arch_default_crash_size(unsigned long long total_size)
>+{

This function shouldn't be inlined (Andrew commented this before). You might remove inline and add __init for this function. 

>+	unsigned long long ret;
>+
>+	if (total_size >= GBYTES(4) && total_size < GBYTES(12))
>+		ret = MBYTES(256);
>+	else if (total_size >= GBYTES(12) && total_size < GBYTES(128))
>+		ret = MBYTES(512);
>+	else if (total_size >= GBYTES(128) && total_size < GBYTES(256))
>+		ret = MBYTES(768);
>+	else if (total_size >= GBYTES(256) && total_size < GBYTES(378))
>+		ret = MBYTES(1024);
>+	else if (total_size >= GBYTES(318) && total_size < GBYTES(512))
>+		ret = MBYTES(1536);
>+	else if (total_size >= GBYTES(512) && total_size < GBYTES(768))
>+		ret = MBYTES(2048);
>+	else
>+		ret = MBYTES(3072);
>+	if (!ia64_platform_is("sn2") && !ia64_platform_is("uv"))
>+		if (ret > GBYTES(4))
>+			ret = ret / GBYTES(4) * MBYTES(256);

This code doesn't make sense to me. What you really want is following code, right?
+		if (total_size > GBYTES(4))
+			ret = total_size / GBYTES(4) * MBYTEST(256)

>+	return ret;
>+}
>+#undef GBYTES
>+#undef MBYTES
>+#define arch_default_crash_size arch_default_crash_size
>+#endif
>+
> extern struct kimage *ia64_kimage;
> extern const unsigned int relocate_new_kernel_size;
> extern void relocate_new_kernel(unsigned long, unsigned long,

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

* Re: [Patch 4/8] ia64: implement crashkernel=auto
  2009-08-27  4:19   ` Yu, Fenghua
@ 2009-08-27 10:26     ` Amerigo Wang
  2009-08-27 18:13       ` Yu, Fenghua
  0 siblings, 1 reply; 21+ messages in thread
From: Amerigo Wang @ 2009-08-27 10:26 UTC (permalink / raw)
  To: Yu, Fenghua
  Cc: 'linux-kernel@vger.kernel.org', 'Anton Vorontsov',
	Luck, Tony, 'linux-ia64@vger.kernel.org',
	'Neil Horman', 'Eric W. Biederman',
	'kamezawa.hiroyu@jp.fujitsu.com', 'Andi Kleen',
	'Michael Ellerman', 'M. Mohan Kumar',
	'akpm@linux-foundation.org',
	'bernhard.walle@gmx.de', 'Ingo Molnar'

Yu, Fenghua wrote:
>> Since in patch 2/8 we already implement the generic part, this will
>> add the rest part for ia64.
>>
>> Signed-off-by: WANG Cong <amwang@redhat.com>
>> Cc: Fenghua Yu <fenghua.yu@intel.com>
>> Cc: Tony Luck <tony.luck@intel.com>
>>
>> ---
>>
>> Index: linux-2.6/arch/ia64/include/asm/kexec.h
>> ===================================================================
>> --- linux-2.6.orig/arch/ia64/include/asm/kexec.h
>> +++ linux-2.6/arch/ia64/include/asm/kexec.h
>> @@ -1,6 +1,7 @@
>> #ifndef _ASM_IA64_KEXEC_H
>> #define _ASM_IA64_KEXEC_H
>>
>> +#include <asm-generic/kexec.h>
>>
>> /* Maximum physical address we can use pages from */
>> #define KEXEC_SOURCE_MEMORY_LIMIT (-1UL)
>> @@ -19,6 +20,49 @@
>>                 flush_icache_range(page_addr, page_addr + PAGE_SIZE); \
>>         } while(0)
>>
>> +#ifdef CONFIG_KEXEC_AUTO_RESERVE
>> +#define MBYTES(n) ((n)*1024*1024ULL)
>> +#define GBYTES(n) ((n)*1024*1024*1024ULL)
>> +/*
>> +       Memory size     Reserved memory
>> +       ===========     ===============
>> +       [4G, 12G)       256M
>> +       [12G, 128G)     512M
>> +       [128G, 256G)    768M
>> +       [256G, 378G)    1024M
>> +       [378G, 512G)    1536M
>> +       [512G, 768G)    2048M
>> +       [768G, )        3072M
>> + */
>> +static inline
>> +unsigned long long arch_default_crash_size(unsigned long long total_size)
>> +{
>>     
>
> This function shouldn't be inlined (Andrew commented this before). You might remove inline and add __init for this function. 
>
>   

Yeah, seems I missed Andrew's comment... :-/ I will update it.

>> +	unsigned long long ret;
>> +
>> +	if (total_size >= GBYTES(4) && total_size < GBYTES(12))
>> +		ret = MBYTES(256);
>> +	else if (total_size >= GBYTES(12) && total_size < GBYTES(128))
>> +		ret = MBYTES(512);
>> +	else if (total_size >= GBYTES(128) && total_size < GBYTES(256))
>> +		ret = MBYTES(768);
>> +	else if (total_size >= GBYTES(256) && total_size < GBYTES(378))
>> +		ret = MBYTES(1024);
>> +	else if (total_size >= GBYTES(318) && total_size < GBYTES(512))
>> +		ret = MBYTES(1536);
>> +	else if (total_size >= GBYTES(512) && total_size < GBYTES(768))
>> +		ret = MBYTES(2048);
>> +	else
>> +		ret = MBYTES(3072);
>> +	if (!ia64_platform_is("sn2") && !ia64_platform_is("uv"))
>> +		if (ret > GBYTES(4))
>> +			ret = ret / GBYTES(4) * MBYTES(256);
>>     
>
> This code doesn't make sense to me. What you really want is following code, right?
> +		if (total_size > GBYTES(4))
> +			ret = total_size / GBYTES(4) * MBYTEST(256)
>
>   
Nope. Check check_crashkernel_memory().

Thanks.



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

* RE: [Patch 4/8] ia64: implement crashkernel=auto
  2009-08-27 10:26     ` Amerigo Wang
@ 2009-08-27 18:13       ` Yu, Fenghua
  2009-08-28 10:04         ` Amerigo Wang
  0 siblings, 1 reply; 21+ messages in thread
From: Yu, Fenghua @ 2009-08-27 18:13 UTC (permalink / raw)
  To: 'Amerigo Wang'
  Cc: 'linux-kernel@vger.kernel.org', 'Anton Vorontsov',
	Luck, Tony, 'linux-ia64@vger.kernel.org',
	'Neil Horman', 'Eric W. Biederman',
	'kamezawa.hiroyu@jp.fujitsu.com', 'Andi Kleen',
	'Michael Ellerman', 'M. Mohan Kumar',
	'akpm@linux-foundation.org',
	'bernhard.walle@gmx.de', 'Ingo Molnar'

>>> --- linux-2.6.orig/arch/ia64/include/asm/kexec.h
>>> +++ linux-2.6/arch/ia64/include/asm/kexec.h
>>> @@ -1,6 +1,7 @@
>>> #ifndef _ASM_IA64_KEXEC_H
>>> #define _ASM_IA64_KEXEC_H
>>>
>>> +#include <asm-generic/kexec.h>
>>>
>>> /* Maximum physical address we can use pages from */
>>> #define KEXEC_SOURCE_MEMORY_LIMIT (-1UL)
>>> @@ -19,6 +20,49 @@
>>>                 flush_icache_range(page_addr, page_addr + PAGE_SIZE); \
>>>         } while(0)
>>>
>>> +#ifdef CONFIG_KEXEC_AUTO_RESERVE
>>> +#define MBYTES(n) ((n)*1024*1024ULL)
>>> +#define GBYTES(n) ((n)*1024*1024*1024ULL)
>>> +/*
>>> +       Memory size     Reserved memory
>>> +       ===========     ===============
>>> +       [4G, 12G)       256M
>>> +       [12G, 128G)     512M
>>> +       [128G, 256G)    768M
>>> +       [256G, 378G)    1024M
>>> +       [378G, 512G)    1536M
>>> +       [512G, 768G)    2048M
>>> +       [768G, )        3072M
>>> + */
>>> +static inline
>>> +unsigned long long arch_default_crash_size(unsigned long long
>total_size)
>>> +{
>>>
>>
>> This function shouldn't be inlined (Andrew commented this before). You
>might remove inline and add __init for this function.
>>
>>
>
>Yeah, seems I missed Andrew's comment... :-/ I will update it.
>
>>> +	unsigned long long ret;
>>> +
>>> +	if (total_size >= GBYTES(4) && total_size < GBYTES(12))
>>> +		ret = MBYTES(256);
>>> +	else if (total_size >= GBYTES(12) && total_size < GBYTES(128))
>>> +		ret = MBYTES(512);
>>> +	else if (total_size >= GBYTES(128) && total_size < GBYTES(256))
>>> +		ret = MBYTES(768);
>>> +	else if (total_size >= GBYTES(256) && total_size < GBYTES(378))
>>> +		ret = MBYTES(1024);
>>> +	else if (total_size >= GBYTES(318) && total_size < GBYTES(512))
>>> +		ret = MBYTES(1536);
>>> +	else if (total_size >= GBYTES(512) && total_size < GBYTES(768))
>>> +		ret = MBYTES(2048);
>>> +	else
>>> +		ret = MBYTES(3072);
>>> +	if (!ia64_platform_is("sn2") && !ia64_platform_is("uv"))
>>> +		if (ret > GBYTES(4))
>>> +			ret = ret / GBYTES(4) * MBYTES(256);
>>>
>>
>> This code doesn't make sense to me. What you really want is following
>code, right?
>> +		if (total_size > GBYTES(4))
>> +			ret = total_size / GBYTES(4) * MBYTEST(256)
>>
>>
>Nope. Check check_crashkernel_memory().

This statement will be ALWAYS false:
+		if (ret > GBYTES(4))
since ret's max value is 3GB after the above total_size checks.

So the code doesn't make sense. Did I miss something?

Thanks.

-Fenghua

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

* RE: [Patch 6/8] powerpc: implement crashkernel=auto
  2009-08-27  3:16 ` [Patch 6/8] powerpc: implement crashkernel=auto Amerigo Wang
@ 2009-08-27 18:22   ` Yu, Fenghua
  0 siblings, 0 replies; 21+ messages in thread
From: Yu, Fenghua @ 2009-08-27 18:22 UTC (permalink / raw)
  To: 'Amerigo Wang', 'linux-kernel@vger.kernel.org'
  Cc: Luck, Tony, 'linux-ia64@vger.kernel.org',
	'Neil Horman', 'Eric W. Biederman',
	'kamezawa.hiroyu@jp.fujitsu.com', 'Andi Kleen',
	'Michael Ellerman', 'M. Mohan Kumar',
	'akpm@linux-foundation.org',
	'bernhard.walle@gmx.de', 'Ingo Molnar',
	'Anton Vorontsov'

>--- linux-2.6.orig/arch/powerpc/include/asm/kexec.h
>+++ linux-2.6/arch/powerpc/include/asm/kexec.h
>@@ -39,6 +39,45 @@ typedef void (*crash_shutdown_t)(void);
>
> #ifdef CONFIG_KEXEC
>
>+#ifdef CONFIG_KEXEC_AUTO_RESERVE
>+
>+#ifndef KEXEC_AUTO_THRESHOLD
>+#define KEXEC_AUTO_THRESHOLD (1ULL<<31) /* 2G */
>+#endif
>+
>+#ifndef arch_default_crash_base
>+static inline
>+unsigned long long arch_default_crash_base(void)
>+{
>+	return KDUMP_KERNELBASE;
>+}
You don't want inline here either.

>+#define arch_default_crash_base arch_default_crash_base
>+#endif
>+
>+#ifndef arch_default_crash_size
>+static inline
>+unsigned long long arch_default_crash_size(unsigned long long total_size)
>+{

Ditto.

>+	if (total_size < KEXEC_AUTO_THRESHOLD)
>+		return 0;
>+	if (total_size < (1ULL<<32))
>+		return 1ULL<<27;
>+	else {
>+#ifdef CONFIG_64BIT
>+		if (total_size > (1ULL<<37)) /* 128G */
>+			return 1ULL<<32; /* 4G */
>+		return 1ULL<<ilog2(roundup(total_size/32, 1ULL<<21));
>+#else
>+		return 1ULL<<28;
>+#endif
>+	}
>+}
>+#define arch_default_crash_size arch_default_crash_size
>+#endif
>+
>+#endif
>+#include <asm-generic/kexec.h>
>+
> /*
>  * This function is responsible for capturing register states if coming
>  * via panic or invoking dump using sysrq-trigger.

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

* Re: [Patch 4/8] ia64: implement crashkernel=auto
  2009-08-27 18:13       ` Yu, Fenghua
@ 2009-08-28 10:04         ` Amerigo Wang
  2009-08-28 20:08           ` Yu, Fenghua
  0 siblings, 1 reply; 21+ messages in thread
From: Amerigo Wang @ 2009-08-28 10:04 UTC (permalink / raw)
  To: Yu, Fenghua
  Cc: 'linux-kernel@vger.kernel.org', 'Anton Vorontsov',
	Luck, Tony, 'linux-ia64@vger.kernel.org',
	'Neil Horman', 'Eric W. Biederman',
	'kamezawa.hiroyu@jp.fujitsu.com', 'Andi Kleen',
	'Michael Ellerman', 'M. Mohan Kumar',
	'akpm@linux-foundation.org',
	'bernhard.walle@gmx.de', 'Ingo Molnar'

Yu, Fenghua wrote:
>>>> +	unsigned long long ret;
>>>> +
>>>> +	if (total_size >= GBYTES(4) && total_size < GBYTES(12))
>>>> +		ret = MBYTES(256);
>>>> +	else if (total_size >= GBYTES(12) && total_size < GBYTES(128))
>>>> +		ret = MBYTES(512);
>>>> +	else if (total_size >= GBYTES(128) && total_size < GBYTES(256))
>>>> +		ret = MBYTES(768);
>>>> +	else if (total_size >= GBYTES(256) && total_size < GBYTES(378))
>>>> +		ret = MBYTES(1024);
>>>> +	else if (total_size >= GBYTES(318) && total_size < GBYTES(512))
>>>> +		ret = MBYTES(1536);
>>>> +	else if (total_size >= GBYTES(512) && total_size < GBYTES(768))
>>>> +		ret = MBYTES(2048);
>>>> +	else
>>>> +		ret = MBYTES(3072);
>>>> +	if (!ia64_platform_is("sn2") && !ia64_platform_is("uv"))
>>>> +		if (ret > GBYTES(4))
>>>> +			ret = ret / GBYTES(4) * MBYTES(256);
>>>>
>>>>         
>>> This code doesn't make sense to me. What you really want is following
>>>       
>> code, right?
>>     
>>> +		if (total_size > GBYTES(4))
>>> +			ret = total_size / GBYTES(4) * MBYTEST(256)
>>>
>>>
>>>       
>> Nope. Check check_crashkernel_memory().
>>     
>
> This statement will be ALWAYS false:
> +		if (ret > GBYTES(4))
> since ret's max value is 3GB after the above total_size checks.
>
> So the code doesn't make sense. Did I miss something?
>   

Oops, in fact it was supposed to be:

  if (ret + base > GBYTES(4))
    //blah blah

Hmm, but is it possible for ia64 to choose a base address above 1G? If 
no, that code can be removed.

Thanks!




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

* RE: [Patch 4/8] ia64: implement crashkernel=auto
  2009-08-28 10:04         ` Amerigo Wang
@ 2009-08-28 20:08           ` Yu, Fenghua
  0 siblings, 0 replies; 21+ messages in thread
From: Yu, Fenghua @ 2009-08-28 20:08 UTC (permalink / raw)
  To: 'Amerigo Wang'
  Cc: 'linux-kernel@vger.kernel.org', 'Anton Vorontsov',
	Luck, Tony, 'linux-ia64@vger.kernel.org',
	'Neil Horman', 'Eric W. Biederman',
	'kamezawa.hiroyu@jp.fujitsu.com', 'Andi Kleen',
	'Michael Ellerman', 'M. Mohan Kumar',
	'akpm@linux-foundation.org',
	'bernhard.walle@gmx.de', 'Ingo Molnar'

>>>>> +	unsigned long long ret;
>>>>> +
>>>>> +	if (total_size >= GBYTES(4) && total_size < GBYTES(12))
>>>>> +		ret = MBYTES(256);
>>>>> +	else if (total_size >= GBYTES(12) && total_size < GBYTES(128))
>>>>> +		ret = MBYTES(512);
>>>>> +	else if (total_size >= GBYTES(128) && total_size < GBYTES(256))
>>>>> +		ret = MBYTES(768);
>>>>> +	else if (total_size >= GBYTES(256) && total_size < GBYTES(378))
>>>>> +		ret = MBYTES(1024);
>>>>> +	else if (total_size >= GBYTES(318) && total_size < GBYTES(512))
>>>>> +		ret = MBYTES(1536);
>>>>> +	else if (total_size >= GBYTES(512) && total_size < GBYTES(768))
>>>>> +		ret = MBYTES(2048);
>>>>> +	else
>>>>> +		ret = MBYTES(3072);
>>>>> +	if (!ia64_platform_is("sn2") && !ia64_platform_is("uv"))
>>>>> +		if (ret > GBYTES(4))
>>>>> +			ret = ret / GBYTES(4) * MBYTES(256);
>>>>>
>>>>>
>>>> This code doesn't make sense to me. What you really want is following
>>>>
>>> code, right?
>>>
>>>> +		if (total_size > GBYTES(4))
>>>> +			ret = total_size / GBYTES(4) * MBYTEST(256)
>>>>
>>>>
>>>>
>>> Nope. Check check_crashkernel_memory().
>>>
>>
>> This statement will be ALWAYS false:
>> +		if (ret > GBYTES(4))
>> since ret's max value is 3GB after the above total_size checks.
>>
>> So the code doesn't make sense. Did I miss something?
>>
>
>Oops, in fact it was supposed to be:
>
>  if (ret + base > GBYTES(4))
>    //blah blah
>
>Hmm, but is it possible for ia64 to choose a base address above 1G? If
>no, that code can be removed.

I think you don't need to consider the base here. This arch_default_crash_size() only returns size. Later on, ia64 setup_crashkernel() will find a base value in reserved region and check if the base value is under 4GB etc.

Thanks.

-Fenghua

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

* Re: [Patch 0/8] V5 Implement crashkernel=auto
  2009-08-27  3:15 [Patch 0/8] V5 Implement crashkernel=auto Amerigo Wang
                   ` (7 preceding siblings ...)
  2009-08-27  3:17 ` [Patch 8/8] kexec: allow to shrink reserved memory Amerigo Wang
@ 2009-08-31  0:54 ` Michael Ellerman
  2009-08-31  3:03   ` Eric W. Biederman
  2009-08-31  3:27   ` Amerigo Wang
  8 siblings, 2 replies; 21+ messages in thread
From: Michael Ellerman @ 2009-08-31  0:54 UTC (permalink / raw)
  To: Amerigo Wang
  Cc: linux-kernel, tony.luck, linux-ia64, Neil Horman,
	Eric W. Biederman, kamezawa.hiroyu, Andi Kleen, M. Mohan Kumar,
	akpm, bernhard.walle, Fenghua Yu, Ingo Molnar, Anton Vorontsov

[-- Attachment #1: Type: text/plain, Size: 2171 bytes --]

On Wed, 2009-08-26 at 23:15 -0400, Amerigo Wang wrote:
> V4 -> V5:
>  - Rename the global functions, as suggested by Andrew.
>  - Save some macros, as suggested by Andrew.
>  - Change the high threshold, from 32G to 4G.
>  - Change the low threshold on ppc, suggested by ppc developers.
>  - Make the mm part as a seperate function, suggest by Eric.
>  - Make the IA64 code more readable.
>  - Reorder the patchset again, since review from mm people is done.
> 
> V3 -> V4:
>  - Reorder the patches.
>  - Really free the reserved memory, instead of remapping it.
>    (Thanks to KAMEZAWA Hiroyuki!)
>  - Release the reserved memory resource when the size is 0.
>  - Use strict_strtoul() instead of simple_strtoul().
> 
> V2 -> V3:
>  - Use more clever way to calculate reserved memory size, especially for IA64.
>  - Add that patch that implements shrinking reserved memory
> 
> V1 -> V2:
>  - Use include/asm-generic/kexec.h, suggested by Neil.
>  - Rename a local variable, suggested by Fenghua.
>  - Fix some style problems found by checkpatch.pl.
>  - Unify the Kconfig docs.
> 
> This series of patch implements automatically reserved memory for crashkernel,
> by introducing a new boot option "crashkernel=auto". This idea is from Neil.
> 
> In case of breaking user-space applications, it modifies this boot option after
> it decides how much memory should be reserved.
> 
> On different arch, the threshold and reserved memory size is different. Please
> refer patch 7/8 which contains an update for the documentation.
> 
> Patch 8/8 implements shrinking reserved memory at run-time, which is useful
> when more than enough memory is reserved automatically.
> 
> This patchset _is_ already tested on x86_64, IA64 and ppc64.

I don't want to sound like a micro-kernel zealot, I'm not, but I'm still
unconvinced as to why the auto logic needs to go in the kernel. What is
the compelling reason that the kernel needs to do this calculation vs
some userspace tool? We already have the syntax that allows defining a
different crash size depending on the size of RAM.

The shrinking of reserved memory is cool.

cheers

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

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

* Re: [Patch 0/8] V5 Implement crashkernel=auto
  2009-08-31  0:54 ` [Patch 0/8] V5 Implement crashkernel=auto Michael Ellerman
@ 2009-08-31  3:03   ` Eric W. Biederman
  2009-08-31  3:25     ` Amerigo Wang
  2009-08-31  3:27   ` Amerigo Wang
  1 sibling, 1 reply; 21+ messages in thread
From: Eric W. Biederman @ 2009-08-31  3:03 UTC (permalink / raw)
  To: michael
  Cc: Amerigo Wang, linux-kernel, tony.luck, linux-ia64, Neil Horman,
	kamezawa.hiroyu, Andi Kleen, M. Mohan Kumar, akpm, bernhard.walle,
	Fenghua Yu, Ingo Molnar, Anton Vorontsov

Michael Ellerman <michael@ellerman.id.au> writes:

> On Wed, 2009-08-26 at 23:15 -0400, Amerigo Wang wrote:
>> V4 -> V5:
>>  - Rename the global functions, as suggested by Andrew.
>>  - Save some macros, as suggested by Andrew.
>>  - Change the high threshold, from 32G to 4G.
>>  - Change the low threshold on ppc, suggested by ppc developers.
>>  - Make the mm part as a seperate function, suggest by Eric.
>>  - Make the IA64 code more readable.
>>  - Reorder the patchset again, since review from mm people is done.
>> 
>> V3 -> V4:
>>  - Reorder the patches.
>>  - Really free the reserved memory, instead of remapping it.
>>    (Thanks to KAMEZAWA Hiroyuki!)
>>  - Release the reserved memory resource when the size is 0.
>>  - Use strict_strtoul() instead of simple_strtoul().
>> 
>> V2 -> V3:
>>  - Use more clever way to calculate reserved memory size, especially for IA64.
>>  - Add that patch that implements shrinking reserved memory
>> 
>> V1 -> V2:
>>  - Use include/asm-generic/kexec.h, suggested by Neil.
>>  - Rename a local variable, suggested by Fenghua.
>>  - Fix some style problems found by checkpatch.pl.
>>  - Unify the Kconfig docs.
>> 
>> This series of patch implements automatically reserved memory for crashkernel,
>> by introducing a new boot option "crashkernel=auto". This idea is from Neil.
>> 
>> In case of breaking user-space applications, it modifies this boot option after
>> it decides how much memory should be reserved.
>> 
>> On different arch, the threshold and reserved memory size is different. Please
>> refer patch 7/8 which contains an update for the documentation.
>> 
>> Patch 8/8 implements shrinking reserved memory at run-time, which is useful
>> when more than enough memory is reserved automatically.
>> 
>> This patchset _is_ already tested on x86_64, IA64 and ppc64.
>
> I don't want to sound like a micro-kernel zealot, I'm not, but I'm still
> unconvinced as to why the auto logic needs to go in the kernel. What is
> the compelling reason that the kernel needs to do this calculation vs
> some userspace tool? We already have the syntax that allows defining a
> different crash size depending on the size of RAM.
>
> The shrinking of reserved memory is cool.

Michael I am in agreement with you.
The shrinking is good.

If we can come up with some simple and generic logic that we can use
to reserve memory then I am in favor.  However all this patchset is
doing is moving user space specific arbitrary hacks into the kernel we
do that perfectly well on the command line.  Having the amount to
reserve be arch specific is complete non-sense and a major maintenance
pain.

Eric


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

* Re: [Patch 0/8] V5 Implement crashkernel=auto
  2009-08-31  3:03   ` Eric W. Biederman
@ 2009-08-31  3:25     ` Amerigo Wang
  0 siblings, 0 replies; 21+ messages in thread
From: Amerigo Wang @ 2009-08-31  3:25 UTC (permalink / raw)
  To: Eric W. Biederman
  Cc: michael, linux-kernel, tony.luck, linux-ia64, Neil Horman,
	kamezawa.hiroyu, Andi Kleen, M. Mohan Kumar, akpm, bernhard.walle,
	Fenghua Yu, Ingo Molnar, Anton Vorontsov

Eric W. Biederman wrote:
> Michael Ellerman <michael@ellerman.id.au> writes:
>
>   
>> On Wed, 2009-08-26 at 23:15 -0400, Amerigo Wang wrote:
>>     
>>> V4 -> V5:
>>>  - Rename the global functions, as suggested by Andrew.
>>>  - Save some macros, as suggested by Andrew.
>>>  - Change the high threshold, from 32G to 4G.
>>>  - Change the low threshold on ppc, suggested by ppc developers.
>>>  - Make the mm part as a seperate function, suggest by Eric.
>>>  - Make the IA64 code more readable.
>>>  - Reorder the patchset again, since review from mm people is done.
>>>
>>> V3 -> V4:
>>>  - Reorder the patches.
>>>  - Really free the reserved memory, instead of remapping it.
>>>    (Thanks to KAMEZAWA Hiroyuki!)
>>>  - Release the reserved memory resource when the size is 0.
>>>  - Use strict_strtoul() instead of simple_strtoul().
>>>
>>> V2 -> V3:
>>>  - Use more clever way to calculate reserved memory size, especially for IA64.
>>>  - Add that patch that implements shrinking reserved memory
>>>
>>> V1 -> V2:
>>>  - Use include/asm-generic/kexec.h, suggested by Neil.
>>>  - Rename a local variable, suggested by Fenghua.
>>>  - Fix some style problems found by checkpatch.pl.
>>>  - Unify the Kconfig docs.
>>>
>>> This series of patch implements automatically reserved memory for crashkernel,
>>> by introducing a new boot option "crashkernel=auto". This idea is from Neil.
>>>
>>> In case of breaking user-space applications, it modifies this boot option after
>>> it decides how much memory should be reserved.
>>>
>>> On different arch, the threshold and reserved memory size is different. Please
>>> refer patch 7/8 which contains an update for the documentation.
>>>
>>> Patch 8/8 implements shrinking reserved memory at run-time, which is useful
>>> when more than enough memory is reserved automatically.
>>>
>>> This patchset _is_ already tested on x86_64, IA64 and ppc64.
>>>       
>> I don't want to sound like a micro-kernel zealot, I'm not, but I'm still
>> unconvinced as to why the auto logic needs to go in the kernel. What is
>> the compelling reason that the kernel needs to do this calculation vs
>> some userspace tool? We already have the syntax that allows defining a
>> different crash size depending on the size of RAM.
>>
>> The shrinking of reserved memory is cool.
>>     
>
> Michael I am in agreement with you.
> The shrinking is good.
>
> If we can come up with some simple and generic logic that we can use
> to reserve memory then I am in favor.  However all this patchset is
> doing is moving user space specific arbitrary hacks into the kernel we
> do that perfectly well on the command line.  Having the amount to
> reserve be arch specific is complete non-sense and a major maintenance
> pain.
>   

Ok, since you guys think we should not do sth in kernel space if we can 
do it in user space, why not removing the extended crash kernel syntax??

E.g.
crashkernel=512M-2G:64M,2G-:128M

I am *quite* sure this can be done in user space too. In theory, only 
you need is just:

crashkernel=X@Y

all the rest things can be done in user space. Enjoy!


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

* Re: [Patch 0/8] V5 Implement crashkernel=auto
  2009-08-31  0:54 ` [Patch 0/8] V5 Implement crashkernel=auto Michael Ellerman
  2009-08-31  3:03   ` Eric W. Biederman
@ 2009-08-31  3:27   ` Amerigo Wang
  1 sibling, 0 replies; 21+ messages in thread
From: Amerigo Wang @ 2009-08-31  3:27 UTC (permalink / raw)
  To: michael
  Cc: linux-kernel, tony.luck, linux-ia64, Neil Horman,
	Eric W. Biederman, kamezawa.hiroyu, Andi Kleen, M. Mohan Kumar,
	akpm, bernhard.walle, Fenghua Yu, Ingo Molnar, Anton Vorontsov

Michael Ellerman wrote:
> On Wed, 2009-08-26 at 23:15 -0400, Amerigo Wang wrote:
>   
>> V4 -> V5:
>>  - Rename the global functions, as suggested by Andrew.
>>  - Save some macros, as suggested by Andrew.
>>  - Change the high threshold, from 32G to 4G.
>>  - Change the low threshold on ppc, suggested by ppc developers.
>>  - Make the mm part as a seperate function, suggest by Eric.
>>  - Make the IA64 code more readable.
>>  - Reorder the patchset again, since review from mm people is done.
>>
>> V3 -> V4:
>>  - Reorder the patches.
>>  - Really free the reserved memory, instead of remapping it.
>>    (Thanks to KAMEZAWA Hiroyuki!)
>>  - Release the reserved memory resource when the size is 0.
>>  - Use strict_strtoul() instead of simple_strtoul().
>>
>> V2 -> V3:
>>  - Use more clever way to calculate reserved memory size, especially for IA64.
>>  - Add that patch that implements shrinking reserved memory
>>
>> V1 -> V2:
>>  - Use include/asm-generic/kexec.h, suggested by Neil.
>>  - Rename a local variable, suggested by Fenghua.
>>  - Fix some style problems found by checkpatch.pl.
>>  - Unify the Kconfig docs.
>>
>> This series of patch implements automatically reserved memory for crashkernel,
>> by introducing a new boot option "crashkernel=auto". This idea is from Neil.
>>
>> In case of breaking user-space applications, it modifies this boot option after
>> it decides how much memory should be reserved.
>>
>> On different arch, the threshold and reserved memory size is different. Please
>> refer patch 7/8 which contains an update for the documentation.
>>
>> Patch 8/8 implements shrinking reserved memory at run-time, which is useful
>> when more than enough memory is reserved automatically.
>>
>> This patchset _is_ already tested on x86_64, IA64 and ppc64.
>>     
>
> I don't want to sound like a micro-kernel zealot, I'm not, but I'm still
> unconvinced as to why the auto logic needs to go in the kernel. What is
> the compelling reason that the kernel needs to do this calculation vs
> some userspace tool? We already have the syntax that allows defining a
> different crash size depending on the size of RAM.
>   

Take a look at the x86 part, it can not be done _directly_ in kernel 
command line with the syntax.


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

* [Patch 3/8] ia64: add CONFIG_KEXEC_AUTO_RESERVE
  2009-09-04 10:08 [Patch 0/8] V6 " Amerigo Wang
@ 2009-09-04 10:08 ` Amerigo Wang
  0 siblings, 0 replies; 21+ messages in thread
From: Amerigo Wang @ 2009-09-04 10:08 UTC (permalink / raw)
  To: linux-kernel
  Cc: tony.luck, linux-ia64, Neil Horman, Eric W. Biederman, Andi Kleen,
	Ingo Molnar, Michael Ellerman, Amerigo Wang, M. Mohan Kumar, akpm,
	bernhard.walle, Fenghua Yu, kamezawa.hiroyu, Anton Vorontsov


Introduce a new config option KEXEC_AUTO_RESERVE for ia64.

Signed-off-by: WANG Cong <amwang@redhat.com>
Acked-by: Neil Horman <nhorman@tuxdriver.com>

---

Index: linux-2.6/arch/ia64/Kconfig
===================================================================
--- linux-2.6.orig/arch/ia64/Kconfig
+++ linux-2.6/arch/ia64/Kconfig
@@ -582,6 +582,20 @@ config KEXEC
 	  support.  As of this writing the exact hardware interface is
 	  strongly in flux, so no good recommendation can be made.
 
+config KEXEC_AUTO_RESERVE
+	bool "automatically reserve memory for kexec kernel"
+	depends on KEXEC
+	default y
+	---help---
+	  Automatically reserve memory for a kexec kernel, so that you don't
+	  need to specify numbers for the "crashkernel=X@Y" boot option,
+	  instead you can use "crashkernel=auto". To make this work, you need
+	  to have more than 4G memory.
+
+	  The reserved memory size is different depends on how much memory
+	  you actually have. Please check Documentation/kdump/kdump.txt.
+	  If you doubt, say N.
+
 config CRASH_DUMP
 	  bool "kernel crash dumps"
 	  depends on IA64_MCA_RECOVERY && !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)

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

end of thread, other threads:[~2009-09-04 10:10 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-27  3:15 [Patch 0/8] V5 Implement crashkernel=auto Amerigo Wang
2009-08-27  3:15 ` [Patch 1/8] x86: add CONFIG_KEXEC_AUTO_RESERVE Amerigo Wang
2009-08-27  3:15 ` [Patch 2/8] x86: implement crashkernel=auto Amerigo Wang
2009-08-27  3:16 ` [Patch 3/8] ia64: add CONFIG_KEXEC_AUTO_RESERVE Amerigo Wang
2009-08-27  3:16 ` [Patch 4/8] ia64: implement crashkernel=auto Amerigo Wang
2009-08-27  4:19   ` Yu, Fenghua
2009-08-27 10:26     ` Amerigo Wang
2009-08-27 18:13       ` Yu, Fenghua
2009-08-28 10:04         ` Amerigo Wang
2009-08-28 20:08           ` Yu, Fenghua
2009-08-27  3:16 ` [Patch 5/8] powerpc: add CONFIG_KEXEC_AUTO_RESERVE Amerigo Wang
2009-08-27  3:16 ` [Patch 6/8] powerpc: implement crashkernel=auto Amerigo Wang
2009-08-27 18:22   ` Yu, Fenghua
2009-08-27  3:16 ` [Patch 7/8] doc: update the kdump document Amerigo Wang
2009-08-27  3:17 ` [Patch 8/8] kexec: allow to shrink reserved memory Amerigo Wang
2009-08-31  0:54 ` [Patch 0/8] V5 Implement crashkernel=auto Michael Ellerman
2009-08-31  3:03   ` Eric W. Biederman
2009-08-31  3:25     ` Amerigo Wang
2009-08-31  3:27   ` Amerigo Wang
  -- strict thread matches above, loose matches on Subject: below --
2009-09-04 10:08 [Patch 0/8] V6 " Amerigo Wang
2009-09-04 10:08 ` [Patch 3/8] ia64: add CONFIG_KEXEC_AUTO_RESERVE Amerigo Wang
2009-08-12  8:15 [Patch 0/8] V3 Implement crashkernel=auto Amerigo Wang
2009-08-12  8:15 ` [Patch 3/8] ia64: add CONFIG_KEXEC_AUTO_RESERVE Amerigo Wang

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