linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [RFC 0/4] Kexec: Enable run time memory resrvation of crash kernel
@ 2016-08-12 14:18 Ronit Halder
  2016-08-12 14:20 ` [RFC 1/4] Creating one or two CMA area at Boot time Ronit Halder
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Ronit Halder @ 2016-08-12 14:18 UTC (permalink / raw)
  To: linux-kernel
  Cc: tglx, mingo, hpa, bp, dyoung, jroedel, krzysiek, msalter,
	ebiederm, akpm, bhe, vgoyal, mnfhuang, kexec, kirill.shutemov,
	mchehab, aarcange, vdavydov, dan.j.williams, jack, linux-mm,
	Ronit Halder

Currenty linux kernel reserves memory at the boot time for crash kernel.
It will be very useful if we can reserve memory in run time. The user can 
reserve the memory whenerver needed instead of reserving at the boot time.

It is possible to reserve memory for crash kernel at the run time using
CMA (Contiguous Memory Allocator). CMA is capable of allocating big chunk 
of memory. At the boot time we will create one (if only low memory is used)
or two (if we use both high memory in case of x86_64) CMA areas of size 
given in "crashkernel" boot time command line parameter. This memory in CMA
areas can be used as movable pages (used for disk caches, process pages
etc) if not allocated. Then the user can reserve or free memory from those
CMA areas using "/sys/kernel/kexec_crash_size" sysfs entry. If the user
uses high memory it will automatically at least 256MB low memory
(needed for swiotlb and DMA buffers) when the user allocates memory using
mentioned sysfs enrty. In case of high memory reservation the user controls
the size of reserved region in high memory with
"/sys/kernel/kexec_crash_size" entry. If the size set is zero then the 
memory allocated in low memory will automatically be freed.

As the pages under CMA area (when not allocated by CMA) can only be used by
movable pages. The pages won't be used for DMA. So, after allocating pages
from CMA area for loading the crash kernel, there won't be any chance of
DMA on the memory.

Thus is a prototype patch. Please share your opinions on my approach. This
patch is only for x86 and x86_64. Please note, this patch is only a
prototype just to explain my approach and get the review. This patch is on
kernel version v4.4.11.

CMA depends on page migration and only uses movable pages. But, the movable
pages become unmovable momentarily for pinning. The CMA fails for this
reason. I don't have any solution for that right now. This approach will
work when the this problems with CMA will be fixed. The patch is enabled
by a kernel configuration option CONFIG_KEXEC_CMA.

Ronit Halder (4):
  Creating one or two CMA area at Boot time
  Functions for memory reservation and release
  Adding a new kernel configuration to enable the feature
  Enable memory allocation through sysfs interface

 arch/x86/kernel/setup.c | 44 ++++++++++++++++++++++++--
 include/linux/kexec.h   | 11 ++++++-
 kernel/kexec_core.c     | 83 +++++++++++++++++++++++++++++++++++++++++++++++++
 kernel/ksysfs.c         | 23 +++++++++++++-
 mm/Kconfig              |  6 ++++
 5 files changed, 162 insertions(+), 5 deletions(-)

-- 
2.9.0.GIT

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* [RFC 1/4] Creating one or two CMA area at Boot time
  2016-08-12 14:18 [RFC 0/4] Kexec: Enable run time memory resrvation of crash kernel Ronit Halder
@ 2016-08-12 14:20 ` Ronit Halder
  2016-08-12 14:21 ` [RFC 2/4] Functions for memory reservation and release Ronit Halder
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Ronit Halder @ 2016-08-12 14:20 UTC (permalink / raw)
  To: linux-kernel
  Cc: tglx, mingo, hpa, bp, dyoung, jroedel, krzysiek, msalter,
	ebiederm, akpm, bhe, vgoyal, mnfhuang, kexec, kirill.shutemov,
	mchehab, aarcange, vdavydov, dan.j.williams, jack, linux-mm,
	Ronit Halder

This patch create CMA area(s) at boot time. In case of x86_32
only one CMA area will be created. In case of x86_64 if the
user wants to reserve high memory for crash kernel, then there
must be at least 256MB (needed for swiotlb and DMA buffers)
low memory. In that case two CMA areas (one in low memory and
one in high memory) will be created.

Signed-off-by: Ronit Halder <ronit.crj@gmail.com>

---
 arch/x86/kernel/setup.c | 44 +++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 41 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index d2bbe34..87c16c7 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -69,6 +69,7 @@
 #include <linux/crash_dump.h>
 #include <linux/tboot.h>
 #include <linux/jiffies.h>
+#include <linux/cma.h>
 
 #include <video/edid.h>
 
@@ -123,6 +124,10 @@
 unsigned long max_low_pfn_mapped;
 unsigned long max_pfn_mapped;
 
+#ifdef CONFIG_KEXEC_CMA
+struct cma *crashk_cma;
+struct cma *crashk_cma_low;
+#endif
 #ifdef CONFIG_DMI
 RESERVE_BRK(dmi_alloc, 65536);
 #endif
@@ -532,6 +537,18 @@ static int __init reserve_crashkernel_low(void)
 		return -ENOMEM;
 	}
 
+#ifdef CONFIG_KEXEC_CMA
+	ret =  cma_declare_contiguous(low_base, low_size, 0, CRASH_ALIGN, 0, 1, &crashk_cma_low);
+	if (ret) {
+		pr_err("%s: Error reserving CMA area for crashkernel low.\n", __func__);
+		return ret;
+	}
+
+	pr_info("Reserving %ldMB of low memory at %ldMB for CMA area for crashkernel low(System low RAM: %ldMB)\n",
+		(unsigned long)(low_size >> 20),
+		(unsigned long)(low_base >> 20),
+		(unsigned long)(total_low_mem >> 20));
+#else
 	ret = memblock_reserve(low_base, low_size);
 	if (ret) {
 		pr_err("%s: Error reserving crashkernel low memblock.\n", __func__);
@@ -547,6 +564,7 @@ static int __init reserve_crashkernel_low(void)
 	crashk_low_res.end   = low_base + low_size - 1;
 	insert_resource(&iomem_resource, &crashk_low_res);
 #endif
+#endif
 	return 0;
 }
 
@@ -578,8 +596,10 @@ static void __init reserve_crashkernel(void)
 						    high ? CRASH_ADDR_HIGH_MAX
 							 : CRASH_ADDR_LOW_MAX,
 						    crash_size, CRASH_ALIGN);
+		pr_info("Crash_base %llu crash_size %llu\n", crash_base, crash_size);
+
 		if (!crash_base) {
-			pr_info("crashkernel reservation failed - No suitable area found.\n");
+			pr_info("Crashkernel reservation failed - No suitable area found.\n");
 			return;
 		}
 
@@ -589,11 +609,28 @@ static void __init reserve_crashkernel(void)
 		start = memblock_find_in_range(crash_base,
 					       crash_base + crash_size,
 					       crash_size, 1 << 20);
+		pr_info("Base_mentioned crash_base %llu crash_size %llu\n", crash_base, crash_size);
 		if (start != crash_base) {
 			pr_info("crashkernel reservation failed - memory is in use.\n");
 			return;
 		}
 	}
+#ifdef CONFIG_KEXEC_CMA
+	crashk_cma = NULL;
+	crashk_cma_low = NULL;
+	if (crash_base >= (1ULL << 32) && reserve_crashkernel_low())
+		return;
+	ret =  cma_declare_contiguous(crash_base, crash_size, 0, CRASH_ALIGN, 0, 1, &crashk_cma);
+	if (ret) {
+		pr_err("%s: Error reserving CMA area for crashkernel.\n", __func__);
+		return;
+	}
+
+	pr_info("Reserving %ldMB of memory at %ldMB for crashkernel (System RAM: %ldMB)\n",
+		(unsigned long)(crash_size >> 20),
+		(unsigned long)(crash_base >> 20),
+		(unsigned long)(total_mem >> 20));
+#else
 	ret = memblock_reserve(crash_base, crash_size);
 	if (ret) {
 		pr_err("%s: Error reserving crashkernel memblock.\n", __func__);
@@ -613,6 +650,7 @@ static void __init reserve_crashkernel(void)
 	crashk_res.start = crash_base;
 	crashk_res.end   = crash_base + crash_size - 1;
 	insert_resource(&iomem_resource, &crashk_res);
+#endif
 }
 #else
 static void __init reserve_crashkernel(void)
@@ -720,7 +758,7 @@ static void __init trim_snb_memory(void)
 	 * already been reserved.
 	 */
 	memblock_reserve(0, 1<<20);
-	
+
 	for (i = 0; i < ARRAY_SIZE(bad_pages); i++) {
 		if (memblock_reserve(bad_pages[i], PAGE_SIZE))
 			printk(KERN_WARNING "failed to reserve 0x%08lx\n",
@@ -812,7 +850,7 @@ static void __init trim_low_memory_range(void)
 {
 	memblock_reserve(0, ALIGN(reserve_low, PAGE_SIZE));
 }
-	
+
 /*
  * Dump out kernel offset information on panic.
  */
-- 
2.9.0.GIT

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* [RFC 2/4] Functions for memory reservation and release
  2016-08-12 14:18 [RFC 0/4] Kexec: Enable run time memory resrvation of crash kernel Ronit Halder
  2016-08-12 14:20 ` [RFC 1/4] Creating one or two CMA area at Boot time Ronit Halder
@ 2016-08-12 14:21 ` Ronit Halder
  2016-08-12 14:25 ` [RFC 3/4] Adding a new kernel configuration to enable the feature Ronit Halder
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Ronit Halder @ 2016-08-12 14:21 UTC (permalink / raw)
  To: linux-kernel
  Cc: tglx, mingo, hpa, bp, dyoung, jroedel, krzysiek, msalter,
	ebiederm, akpm, bhe, vgoyal, mnfhuang, kexec, kirill.shutemov,
	mchehab, aarcange, vdavydov, dan.j.williams, jack, linux-mm,
	Ronit Halder

Functions reserve and release memory from CMA area(s).

Signed-off-by: Ronit Halder <ronit.crj@gmail.com>

---
 include/linux/kexec.h | 11 ++++++-
 kernel/kexec_core.c   | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 93 insertions(+), 1 deletion(-)

diff --git a/include/linux/kexec.h b/include/linux/kexec.h
index d140b1e..9a1af44 100644
--- a/include/linux/kexec.h
+++ b/include/linux/kexec.h
@@ -307,7 +307,6 @@ extern size_t vmcoreinfo_max_size;
 
 /* flag to track if kexec reboot is in progress */
 extern bool kexec_in_progress;
-
 int __init parse_crashkernel(char *cmdline, unsigned long long system_ram,
 		unsigned long long *crash_size, unsigned long long *crash_base);
 int parse_crashkernel_high(char *cmdline, unsigned long long system_ram,
@@ -318,6 +317,16 @@ int crash_shrink_memory(unsigned long new_size);
 size_t crash_get_memory_size(void);
 void crash_free_reserved_phys_range(unsigned long begin, unsigned long end);
 
+#ifdef CONFIG_KEXEC_CMA
+#ifdef CONFIG_X86
+	extern struct cma *crashk_cma, *crashk_cma_low;
+	int crash_free_memory(unsigned int size);
+	int crash_alloc_memory(unsigned int size);
+	int crash_alloc_memory_low(void);
+	int crash_free_memory_low(void);
+	size_t crash_get_memory_size_low(void);
+#endif
+#endif
 int __weak arch_kexec_kernel_image_probe(struct kimage *image, void *buf,
 					 unsigned long buf_len);
 void * __weak arch_kexec_kernel_image_load(struct kimage *image);
diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c
index 11b64a6..0ef3385 100644
--- a/kernel/kexec_core.c
+++ b/kernel/kexec_core.c
@@ -39,6 +39,7 @@
 #include <linux/compiler.h>
 #include <linux/hugetlb.h>
 
+#include <linux/cma.h>
 #include <asm/page.h>
 #include <asm/sections.h>
 
@@ -46,7 +47,9 @@
 #include <crypto/sha.h>
 #include "kexec_internal.h"
 
+#define CRASH_ALIGN		(16 << 20)
 DEFINE_MUTEX(kexec_mutex);
+DEFINE_MUTEX(kexec_mutex_low);
 
 /* Per cpu memory for storing cpu states in case of system crash. */
 note_buf_t __percpu *crash_notes;
@@ -57,6 +60,7 @@ u32 vmcoreinfo_note[VMCOREINFO_NOTE_SIZE/4];
 size_t vmcoreinfo_size;
 size_t vmcoreinfo_max_size = sizeof(vmcoreinfo_data);
 
+static struct page *pages, *pages_low;
 /* Flag to indicate we are going to kexec a new kernel */
 bool kexec_in_progress = false;
 
@@ -946,6 +950,85 @@ unlock:
 	mutex_unlock(&kexec_mutex);
 	return ret;
 }
+#ifdef CONFIG_KEXEC_CMA
+#ifdef CONFIG_X86
+	size_t crash_get_memory_size_low(void)
+	{
+		size_t size = 0;
+
+		mutex_lock(&kexec_mutex_low);
+		if (crashk_low_res.end != crashk_low_res.start)
+			size = resource_size(&crashk_low_res);
+		mutex_unlock(&kexec_mutex_low);
+		return size;
+	}
+	int crash_free_memory(unsigned int size)
+	{
+		int ret;
+
+		if (!crashk_cma)
+			return 0;
+		ret = cma_release(crashk_cma, pages, size >> PAGE_SHIFT);
+
+		if (!ret) {
+			pr_info("Crash memory release failed");
+			return ret;
+		}
+		release_resource(&crashk_res);
+		return 0;
+	}
+
+	int crash_alloc_memory(unsigned int size)
+	{
+		if (!crashk_cma)
+			return 0;
+		pages = cma_alloc(crashk_cma, size >> PAGE_SHIFT, KEXEC_CRASH_MEM_ALIGN);
+
+		if (!pages) {
+			pr_info("Memory for crash kernel not allocated");
+			return -ENOMEM;
+		}
+
+		crashk_res.start = page_to_pfn(pages) << PAGE_SHIFT;
+		crashk_res.end = crashk_res.start + size - 1;
+		insert_resource(&iomem_resource, &crashk_res);
+		return 0;
+	}
+
+	int crash_free_memory_low(void)
+	{
+		int ret;
+
+		if (!crashk_cma_low)
+			return 0;
+		ret = cma_release(crashk_cma_low, pages_low, cma_get_size(crashk_cma_low) >> PAGE_SHIFT);
+
+		if (!ret) {
+			pr_info("Crash low memory release failed");
+			return ret;
+		}
+		release_resource(&crashk_low_res);
+		return 0;
+	}
+
+	int crash_alloc_memory_low(void)
+	{
+		if (!crashk_cma_low)
+			return 0;
+		pages = cma_alloc(crashk_cma_low, cma_get_size(crashk_cma_low) >> PAGE_SHIFT, KEXEC_CRASH_MEM_ALIGN);
+
+		if (!pages) {
+			pr_info("Low memory for crash kernel not allocated");
+			return -ENOMEM;
+		}
+
+		crashk_low_res.start = page_to_pfn(pages) << PAGE_SHIFT;
+		crashk_low_res.end = crashk_low_res.start + cma_get_size(crashk_cma_low) - 1;
+		insert_resource(&iomem_resource, &crashk_low_res);
+		return 0;
+	}
+#endif
+#endif
 
 static u32 *append_elf_note(u32 *buf, char *name, unsigned type, void *data,
 			    size_t data_len)
