[Suspend2][ 7/9] [Suspend2] Relocate a piece of memory if required.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Given an address and size (never more than a page and never overlapping
page boundaries), relocate the data to an address that can be safely used
during the atomic restore if that relocation is necessary. The memory to be
freed might be slab or a normal page.

Signed-off-by: Nigel Cunningham <[email protected]>

 kernel/power/pagedir.c |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/kernel/power/pagedir.c b/kernel/power/pagedir.c
index 4cdc0ef..ec75e79 100644
--- a/kernel/power/pagedir.c
+++ b/kernel/power/pagedir.c
@@ -288,3 +288,23 @@ unsigned long suspend_get_nonconflicting
 	return (unsigned long) page_address(page);
 }
 
+/* relocate_page_if_required
+ *
+ * Description: Given the address of a pointer to a page, we check if the page
+ * 		needs relocating and do so if needs be, adjusting the pointer
+ * 		too.
+ */
+
+void suspend_relocate_if_required(unsigned long *current_value, unsigned int size)
+{
+	if (PagePageset1(virt_to_page(*current_value))) {
+		unsigned long new_page = suspend_get_nonconflicting_page();
+		memcpy((char *) new_page, (char *) *current_value, size);
+		if (PageSlab(virt_to_page(*current_value)))
+			kfree((void *) *current_value);
+		else
+			free_page((unsigned long) *current_value);
+		*current_value = new_page;
+	}
+}
+

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

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux