All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] powerpc/fadump: add reschedule point while releasing memory
@ 2017-06-01 19:40 Hari Bathini
  2017-06-29 12:21 ` [v2] " Michael Ellerman
  0 siblings, 1 reply; 2+ messages in thread
From: Hari Bathini @ 2017-06-01 19:40 UTC (permalink / raw)
  To: Michael Ellerman; +Cc: linuxppc-dev, Ankit Kumar, Mahesh J Salgaonkar

Around 95% of memory is reserved by fadump/capture kernel. All this
memory is freed, one page at a time, on writing '1' to the node
/sys/kernel/fadump_release_mem. On systems with large memory, this
can take a long time to complete, leading to soft lockup warning
messages. To avoid this, add reschedule points at regular intervals.

Also, while memblock_reserve() implicitly takes care of holes in the
given memory range while reserving memory, those holes need to be
taken care of while releasing memory as memory is freed one page at
a time. Add support to skip holes while releasing memory.

Suggested-by: Michael Ellerman <mpe@ellerman.id.au>
Signed-off-by: Hari Bathini <hbathini@linux.vnet.ibm.com>
---

Changes since v1:
* Got rid of RELEASE_PAGES_BATCH macro and the corresponding code to
  simplify the implementation.
* Introduced support to skip memory holes while releasing memory.


 arch/powerpc/kernel/fadump.c |   65 +++++++++++++++++++++++++++++++++++-------
 1 file changed, 54 insertions(+), 11 deletions(-)

diff --git a/arch/powerpc/kernel/fadump.c b/arch/powerpc/kernel/fadump.c
index 466569e..23aa674 100644
--- a/arch/powerpc/kernel/fadump.c
+++ b/arch/powerpc/kernel/fadump.c
@@ -1046,28 +1046,71 @@ void fadump_cleanup(void)
 	}
 }
 
+static void fadump_free_reserved_memory(unsigned long start_pfn,
+					unsigned long end_pfn)
+{
+	unsigned long pfn;
+	unsigned long time_limit = jiffies + HZ;
+
+	pr_info("freeing reserved memory (0x%llx - 0x%llx)\n",
+		PFN_PHYS(start_pfn), PFN_PHYS(end_pfn));
+
+	for (pfn = start_pfn; pfn < end_pfn; pfn++) {
+		free_reserved_page(pfn_to_page(pfn));
+
+		if (time_after(jiffies, time_limit)) {
+			cond_resched();
+			time_limit = jiffies + HZ;
+		}
+	}
+}
+
+/*
+ * Skip memory holes and free memory that was actually reserved.
+ */
+static void fadump_release_reserved_area(unsigned long start, unsigned long end)
+{
+	struct memblock_region *reg;
+	unsigned long tstart, tend;
+	unsigned long start_pfn = PHYS_PFN(start);
+	unsigned long end_pfn = PHYS_PFN(end);
+
+	for_each_memblock(memory, reg) {
+		tstart = max(start_pfn, memblock_region_memory_base_pfn(reg));
+		tend = min(end_pfn, memblock_region_memory_end_pfn(reg));
+		if (tstart < tend) {
+			fadump_free_reserved_memory(tstart, tend);
+
+			if (tend == end_pfn)
+				break;
+
+			start_pfn = tend + 1;
+		}
+	}
+}
+
 /*
  * Release the memory that was reserved in early boot to preserve the memory
  * contents. The released memory will be available for general use.
  */
 static void fadump_release_memory(unsigned long begin, unsigned long end)
 {
-	unsigned long addr;
 	unsigned long ra_start, ra_end;
 
 	ra_start = fw_dump.reserve_dump_area_start;
 	ra_end = ra_start + fw_dump.reserve_dump_area_size;
 
-	for (addr = begin; addr < end; addr += PAGE_SIZE) {
-		/*
-		 * exclude the dump reserve area. Will reuse it for next
-		 * fadump registration.
-		 */
-		if (addr <= ra_end && ((addr + PAGE_SIZE) > ra_start))
-			continue;
-
-		free_reserved_page(pfn_to_page(addr >> PAGE_SHIFT));
-	}
+	/*
+	 * exclude the dump reserve area. Will reuse it for next
+	 * fadump registration.
+	 */
+	if (begin < ra_end && end > ra_start) {
+		if (begin < ra_start)
+			fadump_release_reserved_area(begin, ra_start);
+		if (end > ra_end)
+			fadump_release_reserved_area(ra_end, end);
+	} else
+		fadump_release_reserved_area(begin, end);
 }
 
 static void fadump_invalidate_release_mem(void)

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

* Re: [v2] powerpc/fadump: add reschedule point while releasing memory
  2017-06-01 19:40 [PATCH v2] powerpc/fadump: add reschedule point while releasing memory Hari Bathini
@ 2017-06-29 12:21 ` Michael Ellerman
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Ellerman @ 2017-06-29 12:21 UTC (permalink / raw)
  To: Hari Bathini; +Cc: linuxppc-dev, Ankit Kumar, Mahesh J Salgaonkar

On Thu, 2017-06-01 at 19:40:10 UTC, Hari Bathini wrote:
> Around 95% of memory is reserved by fadump/capture kernel. All this
> memory is freed, one page at a time, on writing '1' to the node
> /sys/kernel/fadump_release_mem. On systems with large memory, this
> can take a long time to complete, leading to soft lockup warning
> messages. To avoid this, add reschedule points at regular intervals.
> 
> Also, while memblock_reserve() implicitly takes care of holes in the
> given memory range while reserving memory, those holes need to be
> taken care of while releasing memory as memory is freed one page at
> a time. Add support to skip holes while releasing memory.
> 
> Suggested-by: Michael Ellerman <mpe@ellerman.id.au>
> Signed-off-by: Hari Bathini <hbathini@linux.vnet.ibm.com>

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/68fa6478e3b1fab7077d390070ed45

cheers

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

end of thread, other threads:[~2017-06-29 12:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-01 19:40 [PATCH v2] powerpc/fadump: add reschedule point while releasing memory Hari Bathini
2017-06-29 12:21 ` [v2] " Michael Ellerman

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