-- 
2.9.0.GIT

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* [RFC 3/4] Adding a new kernel configuration to enable the feature
  2016-08-12 14:18 [RFC 0/4] Kexec: Enable run time memory resrvation of crash kernel Ronit Halder
  2016-08-12 14:20 ` [RFC 1/4] Creating one or two CMA area at Boot time Ronit Halder
  2016-08-12 14:21 ` [RFC 2/4] Functions for memory reservation and release Ronit Halder
@ 2016-08-12 14:25 ` Ronit Halder
  2016-08-12 14:26 ` [RFC 4/4] Enable memory allocation through sysfs interface Ronit Halder
  2016-08-22 10:59 ` [RFC 0/4] Kexec: Enable run time memory resrvation of crash kernel Pratyush Anand
  4 siblings, 0 replies; 7+ messages in thread
From: Ronit Halder @ 2016-08-12 14:25 UTC (permalink / raw)
  To: linux-kernel
  Cc: tglx, mingo, hpa, bp, dyoung, jroedel, krzysiek, msalter,
	ebiederm, akpm, bhe, vgoyal, mnfhuang, kexec, kirill.shutemov,
	mchehab, aarcange, vdavydov, dan.j.williams, jack, linux-mm,
	Ronit Halder

Kernel configuration option added to enable run time memory reservation
feature for kexec.

Signed-off-by: Ronit Halder <ronit.crj@gmail.com>

---
 mm/Kconfig | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/mm/Kconfig b/mm/Kconfig
index 97a4e06..8b1533d 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -668,3 +668,9 @@ config ZONE_DEVICE
 
 config FRAME_VECTOR
 	bool
+config KEXEC_CMA
+	bool "Use CMA for Kexec crash kernel"
+	depends on CMA
+	help
+	  This configuration option is to use CMA for Kexec.
+	  CMA helps us to allocate memory for crash kernel at runtime.
\ No newline at end of file
-- 
2.9.0.GIT

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* [RFC 4/4] Enable memory allocation through sysfs interface
  2016-08-12 14:18 [RFC 0/4] Kexec: Enable run time memory resrvation of crash kernel Ronit Halder
                   ` (2 preceding siblings ...)
  2016-08-12 14:25 ` [RFC 3/4] Adding a new kernel configuration to enable the feature Ronit Halder
@ 2016-08-12 14:26 ` Ronit Halder
  2016-08-22 10:59 ` [RFC 0/4] Kexec: Enable run time memory resrvation of crash kernel Pratyush Anand
  4 siblings, 0 replies; 7+ messages in thread
From: Ronit Halder @ 2016-08-12 14:26 UTC (permalink / raw)
  To: linux-kernel
  Cc: tglx, mingo, hpa, bp, dyoung, jroedel, krzysiek, msalter,
	ebiederm, akpm, bhe, vgoyal, mnfhuang, kexec, kirill.shutemov,
	mchehab, aarcange, vdavydov, dan.j.williams, jack, linux-mm,
	Ronit Halder

Modify the sysfs entry "kernel/kexec_crash_size" to allocate or
release memory at run time. The memory size will be written to
the entry in MB. If the user uses high memory (in x86_64). Then
size will be only set for high memory. The low memory will be
allocated automatically. If the size set is zero, the both the
allocated region in low and high memory will be released.

Signed-off-by: Ronit Halder <ronit.crj@gmail.com>

---
 kernel/ksysfs.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
index e83b264..4cc286d 100644
--- a/kernel/ksysfs.c
+++ b/kernel/ksysfs.c
@@ -116,10 +116,31 @@ static ssize_t kexec_crash_size_store(struct kobject *kobj,
 {
 	unsigned long cnt;
 	int ret;
+	int size;
 
 	if (kstrtoul(buf, 0, &cnt))
 		return -EINVAL;
-
+#ifdef CONFIG_KEXEC_CMA
+#ifdef CONFIG_X86
+	size = cnt << 20;
+	if (cnt == 0) {
+		crash_free_memory_low();
+		ret = crash_free_memory(crash_get_memory_size());
+	} else if (cnt > 0) {
+		if (!crash_get_memory_size_low() && crash_alloc_memory_low())
+			return -ENOMEM;
+		ret = crash_free_memory(crash_get_memory_size());
+		if (ret)
+			return ret;
+		ret = crash_alloc_memory(size);
+		if (ret)
+			return ret;
+	} else {
+		return -EINVAL;
+	}
+	return count;
+#endif
+#endif
 	ret = crash_shrink_memory(cnt);
 	return ret < 0 ? ret : count;
 }
-- 
2.9.0.GIT

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [RFC 0/4] Kexec: Enable run time memory resrvation of crash kernel
  2016-08-12 14:18 [RFC 0/4] Kexec: Enable run time memory resrvation of crash kernel Ronit Halder
                   ` (3 preceding siblings ...)
  2016-08-12 14:26 ` [RFC 4/4] Enable memory allocation through sysfs interface Ronit Halder
@ 2016-08-22 10:59 ` Pratyush Anand
  2016-08-23  7:08   ` Xunlei Pang
  4 siblings, 1 reply; 7+ messages in thread
From: Pratyush Anand @ 2016-08-22 10:59 UTC (permalink / raw)
  To: Ronit Halder
  Cc: linux-kernel, tglx, mingo, hpa, bp, dyoung, jroedel, krzysiek,
	msalter, ebiederm, akpm, bhe, vgoyal, mnfhuang, kexec,
	kirill.shutemov, mchehab, aarcange, vdavydov, dan.j.williams,
	jack, linux-mm

On 12/08/2016:07:48:38 PM, Ronit Halder wrote:
> Currenty linux kernel reserves memory at the boot time for crash kernel.
> It will be very useful if we can reserve memory in run time. The user can 
> reserve the memory whenerver needed instead of reserving at the boot time.
> 
> It is possible to reserve memory for crash kernel at the run time using
> CMA (Contiguous Memory Allocator). CMA is capable of allocating big chunk 
> of memory. At the boot time we will create one (if only low memory is used)
> or two (if we use both high memory in case of x86_64) CMA areas of size 
> given in "crashkernel" boot time command line parameter. This memory in CMA
> areas can be used as movable pages (used for disk caches, process pages
> etc) if not allocated. Then the user can reserve or free memory from those
> CMA areas using "/sys/kernel/kexec_crash_size" sysfs entry. If the user

But the cma_alloc() is not a guaranteed allocation function, whereas memblock
api will guarantee that crashkerenel memory is available. 
More over, most of the system starts kdump service at boot time, so not sure if
it could be useful enough. Lets see what other says....

> usee high memory it will automatically at least 256MB low memory
> (needed for swiotlb and DMA buffers) when the user allocates memory using
> mentioned sysfs enrty. In case of high memory reservation the user controls
> the size of reserved region in high memory with
> "/sys/kernel/kexec_crash_size" entry. If the size set is zero then the 
> memory allocated in low memory will automatically be freed.
> 
> As the pages under CMA area (when not allocated by CMA) can only be used by
> movable pages. The pages won't be used for DMA. So, after allocating pages
> from CMA area for loading the crash kernel, there won't be any chance of
> DMA on the memory.
> 
> Thus is a prototype patch. Please share your opinions on my approach. This
> patch is only for x86 and x86_64. Please note, this patch is only a
> prototype just to explain my approach and get the review. This patch is on
> kernel version v4.4.11.
> 
> CMA depends on page migration and only uses movable pages. But, the movable
> pages become unmovable momentarily for pinning. The CMA fails for this
> reason. I don't have any solution for that right now. This approach will
> work when the this problems with CMA will be fixed. The patch is enabled
> by a kernel configuration option CONFIG_KEXEC_CMA.
> 
> Ronit Halder (4):
>   Creating one or two CMA area at Boot time
>   Functions for memory reservation and release
>   Adding a new kernel configuration to enable the feature
>   Enable memory allocation through sysfs interface
> 
>  arch/x86/kernel/setup.c | 44 ++++++++++++++++++++++++--
>  include/linux/kexec.h   | 11 ++++++-
>  kernel/kexec_core.c     | 83 +++++++++++++++++++++++++++++++++++++++++++++++++
>  kernel/ksysfs.c         | 23 +++++++++++++-
>  mm/Kconfig              |  6 ++++
>  5 files changed, 162 insertions(+), 5 deletions(-)

~Pratyush

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [RFC 0/4] Kexec: Enable run time memory resrvation of crash kernel
  2016-08-22 10:59 ` [RFC 0/4] Kexec: Enable run time memory resrvation of crash kernel Pratyush Anand
@ 2016-08-23  7:08   ` Xunlei Pang
  0 siblings, 0 replies; 7+ messages in thread
From: Xunlei Pang @ 2016-08-23  7:08 UTC (permalink / raw)
  To: Pratyush Anand, Ronit Halder
  Cc: vdavydov, jack, linux-mm, krzysiek, mnfhuang, hpa, tglx,
	aarcange, bhe, mingo, msalter, bp, dyoung, vgoyal, jroedel,
	mchehab, dan.j.williams, kexec, linux-kernel, ebiederm, akpm,
	kirill.shutemov

On 2016/08/22 at 18:59, Pratyush Anand wrote:
> On 12/08/2016:07:48:38 PM, Ronit Halder wrote:
>> Currenty linux kernel reserves memory at the boot time for crash kernel.
>> It will be very useful if we can reserve memory in run time. The user can 
>> reserve the memory whenerver needed instead of reserving at the boot time.
>>
>> It is possible to reserve memory for crash kernel at the run time using
>> CMA (Contiguous Memory Allocator). CMA is capable of allocating big chunk 
>> of memory. At the boot time we will create one (if only low memory is used)
>> or two (if we use both high memory in case of x86_64) CMA areas of size 
>> given in "crashkernel" boot time command line parameter. This memory in CMA
>> areas can be used as movable pages (used for disk caches, process pages
>> etc) if not allocated. Then the user can reserve or free memory from those
>> CMA areas using "/sys/kernel/kexec_crash_size" sysfs entry. If the user
> But the cma_alloc() is not a guaranteed allocation function, whereas memblock
> api will guarantee that crashkerenel memory is available. 
> More over, most of the system starts kdump service at boot time, so not sure if
> it could be useful enough. Lets see what other says....

Maybe this is useful for debug purpose, after you shrunk the memory and realized
you just made a mistake, you can use this function to expand it without reboot to
modify the cmdline. Otherwise, I can't think of other use cases.

But it still relys on the "crashkernel" cmdline, and I think it would be more useful(at least
for me) if you can throw away "crashkernel", and use the sysfs entry directly to reserve
or expand the memory if possible. Because sometimes when I want to debug some kdump
issue, I found the system I was using didn't specify the right (none or smaller)"crashkernel"
cmdline, so I must reboot it.

Regards,
Xunlei

>
>> usee high memory it will automatically at least 256MB low memory
>> (needed for swiotlb and DMA buffers) when the user allocates memory using
>> mentioned sysfs enrty. In case of high memory reservation the user controls
>> the size of reserved region in high memory with
>> "/sys/kernel/kexec_crash_size" entry. If the size set is zero then the 
>> memory allocated in low memory will automatically be freed.
>>
>> As the pages under CMA area (when not allocated by CMA) can only be used by
>> movable pages. The pages won't be used for DMA. So, after allocating pages
>> from CMA area for loading the crash kernel, there won't be any chance of
>> DMA on the memory.
>>
>> Thus is a prototype patch. Please share your opinions on my approach. This
>> patch is only for x86 and x86_64. Please note, this patch is only a
>> prototype just to explain my approach and get the review. This patch is on
>> kernel version v4.4.11.
>>
>> CMA depends on page migration and only uses movable pages. But, the movable
>> pages become unmovable momentarily for pinning. The CMA fails for this
>> reason. I don't have any solution for that right now. This approach will
>> work when the this problems with CMA will be fixed. The patch is enabled
>> by a kernel configuration option CONFIG_KEXEC_CMA.
>>
>> Ronit Halder (4):
>>   Creating one or two CMA area at Boot time
>>   Functions for memory reservation and release
>>   Adding a new kernel configuration to enable the feature
>>   Enable memory allocation through sysfs interface
>>
>>  arch/x86/kernel/setup.c | 44 ++++++++++++++++++++++++--
>>  include/linux/kexec.h   | 11 ++++++-
>>  kernel/kexec_core.c     | 83 +++++++++++++++++++++++++++++++++++++++++++++++++
>>  kernel/ksysfs.c         | 23 +++++++++++++-
>>  mm/Kconfig              |  6 ++++
>>  5 files changed, 162 insertions(+), 5 deletions(-)
> ~Pratyush
>
> _______________________________________________
> kexec mailing list
> kexec@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/kexec

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

end of thread, other threads:[~2016-08-23  7:08 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-12 14:18 [RFC 0/4] Kexec: Enable run time memory resrvation of crash kernel Ronit Halder
2016-08-12 14:20 ` [RFC 1/4] Creating one or two CMA area at Boot time Ronit Halder
2016-08-12 14:21 ` [RFC 2/4] Functions for memory reservation and release Ronit Halder
2016-08-12 14:25 ` [RFC 3/4] Adding a new kernel configuration to enable the feature Ronit Halder
2016-08-12 14:26 ` [RFC 4/4] Enable memory allocation through sysfs interface Ronit Halder
2016-08-22 10:59 ` [RFC 0/4] Kexec: Enable run time memory resrvation of crash kernel Pratyush Anand
2016-08-23  7:08   ` Xunlei Pang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).