All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] swsusp: Stop using page flags
@ 2007-03-12 21:14 Rafael J. Wysocki
  2007-03-12 21:16 ` [PATCH 1/3] swsusp: Use inline functions for changing " Rafael J. Wysocki
                   ` (2 more replies)
  0 siblings, 3 replies; 24+ messages in thread
From: Rafael J. Wysocki @ 2007-03-12 21:14 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Pavel Machek, Peter Zijlstra, LKML

Hi,

The following three patches make swsusp use its own data structures for memory
management instead of special page flags, so that these page flags can be used
for other purposes.

Greetings,
Rafael


-- 
If you don't have the time to read,
you don't have the time or the tools to write.
		- Stephen King


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

* [PATCH 1/3] swsusp: Use inline functions for changing page flags
  2007-03-12 21:14 [PATCH 0/3] swsusp: Stop using page flags Rafael J. Wysocki
@ 2007-03-12 21:16 ` Rafael J. Wysocki
  2007-03-12 21:19 ` [PATCH 2/3] swsusp: Do not use " Rafael J. Wysocki
  2007-03-12 21:20 ` [PATCH 3/3] mm: Remove unused page flags Rafael J. Wysocki
  2 siblings, 0 replies; 24+ messages in thread
From: Rafael J. Wysocki @ 2007-03-12 21:16 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Pavel Machek, Peter Zijlstra, LKML

From: Rafael J. Wysocki <rjw@sisk.pl>

Replace direct invocations of SetPageNosave(), SetPageNosaveFree() etc. with
calls to inline functions that can be changed in subsequent patches without
modifying the code calling them.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Pavel Machek <pavel@ucw.cz>
---
 include/linux/suspend.h |   33 +++++++++++++++++++++++++++++++++
 kernel/power/snapshot.c |   48 +++++++++++++++++++++++++-----------------------
 mm/page_alloc.c         |    6 +++---
 3 files changed, 61 insertions(+), 26 deletions(-)

Index: linux-2.6.21-rc2/include/linux/suspend.h
===================================================================
--- linux-2.6.21-rc2.orig/include/linux/suspend.h	2007-03-02 09:05:53.000000000 +0100
+++ linux-2.6.21-rc2/include/linux/suspend.h	2007-03-02 09:24:02.000000000 +0100
@@ -8,6 +8,7 @@
 #include <linux/notifier.h>
 #include <linux/init.h>
 #include <linux/pm.h>
+#include <linux/mm.h>
 
 /* struct pbe is used for creating lists of pages that should be restored
  * atomically during the resume from disk, because the page frames they have
@@ -49,6 +50,38 @@ void __save_processor_state(struct saved
 void __restore_processor_state(struct saved_context *ctxt);
 unsigned long get_safe_page(gfp_t gfp_mask);
 
+/* Page management functions for the software suspend (swsusp) */
+
+static inline void swsusp_set_page_forbidden(struct page *page)
+{
+	SetPageNosave(page);
+}
+
+static inline int swsusp_page_is_forbidden(struct page *page)
+{
+	return PageNosave(page);
+}
+
+static inline void swsusp_unset_page_forbidden(struct page *page)
+{
+	ClearPageNosave(page);
+}
+
+static inline void swsusp_set_page_free(struct page *page)
+{
+	SetPageNosaveFree(page);
+}
+
+static inline int swsusp_page_is_free(struct page *page)
+{
+	return PageNosaveFree(page);
+}
+
+static inline void swsusp_unset_page_free(struct page *page)
+{
+	ClearPageNosaveFree(page);
+}
+
 /*
  * XXX: We try to keep some more pages free so that I/O operations succeed
  * without paging. Might this be more?
Index: linux-2.6.21-rc2/kernel/power/snapshot.c
===================================================================
--- linux-2.6.21-rc2.orig/kernel/power/snapshot.c	2007-03-02 09:05:53.000000000 +0100
+++ linux-2.6.21-rc2/kernel/power/snapshot.c	2007-03-02 09:27:06.000000000 +0100
@@ -67,15 +67,15 @@ static void *get_image_page(gfp_t gfp_ma
 
 	res = (void *)get_zeroed_page(gfp_mask);
 	if (safe_needed)
-		while (res && PageNosaveFree(virt_to_page(res))) {
+		while (res && swsusp_page_is_free(virt_to_page(res))) {
 			/* The page is unsafe, mark it for swsusp_free() */
-			SetPageNosave(virt_to_page(res));
+			swsusp_set_page_forbidden(virt_to_page(res));
 			allocated_unsafe_pages++;
 			res = (void *)get_zeroed_page(gfp_mask);
 		}
 	if (res) {
-		SetPageNosave(virt_to_page(res));
-		SetPageNosaveFree(virt_to_page(res));
+		swsusp_set_page_forbidden(virt_to_page(res));
+		swsusp_set_page_free(virt_to_page(res));
 	}
 	return res;
 }
@@ -91,8 +91,8 @@ static struct page *alloc_image_page(gfp
 
 	page = alloc_page(gfp_mask);
 	if (page) {
-		SetPageNosave(page);
-		SetPageNosaveFree(page);
+		swsusp_set_page_forbidden(page);
+		swsusp_set_page_free(page);
 	}
 	return page;
 }
@@ -110,9 +110,9 @@ static inline void free_image_page(void 
 
 	page = virt_to_page(addr);
 
-	ClearPageNosave(page);
+	swsusp_unset_page_forbidden(page);
 	if (clear_nosave_free)
-		ClearPageNosaveFree(page);
+		swsusp_unset_page_free(page);
 
 	__free_page(page);
 }
@@ -615,7 +615,8 @@ static struct page *saveable_highmem_pag
 
 	BUG_ON(!PageHighMem(page));
 
-	if (PageNosave(page) || PageReserved(page) || PageNosaveFree(page))
+	if (swsusp_page_is_forbidden(page) ||  swsusp_page_is_free(page) ||
+	    PageReserved(page))
 		return NULL;
 
 	return page;
@@ -681,7 +682,7 @@ static struct page *saveable_page(unsign
 
 	BUG_ON(PageHighMem(page));
 
-	if (PageNosave(page) || PageNosaveFree(page))
+	if (swsusp_page_is_forbidden(page) || swsusp_page_is_free(page))
 		return NULL;
 
 	if (PageReserved(page) && pfn_is_nosave(pfn))
@@ -821,9 +822,10 @@ void swsusp_free(void)
 			if (pfn_valid(pfn)) {
 				struct page *page = pfn_to_page(pfn);
 
-				if (PageNosave(page) && PageNosaveFree(page)) {
-					ClearPageNosave(page);
-					ClearPageNosaveFree(page);
+				if (swsusp_page_is_forbidden(page) &&
+				    swsusp_page_is_free(page)) {
+					swsusp_unset_page_forbidden(page);
+					swsusp_unset_page_free(page);
 					__free_page(page);
 				}
 			}
@@ -1146,7 +1148,7 @@ static int mark_unsafe_pages(struct memo
 		max_zone_pfn = zone->zone_start_pfn + zone->spanned_pages;
 		for (pfn = zone->zone_start_pfn; pfn < max_zone_pfn; pfn++)
 			if (pfn_valid(pfn))
-				ClearPageNosaveFree(pfn_to_page(pfn));
+				swsusp_unset_page_free(pfn_to_page(pfn));
 	}
 
 	/* Mark pages that correspond to the "original" pfns as "unsafe" */
@@ -1155,7 +1157,7 @@ static int mark_unsafe_pages(struct memo
 		pfn = memory_bm_next_pfn(bm);
 		if (likely(pfn != BM_END_OF_MAP)) {
 			if (likely(pfn_valid(pfn)))
-				SetPageNosaveFree(pfn_to_page(pfn));
+				swsusp_set_page_free(pfn_to_page(pfn));
 			else
 				return -EFAULT;
 		}
@@ -1321,14 +1323,14 @@ prepare_highmem_image(struct memory_bitm
 		struct page *page;
 
 		page = alloc_page(__GFP_HIGHMEM);
-		if (!PageNosaveFree(page)) {
+		if (!swsusp_page_is_free(page)) {
 			/* The page is "safe", set its bit the bitmap */
 			memory_bm_set_bit(bm, page_to_pfn(page));
 			safe_highmem_pages++;
 		}
 		/* Mark the page as allocated */
-		SetPageNosave(page);
-		SetPageNosaveFree(page);
+		swsusp_set_page_forbidden(page);
+		swsusp_set_page_free(page);
 	}
 	memory_bm_position_reset(bm);
 	safe_highmem_bm = bm;
@@ -1360,7 +1362,7 @@ get_highmem_page_buffer(struct page *pag
 	struct highmem_pbe *pbe;
 	void *kaddr;
 
-	if (PageNosave(page) && PageNosaveFree(page)) {
+	if (swsusp_page_is_forbidden(page) && swsusp_page_is_free(page)) {
 		/* We have allocated the "original" page frame and we can
 		 * use it directly to store the loaded page.
 		 */
@@ -1522,14 +1524,14 @@ prepare_image(struct memory_bitmap *new_
 			error = -ENOMEM;
 			goto Free;
 		}
-		if (!PageNosaveFree(virt_to_page(lp))) {
+		if (!swsusp_page_is_free(virt_to_page(lp))) {
 			/* The page is "safe", add it to the list */
 			lp->next = safe_pages_list;
 			safe_pages_list = lp;
 		}
 		/* Mark the page as allocated */
-		SetPageNosave(virt_to_page(lp));
-		SetPageNosaveFree(virt_to_page(lp));
+		swsusp_set_page_forbidden(virt_to_page(lp));
+		swsusp_set_page_free(virt_to_page(lp));
 		nr_pages--;
 	}
 	/* Free the reserved safe pages so that chain_alloc() can use them */
@@ -1558,7 +1560,7 @@ static void *get_buffer(struct memory_bi
 	if (PageHighMem(page))
 		return get_highmem_page_buffer(page, ca);
 
-	if (PageNosave(page) && PageNosaveFree(page))
+	if (swsusp_page_is_forbidden(page) && swsusp_page_is_free(page))
 		/* We have allocated the "original" page frame and we can
 		 * use it directly to store the loaded page.
 		 */
Index: linux-2.6.21-rc2/mm/page_alloc.c
===================================================================
--- linux-2.6.21-rc2.orig/mm/page_alloc.c	2007-03-02 09:03:43.000000000 +0100
+++ linux-2.6.21-rc2/mm/page_alloc.c	2007-03-02 09:11:54.000000000 +0100
@@ -770,8 +770,8 @@ void mark_free_pages(struct zone *zone)
 		if (pfn_valid(pfn)) {
 			struct page *page = pfn_to_page(pfn);
 
-			if (!PageNosave(page))
-				ClearPageNosaveFree(page);
+			if (!swsusp_page_is_forbidden(page))
+				swsusp_unset_page_free(page);
 		}
 
 	for (order = MAX_ORDER - 1; order >= 0; --order)
@@ -780,7 +780,7 @@ void mark_free_pages(struct zone *zone)
 
 			pfn = page_to_pfn(list_entry(curr, struct page, lru));
 			for (i = 0; i < (1UL << order); i++)
-				SetPageNosaveFree(pfn_to_page(pfn + i));
+				swsusp_set_page_free(pfn_to_page(pfn + i));
 		}
 
 	spin_unlock_irqrestore(&zone->lock, flags);


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

* [PATCH 2/3] swsusp: Do not use page flags
  2007-03-12 21:14 [PATCH 0/3] swsusp: Stop using page flags Rafael J. Wysocki
  2007-03-12 21:16 ` [PATCH 1/3] swsusp: Use inline functions for changing " Rafael J. Wysocki
@ 2007-03-12 21:19 ` Rafael J. Wysocki
  2007-03-15 19:08   ` Andrew Morton
  2007-03-20  0:31   ` Andrew Morton
  2007-03-12 21:20 ` [PATCH 3/3] mm: Remove unused page flags Rafael J. Wysocki
  2 siblings, 2 replies; 24+ messages in thread
From: Rafael J. Wysocki @ 2007-03-12 21:19 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Pavel Machek, Peter Zijlstra, LKML

From: Rafael J. Wysocki <rjw@sisk.pl>

Make swsusp use memory bitmaps instead of page flags for marking 'nosave' and
free pages.  This allows us to 'recycle' two page flags that can be used for other
purposes.  Also, the memory needed to store the bitmaps is allocated when
necessary (ie. before the suspend) and freed after the resume which is more
reasonable.

The patch is designed to minimize the amount of changes and there are some nice
simplifications and optimizations possible on top of it.  I am going to
implement them separately in the future.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Pavel Machek <pavel@ucw.cz>
---
 arch/x86_64/kernel/e820.c |   26 +---
 include/linux/suspend.h   |   58 +++-------
 kernel/power/disk.c       |   23 +++-
 kernel/power/power.h      |    2 
 kernel/power/snapshot.c   |  250 +++++++++++++++++++++++++++++++++++++++++++---
 kernel/power/user.c       |    4 
 6 files changed, 281 insertions(+), 82 deletions(-)

Index: linux-2.6.21-rc3/include/linux/suspend.h
===================================================================
--- linux-2.6.21-rc3.orig/include/linux/suspend.h
+++ linux-2.6.21-rc3/include/linux/suspend.h
@@ -24,63 +24,41 @@ struct pbe {
 extern void drain_local_pages(void);
 extern void mark_free_pages(struct zone *zone);
 
-#ifdef CONFIG_PM
-/* kernel/power/swsusp.c */
-extern int software_suspend(void);
-
-#if defined(CONFIG_VT) && defined(CONFIG_VT_CONSOLE)
+#if defined(CONFIG_PM) && defined(CONFIG_VT) && defined(CONFIG_VT_CONSOLE)
 extern int pm_prepare_console(void);
 extern void pm_restore_console(void);
 #else
 static inline int pm_prepare_console(void) { return 0; }
 static inline void pm_restore_console(void) {}
-#endif /* defined(CONFIG_VT) && defined(CONFIG_VT_CONSOLE) */
+#endif
+
+#if defined(CONFIG_PM) && defined(CONFIG_SOFTWARE_SUSPEND)
+/* kernel/power/swsusp.c */
+extern int software_suspend(void);
+/* kernel/power/snapshot.c */
+extern void __init register_nosave_region(unsigned long, unsigned long);
+extern int swsusp_page_is_forbidden(struct page *);
+extern void swsusp_set_page_free(struct page *);
+extern void swsusp_unset_page_free(struct page *);
+extern unsigned long get_safe_page(gfp_t gfp_mask);
 #else
 static inline int software_suspend(void)
 {
 	printk("Warning: fake suspend called\n");
 	return -ENOSYS;
 }
-#endif /* CONFIG_PM */
+
+static inline void register_nosave_region(unsigned long b, unsigned long e) {}
+static inline int swsusp_page_is_forbidden(struct page *p) { return 0; }
+static inline void swsusp_set_page_free(struct page *p) {}
+static inline void swsusp_unset_page_free(struct page *p) {}
+#endif /* defined(CONFIG_PM) && defined(CONFIG_SOFTWARE_SUSPEND) */
 
 void save_processor_state(void);
 void restore_processor_state(void);
 struct saved_context;
 void __save_processor_state(struct saved_context *ctxt);
 void __restore_processor_state(struct saved_context *ctxt);
-unsigned long get_safe_page(gfp_t gfp_mask);
-
-/* Page management functions for the software suspend (swsusp) */
-
-static inline void swsusp_set_page_forbidden(struct page *page)
-{
-	SetPageNosave(page);
-}
-
-static inline int swsusp_page_is_forbidden(struct page *page)
-{
-	return PageNosave(page);
-}
-
-static inline void swsusp_unset_page_forbidden(struct page *page)
-{
-	ClearPageNosave(page);
-}
-
-static inline void swsusp_set_page_free(struct page *page)
-{
-	SetPageNosaveFree(page);
-}
-
-static inline int swsusp_page_is_free(struct page *page)
-{
-	return PageNosaveFree(page);
-}
-
-static inline void swsusp_unset_page_free(struct page *page)
-{
-	ClearPageNosaveFree(page);
-}
 
 /*
  * XXX: We try to keep some more pages free so that I/O operations succeed
Index: linux-2.6.21-rc3/kernel/power/snapshot.c
===================================================================
--- linux-2.6.21-rc3.orig/kernel/power/snapshot.c
+++ linux-2.6.21-rc3/kernel/power/snapshot.c
@@ -21,6 +21,7 @@
 #include <linux/kernel.h>
 #include <linux/pm.h>
 #include <linux/device.h>
+#include <linux/init.h>
 #include <linux/bootmem.h>
 #include <linux/syscalls.h>
 #include <linux/console.h>
@@ -34,6 +35,10 @@
 
 #include "power.h"
 
+static int swsusp_page_is_free(struct page *);
+static void swsusp_set_page_forbidden(struct page *);
+static void swsusp_unset_page_forbidden(struct page *);
+
 /* List of PBEs needed for restoring the pages that were allocated before
  * the suspend and included in the suspend image, but have also been
  * allocated by the "resume" kernel, so their contents cannot be written
@@ -224,11 +229,6 @@ static void chain_free(struct chain_allo
  *	of type unsigned long each).  It also contains the pfns that
  *	correspond to the start and end of the represented memory area and
  *	the number of bit chunks in the block.
- *
- *	NOTE: Memory bitmaps are used for two types of operations only:
- *	"set a bit" and "find the next bit set".  Moreover, the searching
- *	is always carried out after all of the "set a bit" operations
- *	on given bitmap.
  */
 
 #define BM_END_OF_MAP	(~0UL)
@@ -443,15 +443,13 @@ static void memory_bm_free(struct memory
 }
 
 /**
- *	memory_bm_set_bit - set the bit in the bitmap @bm that corresponds
+ *	memory_bm_find_bit - find the bit in the bitmap @bm that corresponds
  *	to given pfn.  The cur_zone_bm member of @bm and the cur_block member
  *	of @bm->cur_zone_bm are updated.
- *
- *	If the bit cannot be set, the function returns -EINVAL .
  */
 
-static int
-memory_bm_set_bit(struct memory_bitmap *bm, unsigned long pfn)
+static void memory_bm_find_bit(struct memory_bitmap *bm, unsigned long pfn,
+				void **addr, unsigned int *bit_nr)
 {
 	struct zone_bitmap *zone_bm;
 	struct bm_block *bb;
@@ -463,8 +461,8 @@ memory_bm_set_bit(struct memory_bitmap *
 		/* We don't assume that the zones are sorted by pfns */
 		while (pfn < zone_bm->start_pfn || pfn >= zone_bm->end_pfn) {
 			zone_bm = zone_bm->next;
-			if (unlikely(!zone_bm))
-				return -EINVAL;
+
+			BUG_ON(!zone_bm);
 		}
 		bm->cur.zone_bm = zone_bm;
 	}
@@ -475,13 +473,40 @@ memory_bm_set_bit(struct memory_bitmap *
 
 	while (pfn >= bb->end_pfn) {
 		bb = bb->next;
-		if (unlikely(!bb))
-			return -EINVAL;
+
+		BUG_ON(!bb);
 	}
 	zone_bm->cur_block = bb;
 	pfn -= bb->start_pfn;
-	set_bit(pfn % BM_BITS_PER_CHUNK, bb->data + pfn / BM_BITS_PER_CHUNK);
-	return 0;
+	*bit_nr = pfn % BM_BITS_PER_CHUNK;
+	*addr = bb->data + pfn / BM_BITS_PER_CHUNK;
+}
+
+static void memory_bm_set_bit(struct memory_bitmap *bm, unsigned long pfn)
+{
+	void *addr;
+	unsigned int bit;
+
+	memory_bm_find_bit(bm, pfn, &addr, &bit);
+	set_bit(bit, addr);
+}
+
+static void memory_bm_clear_bit(struct memory_bitmap *bm, unsigned long pfn)
+{
+	void *addr;
+	unsigned int bit;
+
+	memory_bm_find_bit(bm, pfn, &addr, &bit);
+	clear_bit(bit, addr);
+}
+
+static int memory_bm_test_bit(struct memory_bitmap *bm, unsigned long pfn)
+{
+	void *addr;
+	unsigned int bit;
+
+	memory_bm_find_bit(bm, pfn, &addr, &bit);
+	return test_bit(bit, addr);
 }
 
 /* Two auxiliary functions for memory_bm_next_pfn */
@@ -564,6 +589,199 @@ static unsigned long memory_bm_next_pfn(
 }
 
 /**
+ *	This structure represents a range of page frames the contents of which
+ *	should not be saved during the suspend.
+ */
+
+struct nosave_region {
+	struct list_head list;
+	unsigned long start_pfn;
+	unsigned long end_pfn;
+};
+
+static LIST_HEAD(nosave_regions);
+
+/**
+ *	register_nosave_region - register a range of page frames the contents
+ *	of which should not be saved during the suspend (to be used in the early
+ *	initializatoion code)
+ */
+
+void __init
+register_nosave_region(unsigned long start_pfn, unsigned long end_pfn)
+{
+	struct nosave_region *region;
+
+	if (start_pfn >= end_pfn)
+		return;
+
+	if (!list_empty(&nosave_regions)) {
+		/* Try to extend the previous region (they should be sorted) */
+		region = list_entry(nosave_regions.prev,
+					struct nosave_region, list);
+		if (region->end_pfn == start_pfn) {
+			region->end_pfn = end_pfn;
+			goto Report;
+		}
+	}
+	/* This allocation cannot fail */
+	region = alloc_bootmem_low(sizeof(struct nosave_region));
+	region->start_pfn = start_pfn;
+	region->end_pfn = end_pfn;
+	list_add_tail(&region->list, &nosave_regions);
+ Report:
+	printk("swsusp: Registered nosave memory region: %016lx - %016lx\n",
+		start_pfn << PAGE_SHIFT, end_pfn << PAGE_SHIFT);
+}
+
+/*
+ * Set bits in this map correspond to the page frames the contents of which
+ * should not be saved during the suspend.
+ */
+static struct memory_bitmap *forbidden_pages_map;
+
+/* Set bits in this map correspond to free page frames. */
+static struct memory_bitmap *free_pages_map;
+
+/*
+ * Each page frame allocated for creating the image is marked by setting the
+ * corresponding bits in forbidden_pages_map and free_pages_map simultaneously
+ */
+
+void swsusp_set_page_free(struct page *page)
+{
+	if (free_pages_map)
+		memory_bm_set_bit(free_pages_map, page_to_pfn(page));
+}
+
+static int swsusp_page_is_free(struct page *page)
+{
+	return free_pages_map ?
+		memory_bm_test_bit(free_pages_map, page_to_pfn(page)) : 0;
+}
+
+void swsusp_unset_page_free(struct page *page)
+{
+	if (free_pages_map)
+		memory_bm_clear_bit(free_pages_map, page_to_pfn(page));
+}
+
+static void swsusp_set_page_forbidden(struct page *page)
+{
+	if (forbidden_pages_map)
+		memory_bm_set_bit(forbidden_pages_map, page_to_pfn(page));
+}
+
+int swsusp_page_is_forbidden(struct page *page)
+{
+	return forbidden_pages_map ?
+		memory_bm_test_bit(forbidden_pages_map, page_to_pfn(page)) : 0;
+}
+
+static void swsusp_unset_page_forbidden(struct page *page)
+{
+	if (forbidden_pages_map)
+		memory_bm_clear_bit(forbidden_pages_map, page_to_pfn(page));
+}
+
+/**
+ *	mark_nosave_pages - set bits corresponding to the page frames the
+ *	contents of which should not be saved in a given bitmap.
+ */
+
+static void mark_nosave_pages(struct memory_bitmap *bm)
+{
+	struct nosave_region *region;
+
+	if (list_empty(&nosave_regions))
+		return;
+
+	list_for_each_entry(region, &nosave_regions, list) {
+		unsigned long pfn;
+
+		printk("swsusp: Marking nosave pages: %016lx - %016lx\n",
+				region->start_pfn << PAGE_SHIFT,
+				region->end_pfn << PAGE_SHIFT);
+
+		for (pfn = region->start_pfn; pfn < region->end_pfn; pfn++)
+			memory_bm_set_bit(bm, pfn);
+	}
+}
+
+/**
+ *	create_basic_memory_bitmaps - create bitmaps needed for marking page
+ *	frames that should not be saved and free page frames.  The pointers
+ *	forbidden_pages_map and free_pages_map are only modified if everything
+ *	goes well, because we don't want the bits to be used before both bitmaps
+ *	are set up.
+ */
+
+int create_basic_memory_bitmaps(void)
+{
+	struct memory_bitmap *bm1, *bm2;
+	int error = 0;
+
+	BUG_ON(forbidden_pages_map || free_pages_map);
+
+	bm1 = kzalloc(sizeof(struct memory_bitmap), GFP_ATOMIC);
+	if (!bm1)
+		return -ENOMEM;
+
+	error = memory_bm_create(bm1, GFP_ATOMIC | __GFP_COLD, PG_ANY);
+	if (error)
+		goto Free_first_object;
+
+	bm2 = kzalloc(sizeof(struct memory_bitmap), GFP_ATOMIC);
+	if (!bm2)
+		goto Free_first_bitmap;
+
+	error = memory_bm_create(bm2, GFP_ATOMIC | __GFP_COLD, PG_ANY);
+	if (error)
+		goto Free_second_object;
+
+	forbidden_pages_map = bm1;
+	free_pages_map = bm2;
+	mark_nosave_pages(forbidden_pages_map);
+
+	printk("swsusp: Basic memory bitmaps created\n");
+
+	return 0;
+
+ Free_second_object:
+	kfree(bm2);
+ Free_first_bitmap:
+ 	memory_bm_free(bm1, PG_UNSAFE_CLEAR);
+ Free_first_object:
+	kfree(bm1);
+	return -ENOMEM;
+}
+
+/**
+ *	free_basic_memory_bitmaps - free memory bitmaps allocated by
+ *	create_basic_memory_bitmaps().  The auxiliary pointers are necessary
+ *	so that the bitmaps themselves are not referred to while they are being
+ *	freed.
+ */
+
+void free_basic_memory_bitmaps(void)
+{
+	struct memory_bitmap *bm1, *bm2;
+
+	BUG_ON(!(forbidden_pages_map && free_pages_map));
+
+	bm1 = forbidden_pages_map;
+	bm2 = free_pages_map;
+	forbidden_pages_map = NULL;
+	free_pages_map = NULL;
+	memory_bm_free(bm1, PG_UNSAFE_CLEAR);
+	kfree(bm1);
+	memory_bm_free(bm2, PG_UNSAFE_CLEAR);
+	kfree(bm2);
+
+	printk("swsusp: Basic memory bitmaps freed\n");
+}
+
+/**
  *	snapshot_additional_pages - estimate the number of additional pages
  *	be needed for setting up the suspend image data structures for given
  *	zone (usually the returned value is greater than the exact number)
Index: linux-2.6.21-rc3/arch/x86_64/kernel/e820.c
===================================================================
--- linux-2.6.21-rc3.orig/arch/x86_64/kernel/e820.c
+++ linux-2.6.21-rc3/arch/x86_64/kernel/e820.c
@@ -17,6 +17,8 @@
 #include <linux/kexec.h>
 #include <linux/module.h>
 #include <linux/mm.h>
+#include <linux/suspend.h>
+#include <linux/pfn.h>
 
 #include <asm/pgtable.h>
 #include <asm/page.h>
@@ -255,22 +257,6 @@ void __init e820_reserve_resources(void)
 	}
 }
 
-/* Mark pages corresponding to given address range as nosave */
-static void __init
-e820_mark_nosave_range(unsigned long start, unsigned long end)
-{
-	unsigned long pfn, max_pfn;
-
-	if (start >= end)
-		return;
-
-	printk("Nosave address range: %016lx - %016lx\n", start, end);
-	max_pfn = end >> PAGE_SHIFT;
-	for (pfn = start >> PAGE_SHIFT; pfn < max_pfn; pfn++)
-		if (pfn_valid(pfn))
-			SetPageNosave(pfn_to_page(pfn));
-}
-
 /*
  * Find the ranges of physical addresses that do not correspond to
  * e820 RAM areas and mark the corresponding pages as nosave for software
@@ -289,13 +275,13 @@ void __init e820_mark_nosave_regions(voi
 		struct e820entry *ei = &e820.map[i];
 
 		if (paddr < ei->addr)
-			e820_mark_nosave_range(paddr,
-					round_up(ei->addr, PAGE_SIZE));
+			register_nosave_region(PFN_DOWN(paddr),
+						PFN_UP(ei->addr));
 
 		paddr = round_down(ei->addr + ei->size, PAGE_SIZE);
 		if (ei->type != E820_RAM)
-			e820_mark_nosave_range(round_up(ei->addr, PAGE_SIZE),
-					paddr);
+			register_nosave_region(PFN_UP(ei->addr),
+						PFN_DOWN(paddr));
 
 		if (paddr >= (end_pfn << PAGE_SHIFT))
 			break;
Index: linux-2.6.21-rc3/kernel/power/power.h
===================================================================
--- linux-2.6.21-rc3.orig/kernel/power/power.h
+++ linux-2.6.21-rc3/kernel/power/power.h
@@ -49,6 +49,8 @@ extern sector_t swsusp_resume_block;
 extern asmlinkage int swsusp_arch_suspend(void);
 extern asmlinkage int swsusp_arch_resume(void);
 
+extern int create_basic_memory_bitmaps(void);
+extern void free_basic_memory_bitmaps(void);
 extern unsigned int count_data_pages(void);
 
 /**
Index: linux-2.6.21-rc3/kernel/power/user.c
===================================================================
--- linux-2.6.21-rc3.orig/kernel/power/user.c
+++ linux-2.6.21-rc3/kernel/power/user.c
@@ -52,6 +52,9 @@ static int snapshot_open(struct inode *i
 	if ((filp->f_flags & O_ACCMODE) == O_RDWR)
 		return -ENOSYS;
 
+	if(create_basic_memory_bitmaps())
+		return -ENOMEM;
+
 	nonseekable_open(inode, filp);
 	data = &snapshot_state;
 	filp->private_data = data;
@@ -77,6 +80,7 @@ static int snapshot_release(struct inode
 	struct snapshot_data *data;
 
 	swsusp_free();
+	free_basic_memory_bitmaps();
 	data = filp->private_data;
 	free_all_swap_pages(data->swap, data->bitmap);
 	free_bitmap(data->bitmap);
Index: linux-2.6.21-rc3/kernel/power/disk.c
===================================================================
--- linux-2.6.21-rc3.orig/kernel/power/disk.c
+++ linux-2.6.21-rc3/kernel/power/disk.c
@@ -127,14 +127,19 @@ int pm_suspend_disk(void)
 		mdelay(5000);
 		goto Thaw;
 	}
+	/* Allocate memory management structures */
+	error = create_basic_memory_bitmaps();
+	if (error)
+		goto Thaw;
+
 	/* Free memory before shutting down devices. */
 	error = swsusp_shrink_memory();
 	if (error)
-		goto Thaw;
+		goto Finish;
 
 	error = platform_prepare();
 	if (error)
-		goto Thaw;
+		goto Finish;
 
 	suspend_console();
 	error = device_suspend(PMSG_FREEZE);
@@ -169,7 +174,7 @@ int pm_suspend_disk(void)
 			power_down(pm_disk_mode);
 		else {
 			swsusp_free();
-			goto Thaw;
+			goto Finish;
 		}
 	} else {
 		pr_debug("PM: Image restored successfully.\n");
@@ -182,6 +187,8 @@ int pm_suspend_disk(void)
 	platform_finish();
 	device_resume();
 	resume_console();
+ Finish:
+	free_basic_memory_bitmaps();
  Thaw:
 	unprepare_processes();
 	return error;
@@ -227,13 +234,15 @@ static int software_resume(void)
 	}
 
 	pr_debug("PM: Checking swsusp image.\n");
-
 	error = swsusp_check();
 	if (error)
-		goto Done;
+		goto Unlock;
 
-	pr_debug("PM: Preparing processes for restore.\n");
+	error = create_basic_memory_bitmaps();
+	if (error)
+		goto Unlock;
 
+	pr_debug("PM: Preparing processes for restore.\n");
 	error = prepare_processes();
 	if (error) {
 		swsusp_close();
@@ -275,7 +284,9 @@ static int software_resume(void)
 	printk(KERN_ERR "PM: Restore failed, recovering.\n");
 	unprepare_processes();
  Done:
+	free_basic_memory_bitmaps();
 	/* For success case, the suspend path will release the lock */
+ Unlock:
 	mutex_unlock(&pm_mutex);
 	pr_debug("PM: Resume from disk failed.\n");
 	return 0;


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

* [PATCH 3/3] mm: Remove unused page flags
  2007-03-12 21:14 [PATCH 0/3] swsusp: Stop using page flags Rafael J. Wysocki
  2007-03-12 21:16 ` [PATCH 1/3] swsusp: Use inline functions for changing " Rafael J. Wysocki
  2007-03-12 21:19 ` [PATCH 2/3] swsusp: Do not use " Rafael J. Wysocki
@ 2007-03-12 21:20 ` Rafael J. Wysocki
  2 siblings, 0 replies; 24+ messages in thread
From: Rafael J. Wysocki @ 2007-03-12 21:20 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Pavel Machek, Peter Zijlstra, LKML

From: Rafael J. Wysocki <rjw@sisk.pl>

Remove the two page flags that were previously used by swsusp and are no longer
needed.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Pavel Machek <pavel@ucw.cz>
---
 include/linux/page-flags.h |   12 ------------
 1 file changed, 12 deletions(-)

Index: linux-2.6.21-rc3/include/linux/page-flags.h
===================================================================
--- linux-2.6.21-rc3.orig/include/linux/page-flags.h
+++ linux-2.6.21-rc3/include/linux/page-flags.h
@@ -82,13 +82,11 @@
 #define PG_private		11	/* If pagecache, has fs-private data */
 
 #define PG_writeback		12	/* Page is under writeback */
-#define PG_nosave		13	/* Used for system suspend/resume */
 #define PG_compound		14	/* Part of a compound page */
 #define PG_swapcache		15	/* Swap page: swp_entry_t in private */
 
 #define PG_mappedtodisk		16	/* Has blocks allocated on-disk */
 #define PG_reclaim		17	/* To be reclaimed asap */
-#define PG_nosave_free		18	/* Used for system suspend/resume */
 #define PG_buddy		19	/* Page is free, on buddy lists */
 
 /* PG_owner_priv_1 users should have descriptive aliases */
@@ -214,16 +212,6 @@ static inline void SetPageUptodate(struc
 		ret;							\
 	})
 
-#define PageNosave(page)	test_bit(PG_nosave, &(page)->flags)
-#define SetPageNosave(page)	set_bit(PG_nosave, &(page)->flags)
-#define TestSetPageNosave(page)	test_and_set_bit(PG_nosave, &(page)->flags)
-#define ClearPageNosave(page)		clear_bit(PG_nosave, &(page)->flags)
-#define TestClearPageNosave(page)	test_and_clear_bit(PG_nosave, &(page)->flags)
-
-#define PageNosaveFree(page)	test_bit(PG_nosave_free, &(page)->flags)
-#define SetPageNosaveFree(page)	set_bit(PG_nosave_free, &(page)->flags)
-#define ClearPageNosaveFree(page)		clear_bit(PG_nosave_free, &(page)->flags)
-
 #define PageBuddy(page)		test_bit(PG_buddy, &(page)->flags)
 #define __SetPageBuddy(page)	__set_bit(PG_buddy, &(page)->flags)
 #define __ClearPageBuddy(page)	__clear_bit(PG_buddy, &(page)->flags)

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

* Re: [PATCH 2/3] swsusp: Do not use page flags
  2007-03-12 21:19 ` [PATCH 2/3] swsusp: Do not use " Rafael J. Wysocki
@ 2007-03-15 19:08   ` Andrew Morton
  2007-03-15 21:05     ` Rafael J. Wysocki
  2007-03-20  0:31   ` Andrew Morton
  1 sibling, 1 reply; 24+ messages in thread
From: Andrew Morton @ 2007-03-15 19:08 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: pavel, a.p.zijlstra, linux-kernel

> On Mon, 12 Mar 2007 22:19:20 +0100 "Rafael J. Wysocki" <rjw@sisk.pl> wrote:
> +int create_basic_memory_bitmaps(void)
> +{
> +	struct memory_bitmap *bm1, *bm2;
> +	int error = 0;
> +
> +	BUG_ON(forbidden_pages_map || free_pages_map);
> +
> +	bm1 = kzalloc(sizeof(struct memory_bitmap), GFP_ATOMIC);
> +	if (!bm1)
> +		return -ENOMEM;
> +
> +	error = memory_bm_create(bm1, GFP_ATOMIC | __GFP_COLD, PG_ANY);
> +	if (error)
> +		goto Free_first_object;
> +
> +	bm2 = kzalloc(sizeof(struct memory_bitmap), GFP_ATOMIC);
> +	if (!bm2)
> +		goto Free_first_bitmap;
> +
> +	error = memory_bm_create(bm2, GFP_ATOMIC | __GFP_COLD, PG_ANY);
> +	if (error)

What is the risk that we'll go OOM here?  GFP_ATOMIC is rather unreliable.

And why _does_ suspend use GFP_ATOMIC all over the place?

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

* Re: [PATCH 2/3] swsusp: Do not use page flags
  2007-03-15 19:08   ` Andrew Morton
@ 2007-03-15 21:05     ` Rafael J. Wysocki
  2007-03-15 21:29       ` Andrew Morton
  0 siblings, 1 reply; 24+ messages in thread
From: Rafael J. Wysocki @ 2007-03-15 21:05 UTC (permalink / raw)
  To: Andrew Morton; +Cc: pavel, a.p.zijlstra, linux-kernel

On Thursday, 15 March 2007 20:08, Andrew Morton wrote:
> > On Mon, 12 Mar 2007 22:19:20 +0100 "Rafael J. Wysocki" <rjw@sisk.pl> wrote:
> > +int create_basic_memory_bitmaps(void)
> > +{
> > +	struct memory_bitmap *bm1, *bm2;
> > +	int error = 0;
> > +
> > +	BUG_ON(forbidden_pages_map || free_pages_map);
> > +
> > +	bm1 = kzalloc(sizeof(struct memory_bitmap), GFP_ATOMIC);
> > +	if (!bm1)
> > +		return -ENOMEM;
> > +
> > +	error = memory_bm_create(bm1, GFP_ATOMIC | __GFP_COLD, PG_ANY);
> > +	if (error)
> > +		goto Free_first_object;
> > +
> > +	bm2 = kzalloc(sizeof(struct memory_bitmap), GFP_ATOMIC);
> > +	if (!bm2)
> > +		goto Free_first_bitmap;
> > +
> > +	error = memory_bm_create(bm2, GFP_ATOMIC | __GFP_COLD, PG_ANY);
> > +	if (error)
> 
> What is the risk that we'll go OOM here?  GFP_ATOMIC is rather unreliable.

Well, this can be called after processes (including kswapd) has been frozen.
We can't go to sleep at this point.

> And why _does_ suspend use GFP_ATOMIC all over the place?

Generally, because it cannot sleep.

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

* Re: [PATCH 2/3] swsusp: Do not use page flags
  2007-03-15 21:05     ` Rafael J. Wysocki
@ 2007-03-15 21:29       ` Andrew Morton
  2007-03-15 22:19         ` Jiri Kosina
  2007-03-15 23:05         ` Pavel Machek
  0 siblings, 2 replies; 24+ messages in thread
From: Andrew Morton @ 2007-03-15 21:29 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: pavel, a.p.zijlstra, linux-kernel

On Thu, 15 Mar 2007 22:05:53 +0100
"Rafael J. Wysocki" <rjw@sisk.pl> wrote:

> On Thursday, 15 March 2007 20:08, Andrew Morton wrote:
> > > On Mon, 12 Mar 2007 22:19:20 +0100 "Rafael J. Wysocki" <rjw@sisk.pl> wrote:
> > > +int create_basic_memory_bitmaps(void)
> > > +{
> > > +	struct memory_bitmap *bm1, *bm2;
> > > +	int error = 0;
> > > +
> > > +	BUG_ON(forbidden_pages_map || free_pages_map);
> > > +
> > > +	bm1 = kzalloc(sizeof(struct memory_bitmap), GFP_ATOMIC);
> > > +	if (!bm1)
> > > +		return -ENOMEM;
> > > +
> > > +	error = memory_bm_create(bm1, GFP_ATOMIC | __GFP_COLD, PG_ANY);
> > > +	if (error)
> > > +		goto Free_first_object;
> > > +
> > > +	bm2 = kzalloc(sizeof(struct memory_bitmap), GFP_ATOMIC);
> > > +	if (!bm2)
> > > +		goto Free_first_bitmap;
> > > +
> > > +	error = memory_bm_create(bm2, GFP_ATOMIC | __GFP_COLD, PG_ANY);
> > > +	if (error)
> > 
> > What is the risk that we'll go OOM here?  GFP_ATOMIC is rather unreliable.
> 
> Well, this can be called after processes (including kswapd) has been frozen.
> We can't go to sleep at this point.

So it _is_ unreliable?

> > And why _does_ suspend use GFP_ATOMIC all over the place?
> 
> Generally, because it cannot sleep.

Why not?

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

* Re: [PATCH 2/3] swsusp: Do not use page flags
  2007-03-15 21:29       ` Andrew Morton
@ 2007-03-15 22:19         ` Jiri Kosina
  2007-03-15 22:23           ` Andrew Morton
  2007-03-15 23:05         ` Pavel Machek
  1 sibling, 1 reply; 24+ messages in thread
From: Jiri Kosina @ 2007-03-15 22:19 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Rafael J. Wysocki, Pavel Machek, a.p.zijlstra, linux-kernel

On Thu, 15 Mar 2007, Andrew Morton wrote:

> > > And why _does_ suspend use GFP_ATOMIC all over the place?
> > Generally, because it cannot sleep.
> Why not?

I guess it's simply beucase of kswapd being already frozen, so there is no 
chance that once GFP_KERNEL allocation goes to sleep, it is going to get 
any free pages eventually ... ?

-- 
Jiri Kosina

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

* Re: [PATCH 2/3] swsusp: Do not use page flags
  2007-03-15 22:19         ` Jiri Kosina
@ 2007-03-15 22:23           ` Andrew Morton
  2007-03-16  0:01             ` Rafael J. Wysocki
  0 siblings, 1 reply; 24+ messages in thread
From: Andrew Morton @ 2007-03-15 22:23 UTC (permalink / raw)
  To: Jiri Kosina; +Cc: Rafael J. Wysocki, Pavel Machek, a.p.zijlstra, linux-kernel

On Thu, 15 Mar 2007 23:19:02 +0100 (CET)
Jiri Kosina <jikos@jikos.cz> wrote:

> On Thu, 15 Mar 2007, Andrew Morton wrote:
> 
> > > > And why _does_ suspend use GFP_ATOMIC all over the place?
> > > Generally, because it cannot sleep.
> > Why not?
> 
> I guess it's simply beucase of kswapd being already frozen, so there is no 
> chance that once GFP_KERNEL allocation goes to sleep, it is going to get 
> any free pages eventually ... ?

No, things should run fine with a dead kswapd.

There are reasons why we can't call into filesystems from there, but
GFP_NOIO will ensure that and it is heaps better than GFP_ATOMIC.




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

* Re: [PATCH 2/3] swsusp: Do not use page flags
  2007-03-15 21:29       ` Andrew Morton
  2007-03-15 22:19         ` Jiri Kosina
@ 2007-03-15 23:05         ` Pavel Machek
  1 sibling, 0 replies; 24+ messages in thread
From: Pavel Machek @ 2007-03-15 23:05 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Rafael J. Wysocki, a.p.zijlstra, linux-kernel

Hi!

> > > > On Mon, 12 Mar 2007 22:19:20 +0100 "Rafael J. Wysocki" <rjw@sisk.pl> wrote:
> > > > +int create_basic_memory_bitmaps(void)
> > > > +{
> > > > +	struct memory_bitmap *bm1, *bm2;
> > > > +	int error = 0;
> > > > +
> > > > +	BUG_ON(forbidden_pages_map || free_pages_map);
> > > > +
> > > > +	bm1 = kzalloc(sizeof(struct memory_bitmap), GFP_ATOMIC);
> > > > +	if (!bm1)
> > > > +		return -ENOMEM;
> > > > +
> > > > +	error = memory_bm_create(bm1, GFP_ATOMIC | __GFP_COLD, PG_ANY);
> > > > +	if (error)
> > > > +		goto Free_first_object;
> > > > +
> > > > +	bm2 = kzalloc(sizeof(struct memory_bitmap), GFP_ATOMIC);
> > > > +	if (!bm2)
> > > > +		goto Free_first_bitmap;
> > > > +
> > > > +	error = memory_bm_create(bm2, GFP_ATOMIC | __GFP_COLD, PG_ANY);
> > > > +	if (error)
> > > 
> > > What is the risk that we'll go OOM here?  GFP_ATOMIC is rather unreliable.
> > 
> > Well, this can be called after processes (including kswapd) has been frozen.
> > We can't go to sleep at this point.
> 
> So it _is_ unreliable?

We are careful to leave some memory aside for suspend... We actually
free memory at beggining of suspend, and there's some simple "add few
percent for our overhead" there.
									Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

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

* Re: [PATCH 2/3] swsusp: Do not use page flags
  2007-03-15 22:23           ` Andrew Morton
@ 2007-03-16  0:01             ` Rafael J. Wysocki
  0 siblings, 0 replies; 24+ messages in thread
From: Rafael J. Wysocki @ 2007-03-16  0:01 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Jiri Kosina, Pavel Machek, a.p.zijlstra, linux-kernel

On Thursday, 15 March 2007 23:23, Andrew Morton wrote:
> On Thu, 15 Mar 2007 23:19:02 +0100 (CET)
> Jiri Kosina <jikos@jikos.cz> wrote:
> 
> > On Thu, 15 Mar 2007, Andrew Morton wrote:
> > 
> > > > > And why _does_ suspend use GFP_ATOMIC all over the place?
> > > > Generally, because it cannot sleep.
> > > Why not?
> > 
> > I guess it's simply beucase of kswapd being already frozen, so there is no 
> > chance that once GFP_KERNEL allocation goes to sleep, it is going to get 
> > any free pages eventually ... ?
> 
> No, things should run fine with a dead kswapd.
> 
> There are reasons why we can't call into filesystems from there, but
> GFP_NOIO will ensure that and it is heaps better than GFP_ATOMIC.

In fact the role of swsusp_shrink_memory() is to ensure that our subsequent
atomic allocations won't fail.

Still, the particular allocations in create_basic_memory_bitmaps() are made
before we call swsusp_shrink_memory(), so it's better to use GFP_NOIO in there.

I'll prepare a patch for that on top of the current series.

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

* Re: [PATCH 2/3] swsusp: Do not use page flags
  2007-03-12 21:19 ` [PATCH 2/3] swsusp: Do not use " Rafael J. Wysocki
  2007-03-15 19:08   ` Andrew Morton
@ 2007-03-20  0:31   ` Andrew Morton
  2007-03-20 13:18     ` Pavel Machek
  2007-03-20 21:18     ` Rafael J. Wysocki
  1 sibling, 2 replies; 24+ messages in thread
From: Andrew Morton @ 2007-03-20  0:31 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: Pavel Machek, Peter Zijlstra, LKML

On Mon, 12 Mar 2007 22:19:20 +0100
"Rafael J. Wysocki" <rjw@sisk.pl> wrote:

> Make swsusp use memory bitmaps instead of page flags for marking 'nosave' and
> free pages.  This allows us to 'recycle' two page flags that can be used for other
> purposes.  Also, the memory needed to store the bitmaps is allocated when
> necessary (ie. before the suspend) and freed after the resume which is more
> reasonable.
> 
> The patch is designed to minimize the amount of changes and there are some nice
> simplifications and optimizations possible on top of it.  I am going to
> implement them separately in the future.

Blows up with ia64 allmodconfig due to CONFIG_PM=y, CONFIG_SOFTWARE_SUSPEND=n:

kernel/power/main.c:223: error: redefinition of 'software_suspend'
include/linux/suspend.h:46: error: previous definition of 'software_suspend' was here

I had a look at fixing it, but it's unobvious why we're compiling most of
kernel/power/main.c when CONFIG_SOFTWARE_SUSPEND=n so I'll send this series
back for repair please.

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

* Re: [PATCH 2/3] swsusp: Do not use page flags
  2007-03-20  0:31   ` Andrew Morton
@ 2007-03-20 13:18     ` Pavel Machek
  2007-03-20 21:18     ` Rafael J. Wysocki
  1 sibling, 0 replies; 24+ messages in thread
From: Pavel Machek @ 2007-03-20 13:18 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Rafael J. Wysocki, Peter Zijlstra, LKML

Hi!

> > The patch is designed to minimize the amount of changes and there are some nice
> > simplifications and optimizations possible on top of it.  I am going to
> > implement them separately in the future.
> 
> Blows up with ia64 allmodconfig due to CONFIG_PM=y, CONFIG_SOFTWARE_SUSPEND=n:
> 
> kernel/power/main.c:223: error: redefinition of 'software_suspend'
> include/linux/suspend.h:46: error: previous definition of 'software_suspend' was here
> 
> I had a look at fixing it, but it's unobvious why we're compiling most of
> kernel/power/main.c when CONFIG_SOFTWARE_SUSPEND=n so I'll send this series
> back for repair please.

main.c is needed for suspend-to-ram, too.
									Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

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

* Re: [PATCH 2/3] swsusp: Do not use page flags
  2007-03-20  0:31   ` Andrew Morton
  2007-03-20 13:18     ` Pavel Machek
@ 2007-03-20 21:18     ` Rafael J. Wysocki
  2007-03-20 21:20       ` [PATCH 1/5] swsusp: Use inline functions for changing " Rafael J. Wysocki
                         ` (4 more replies)
  1 sibling, 5 replies; 24+ messages in thread
From: Rafael J. Wysocki @ 2007-03-20 21:18 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Pavel Machek, Peter Zijlstra, LKML

On Tuesday, 20 March 2007 01:31, Andrew Morton wrote:
> On Mon, 12 Mar 2007 22:19:20 +0100
> "Rafael J. Wysocki" <rjw@sisk.pl> wrote:
> 
> > Make swsusp use memory bitmaps instead of page flags for marking 'nosave' and
> > free pages.  This allows us to 'recycle' two page flags that can be used for other
> > purposes.  Also, the memory needed to store the bitmaps is allocated when
> > necessary (ie. before the suspend) and freed after the resume which is more
> > reasonable.
> > 
> > The patch is designed to minimize the amount of changes and there are some nice
> > simplifications and optimizations possible on top of it.  I am going to
> > implement them separately in the future.
> 
> Blows up with ia64 allmodconfig due to CONFIG_PM=y, CONFIG_SOFTWARE_SUSPEND=n:
> 
> kernel/power/main.c:223: error: redefinition of 'software_suspend'
> include/linux/suspend.h:46: error: previous definition of 'software_suspend' was here
> 
> I had a look at fixing it, but it's unobvious why we're compiling most of
> kernel/power/main.c when CONFIG_SOFTWARE_SUSPEND=n so I'll send this series
> back for repair please.

Well, it was sufficient to add #ifdef CONFIG_SOFTWARE_SUSPEND around the
definition of software_suspend() in kernel/power/main.c.

The following series of patches compiles with CONFIG_SOFTWARE_SUSPEND=n too.

Greetings,
Rafael


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

* [PATCH 1/5] swsusp: Use inline functions for changing page flags
  2007-03-20 21:18     ` Rafael J. Wysocki
@ 2007-03-20 21:20       ` Rafael J. Wysocki
  2007-03-20 21:22       ` [PATCH 2/5] swsusp: do not use " Rafael J. Wysocki
                         ` (3 subsequent siblings)
  4 siblings, 0 replies; 24+ messages in thread
From: Rafael J. Wysocki @ 2007-03-20 21:20 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Pavel Machek, Peter Zijlstra, LKML

From: Rafael J. Wysocki <rjw@sisk.pl>

Replace direct invocations of SetPageNosave(), SetPageNosaveFree() etc. with
calls to inline functions that can be changed in subsequent patches without
modifying the code calling them.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Pavel Machek <pavel@ucw.cz>
---
 include/linux/suspend.h |   33 +++++++++++++++++++++++++++++++++
 kernel/power/snapshot.c |   48 +++++++++++++++++++++++++-----------------------
 mm/page_alloc.c         |    6 +++---
 3 files changed, 61 insertions(+), 26 deletions(-)

Index: linux-2.6.21-rc4-mm1/include/linux/suspend.h
===================================================================
--- linux-2.6.21-rc4-mm1.orig/include/linux/suspend.h	2007-02-04 19:44:54.000000000 +0100
+++ linux-2.6.21-rc4-mm1/include/linux/suspend.h	2007-03-20 21:03:20.000000000 +0100
@@ -8,6 +8,7 @@
 #include <linux/notifier.h>
 #include <linux/init.h>
 #include <linux/pm.h>
+#include <linux/mm.h>
 
 /* struct pbe is used for creating lists of pages that should be restored
  * atomically during the resume from disk, because the page frames they have
@@ -49,6 +50,38 @@ void __save_processor_state(struct saved
 void __restore_processor_state(struct saved_context *ctxt);
 unsigned long get_safe_page(gfp_t gfp_mask);
 
+/* Page management functions for the software suspend (swsusp) */
+
+static inline void swsusp_set_page_forbidden(struct page *page)
+{
+	SetPageNosave(page);
+}
+
+static inline int swsusp_page_is_forbidden(struct page *page)
+{
+	return PageNosave(page);
+}
+
+static inline void swsusp_unset_page_forbidden(struct page *page)
+{
+	ClearPageNosave(page);
+}
+
+static inline void swsusp_set_page_free(struct page *page)
+{
+	SetPageNosaveFree(page);
+}
+
+static inline int swsusp_page_is_free(struct page *page)
+{
+	return PageNosaveFree(page);
+}
+
+static inline void swsusp_unset_page_free(struct page *page)
+{
+	ClearPageNosaveFree(page);
+}
+
 /*
  * XXX: We try to keep some more pages free so that I/O operations succeed
  * without paging. Might this be more?
Index: linux-2.6.21-rc4-mm1/kernel/power/snapshot.c
===================================================================
--- linux-2.6.21-rc4-mm1.orig/kernel/power/snapshot.c	2007-03-20 20:57:04.000000000 +0100
+++ linux-2.6.21-rc4-mm1/kernel/power/snapshot.c	2007-03-20 21:03:20.000000000 +0100
@@ -67,15 +67,15 @@ static void *get_image_page(gfp_t gfp_ma
 
 	res = (void *)get_zeroed_page(gfp_mask);
 	if (safe_needed)
-		while (res && PageNosaveFree(virt_to_page(res))) {
+		while (res && swsusp_page_is_free(virt_to_page(res))) {
 			/* The page is unsafe, mark it for swsusp_free() */
-			SetPageNosave(virt_to_page(res));
+			swsusp_set_page_forbidden(virt_to_page(res));
 			allocated_unsafe_pages++;
 			res = (void *)get_zeroed_page(gfp_mask);
 		}
 	if (res) {
-		SetPageNosave(virt_to_page(res));
-		SetPageNosaveFree(virt_to_page(res));
+		swsusp_set_page_forbidden(virt_to_page(res));
+		swsusp_set_page_free(virt_to_page(res));
 	}
 	return res;
 }
@@ -91,8 +91,8 @@ static struct page *alloc_image_page(gfp
 
 	page = alloc_page(gfp_mask);
 	if (page) {
-		SetPageNosave(page);
-		SetPageNosaveFree(page);
+		swsusp_set_page_forbidden(page);
+		swsusp_set_page_free(page);
 	}
 	return page;
 }
@@ -110,9 +110,9 @@ static inline void free_image_page(void 
 
 	page = virt_to_page(addr);
 
-	ClearPageNosave(page);
+	swsusp_unset_page_forbidden(page);
 	if (clear_nosave_free)
-		ClearPageNosaveFree(page);
+		swsusp_unset_page_free(page);
 
 	__free_page(page);
 }
@@ -615,7 +615,8 @@ static struct page *saveable_highmem_pag
 
 	BUG_ON(!PageHighMem(page));
 
-	if (PageNosave(page) || PageReserved(page) || PageNosaveFree(page))
+	if (swsusp_page_is_forbidden(page) ||  swsusp_page_is_free(page) ||
+	    PageReserved(page))
 		return NULL;
 
 	return page;
@@ -681,7 +682,7 @@ static struct page *saveable_page(unsign
 
 	BUG_ON(PageHighMem(page));
 
-	if (PageNosave(page) || PageNosaveFree(page))
+	if (swsusp_page_is_forbidden(page) || swsusp_page_is_free(page))
 		return NULL;
 
 	if (PageReserved(page) && pfn_is_nosave(pfn))
@@ -821,9 +822,10 @@ void swsusp_free(void)
 			if (pfn_valid(pfn)) {
 				struct page *page = pfn_to_page(pfn);
 
-				if (PageNosave(page) && PageNosaveFree(page)) {
-					ClearPageNosave(page);
-					ClearPageNosaveFree(page);
+				if (swsusp_page_is_forbidden(page) &&
+				    swsusp_page_is_free(page)) {
+					swsusp_unset_page_forbidden(page);
+					swsusp_unset_page_free(page);
 					__free_page(page);
 				}
 			}
@@ -1146,7 +1148,7 @@ static int mark_unsafe_pages(struct memo
 		max_zone_pfn = zone->zone_start_pfn + zone->spanned_pages;
 		for (pfn = zone->zone_start_pfn; pfn < max_zone_pfn; pfn++)
 			if (pfn_valid(pfn))
-				ClearPageNosaveFree(pfn_to_page(pfn));
+				swsusp_unset_page_free(pfn_to_page(pfn));
 	}
 
 	/* Mark pages that correspond to the "original" pfns as "unsafe" */
@@ -1155,7 +1157,7 @@ static int mark_unsafe_pages(struct memo
 		pfn = memory_bm_next_pfn(bm);
 		if (likely(pfn != BM_END_OF_MAP)) {
 			if (likely(pfn_valid(pfn)))
-				SetPageNosaveFree(pfn_to_page(pfn));
+				swsusp_set_page_free(pfn_to_page(pfn));
 			else
 				return -EFAULT;
 		}
@@ -1321,14 +1323,14 @@ prepare_highmem_image(struct memory_bitm
 		struct page *page;
 
 		page = alloc_page(__GFP_HIGHMEM);
-		if (!PageNosaveFree(page)) {
+		if (!swsusp_page_is_free(page)) {
 			/* The page is "safe", set its bit the bitmap */
 			memory_bm_set_bit(bm, page_to_pfn(page));
 			safe_highmem_pages++;
 		}
 		/* Mark the page as allocated */
-		SetPageNosave(page);
-		SetPageNosaveFree(page);
+		swsusp_set_page_forbidden(page);
+		swsusp_set_page_free(page);
 	}
 	memory_bm_position_reset(bm);
 	safe_highmem_bm = bm;
@@ -1360,7 +1362,7 @@ get_highmem_page_buffer(struct page *pag
 	struct highmem_pbe *pbe;
 	void *kaddr;
 
-	if (PageNosave(page) && PageNosaveFree(page)) {
+	if (swsusp_page_is_forbidden(page) && swsusp_page_is_free(page)) {
 		/* We have allocated the "original" page frame and we can
 		 * use it directly to store the loaded page.
 		 */
@@ -1522,14 +1524,14 @@ prepare_image(struct memory_bitmap *new_
 			error = -ENOMEM;
 			goto Free;
 		}
-		if (!PageNosaveFree(virt_to_page(lp))) {
+		if (!swsusp_page_is_free(virt_to_page(lp))) {
 			/* The page is "safe", add it to the list */
 			lp->next = safe_pages_list;
 			safe_pages_list = lp;
 		}
 		/* Mark the page as allocated */
-		SetPageNosave(virt_to_page(lp));
-		SetPageNosaveFree(virt_to_page(lp));
+		swsusp_set_page_forbidden(virt_to_page(lp));
+		swsusp_set_page_free(virt_to_page(lp));
 		nr_pages--;
 	}
 	/* Free the reserved safe pages so that chain_alloc() can use them */
@@ -1558,7 +1560,7 @@ static void *get_buffer(struct memory_bi
 	if (PageHighMem(page))
 		return get_highmem_page_buffer(page, ca);
 
-	if (PageNosave(page) && PageNosaveFree(page))
+	if (swsusp_page_is_forbidden(page) && swsusp_page_is_free(page))
 		/* We have allocated the "original" page frame and we can
 		 * use it directly to store the loaded page.
 		 */
Index: linux-2.6.21-rc4-mm1/mm/page_alloc.c
===================================================================
--- linux-2.6.21-rc4-mm1.orig/mm/page_alloc.c	2007-03-20 20:58:46.000000000 +0100
+++ linux-2.6.21-rc4-mm1/mm/page_alloc.c	2007-03-20 21:03:20.000000000 +0100
@@ -1050,8 +1050,8 @@ void mark_free_pages(struct zone *zone)
 		if (pfn_valid(pfn)) {
 			struct page *page = pfn_to_page(pfn);
 
-			if (!PageNosave(page))
-				ClearPageNosaveFree(page);
+			if (!swsusp_page_is_forbidden(page))
+				swsusp_unset_page_free(page);
 		}
 
 	for_each_migratetype_order(order, t) {
@@ -1060,7 +1060,7 @@ void mark_free_pages(struct zone *zone)
 
 			pfn = page_to_pfn(list_entry(curr, struct page, lru));
 			for (i = 0; i < (1UL << order); i++)
-				SetPageNosaveFree(pfn_to_page(pfn + i));
+				swsusp_set_page_free(pfn_to_page(pfn + i));
 		}
 	}
 


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

* [PATCH 2/5] swsusp: do not use page flags
  2007-03-20 21:18     ` Rafael J. Wysocki
  2007-03-20 21:20       ` [PATCH 1/5] swsusp: Use inline functions for changing " Rafael J. Wysocki
@ 2007-03-20 21:22       ` Rafael J. Wysocki
  2007-03-20 21:25       ` [PATCH 3/5] mm: remove unused " Rafael J. Wysocki
                         ` (2 subsequent siblings)
  4 siblings, 0 replies; 24+ messages in thread
From: Rafael J. Wysocki @ 2007-03-20 21:22 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Pavel Machek, Peter Zijlstra, LKML

From: Rafael J. Wysocki <rjw@sisk.pl>

Make swsusp use memory bitmaps instead of page flags for marking 'nosave' and
free pages.  This allows us to 'recycle' two page flags that can be used for
other purposes.  Also, the memory needed to store the bitmaps is allocated
when necessary (ie. before the suspend) and freed after the resume which is
more reasonable.

The patch is designed to minimize the amount of changes and there are some
nice simplifications and optimizations possible on top of it.  I am going to
implement them separately in the future.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Pavel Machek <pavel@ucw.cz>
---
 arch/x86_64/kernel/e820.c |   26 +---
 include/linux/suspend.h   |   58 +++-------
 kernel/power/disk.c       |   23 +++-
 kernel/power/main.c       |    2 
 kernel/power/power.h      |    2 
 kernel/power/snapshot.c   |  250 +++++++++++++++++++++++++++++++++++++++++++---
 kernel/power/user.c       |    4 
 7 files changed, 283 insertions(+), 82 deletions(-)

Index: linux-2.6.21-rc4-mm1/include/linux/suspend.h
===================================================================
--- linux-2.6.21-rc4-mm1.orig/include/linux/suspend.h	2007-03-20 21:04:13.000000000 +0100
+++ linux-2.6.21-rc4-mm1/include/linux/suspend.h	2007-03-20 21:19:31.000000000 +0100
@@ -24,63 +24,41 @@ struct pbe {
 extern void drain_local_pages(void);
 extern void mark_free_pages(struct zone *zone);
 
-#ifdef CONFIG_PM
-/* kernel/power/swsusp.c */
-extern int software_suspend(void);
-
-#if defined(CONFIG_VT) && defined(CONFIG_VT_CONSOLE)
+#if defined(CONFIG_PM) && defined(CONFIG_VT) && defined(CONFIG_VT_CONSOLE)
 extern int pm_prepare_console(void);
 extern void pm_restore_console(void);
 #else
 static inline int pm_prepare_console(void) { return 0; }
 static inline void pm_restore_console(void) {}
-#endif /* defined(CONFIG_VT) && defined(CONFIG_VT_CONSOLE) */
+#endif
+
+#if defined(CONFIG_PM) && defined(CONFIG_SOFTWARE_SUSPEND)
+/* kernel/power/swsusp.c */
+extern int software_suspend(void);
+/* kernel/power/snapshot.c */
+extern void __init register_nosave_region(unsigned long, unsigned long);
+extern int swsusp_page_is_forbidden(struct page *);
+extern void swsusp_set_page_free(struct page *);
+extern void swsusp_unset_page_free(struct page *);
+extern unsigned long get_safe_page(gfp_t gfp_mask);
 #else
 static inline int software_suspend(void)
 {
 	printk("Warning: fake suspend called\n");
 	return -ENOSYS;
 }
-#endif /* CONFIG_PM */
+
+static inline void register_nosave_region(unsigned long b, unsigned long e) {}
+static inline int swsusp_page_is_forbidden(struct page *p) { return 0; }
+static inline void swsusp_set_page_free(struct page *p) {}
+static inline void swsusp_unset_page_free(struct page *p) {}
+#endif /* defined(CONFIG_PM) && defined(CONFIG_SOFTWARE_SUSPEND) */
 
 void save_processor_state(void);
 void restore_processor_state(void);
 struct saved_context;
 void __save_processor_state(struct saved_context *ctxt);
 void __restore_processor_state(struct saved_context *ctxt);
-unsigned long get_safe_page(gfp_t gfp_mask);
-
-/* Page management functions for the software suspend (swsusp) */
-
-static inline void swsusp_set_page_forbidden(struct page *page)
-{
-	SetPageNosave(page);
-}
-
-static inline int swsusp_page_is_forbidden(struct page *page)
-{
-	return PageNosave(page);
-}
-
-static inline void swsusp_unset_page_forbidden(struct page *page)
-{
-	ClearPageNosave(page);
-}
-
-static inline void swsusp_set_page_free(struct page *page)
-{
-	SetPageNosaveFree(page);
-}
-
-static inline int swsusp_page_is_free(struct page *page)
-{
-	return PageNosaveFree(page);
-}
-
-static inline void swsusp_unset_page_free(struct page *page)
-{
-	ClearPageNosaveFree(page);
-}
 
 /*
  * XXX: We try to keep some more pages free so that I/O operations succeed
Index: linux-2.6.21-rc4-mm1/kernel/power/snapshot.c
===================================================================
--- linux-2.6.21-rc4-mm1.orig/kernel/power/snapshot.c	2007-03-20 21:04:13.000000000 +0100
+++ linux-2.6.21-rc4-mm1/kernel/power/snapshot.c	2007-03-20 21:19:31.000000000 +0100
@@ -21,6 +21,7 @@
 #include <linux/kernel.h>
 #include <linux/pm.h>
 #include <linux/device.h>
+#include <linux/init.h>
 #include <linux/bootmem.h>
 #include <linux/syscalls.h>
 #include <linux/console.h>
@@ -34,6 +35,10 @@
 
 #include "power.h"
 
+static int swsusp_page_is_free(struct page *);
+static void swsusp_set_page_forbidden(struct page *);
+static void swsusp_unset_page_forbidden(struct page *);
+
 /* List of PBEs needed for restoring the pages that were allocated before
  * the suspend and included in the suspend image, but have also been
  * allocated by the "resume" kernel, so their contents cannot be written
@@ -224,11 +229,6 @@ static void chain_free(struct chain_allo
  *	of type unsigned long each).  It also contains the pfns that
  *	correspond to the start and end of the represented memory area and
  *	the number of bit chunks in the block.
- *
- *	NOTE: Memory bitmaps are used for two types of operations only:
- *	"set a bit" and "find the next bit set".  Moreover, the searching
- *	is always carried out after all of the "set a bit" operations
- *	on given bitmap.
  */
 
 #define BM_END_OF_MAP	(~0UL)
@@ -443,15 +443,13 @@ static void memory_bm_free(struct memory
 }
 
 /**
- *	memory_bm_set_bit - set the bit in the bitmap @bm that corresponds
+ *	memory_bm_find_bit - find the bit in the bitmap @bm that corresponds
  *	to given pfn.  The cur_zone_bm member of @bm and the cur_block member
  *	of @bm->cur_zone_bm are updated.
- *
- *	If the bit cannot be set, the function returns -EINVAL .
  */
 
-static int
-memory_bm_set_bit(struct memory_bitmap *bm, unsigned long pfn)
+static void memory_bm_find_bit(struct memory_bitmap *bm, unsigned long pfn,
+				void **addr, unsigned int *bit_nr)
 {
 	struct zone_bitmap *zone_bm;
 	struct bm_block *bb;
@@ -463,8 +461,8 @@ memory_bm_set_bit(struct memory_bitmap *
 		/* We don't assume that the zones are sorted by pfns */
 		while (pfn < zone_bm->start_pfn || pfn >= zone_bm->end_pfn) {
 			zone_bm = zone_bm->next;
-			if (unlikely(!zone_bm))
-				return -EINVAL;
+
+			BUG_ON(!zone_bm);
 		}
 		bm->cur.zone_bm = zone_bm;
 	}
@@ -475,13 +473,40 @@ memory_bm_set_bit(struct memory_bitmap *
 
 	while (pfn >= bb->end_pfn) {
 		bb = bb->next;
-		if (unlikely(!bb))
-			return -EINVAL;
+
+		BUG_ON(!bb);
 	}
 	zone_bm->cur_block = bb;
 	pfn -= bb->start_pfn;
-	set_bit(pfn % BM_BITS_PER_CHUNK, bb->data + pfn / BM_BITS_PER_CHUNK);
-	return 0;
+	*bit_nr = pfn % BM_BITS_PER_CHUNK;
+	*addr = bb->data + pfn / BM_BITS_PER_CHUNK;
+}
+
+static void memory_bm_set_bit(struct memory_bitmap *bm, unsigned long pfn)
+{
+	void *addr;
+	unsigned int bit;
+
+	memory_bm_find_bit(bm, pfn, &addr, &bit);
+	set_bit(bit, addr);
+}
+
+static void memory_bm_clear_bit(struct memory_bitmap *bm, unsigned long pfn)
+{
+	void *addr;
+	unsigned int bit;
+
+	memory_bm_find_bit(bm, pfn, &addr, &bit);
+	clear_bit(bit, addr);
+}
+
+static int memory_bm_test_bit(struct memory_bitmap *bm, unsigned long pfn)
+{
+	void *addr;
+	unsigned int bit;
+
+	memory_bm_find_bit(bm, pfn, &addr, &bit);
+	return test_bit(bit, addr);
 }
 
 /* Two auxiliary functions for memory_bm_next_pfn */
@@ -564,6 +589,199 @@ static unsigned long memory_bm_next_pfn(
 }
 
 /**
+ *	This structure represents a range of page frames the contents of which
+ *	should not be saved during the suspend.
+ */
+
+struct nosave_region {
+	struct list_head list;
+	unsigned long start_pfn;
+	unsigned long end_pfn;
+};
+
+static LIST_HEAD(nosave_regions);
+
+/**
+ *	register_nosave_region - register a range of page frames the contents
+ *	of which should not be saved during the suspend (to be used in the early
+ *	initializatoion code)
+ */
+
+void __init
+register_nosave_region(unsigned long start_pfn, unsigned long end_pfn)
+{
+	struct nosave_region *region;
+
+	if (start_pfn >= end_pfn)
+		return;
+
+	if (!list_empty(&nosave_regions)) {
+		/* Try to extend the previous region (they should be sorted) */
+		region = list_entry(nosave_regions.prev,
+					struct nosave_region, list);
+		if (region->end_pfn == start_pfn) {
+			region->end_pfn = end_pfn;
+			goto Report;
+		}
+	}
+	/* This allocation cannot fail */
+	region = alloc_bootmem_low(sizeof(struct nosave_region));
+	region->start_pfn = start_pfn;
+	region->end_pfn = end_pfn;
+	list_add_tail(&region->list, &nosave_regions);
+ Report:
+	printk("swsusp: Registered nosave memory region: %016lx - %016lx\n",
+		start_pfn << PAGE_SHIFT, end_pfn << PAGE_SHIFT);
+}
+
+/*
+ * Set bits in this map correspond to the page frames the contents of which
+ * should not be saved during the suspend.
+ */
+static struct memory_bitmap *forbidden_pages_map;
+
+/* Set bits in this map correspond to free page frames. */
+static struct memory_bitmap *free_pages_map;
+
+/*
+ * Each page frame allocated for creating the image is marked by setting the
+ * corresponding bits in forbidden_pages_map and free_pages_map simultaneously
+ */
+
+void swsusp_set_page_free(struct page *page)
+{
+	if (free_pages_map)
+		memory_bm_set_bit(free_pages_map, page_to_pfn(page));
+}
+
+static int swsusp_page_is_free(struct page *page)
+{
+	return free_pages_map ?
+		memory_bm_test_bit(free_pages_map, page_to_pfn(page)) : 0;
+}
+
+void swsusp_unset_page_free(struct page *page)
+{
+	if (free_pages_map)
+		memory_bm_clear_bit(free_pages_map, page_to_pfn(page));
+}
+
+static void swsusp_set_page_forbidden(struct page *page)
+{
+	if (forbidden_pages_map)
+		memory_bm_set_bit(forbidden_pages_map, page_to_pfn(page));
+}
+
+int swsusp_page_is_forbidden(struct page *page)
+{
+	return forbidden_pages_map ?
+		memory_bm_test_bit(forbidden_pages_map, page_to_pfn(page)) : 0;
+}
+
+static void swsusp_unset_page_forbidden(struct page *page)
+{
+	if (forbidden_pages_map)
+		memory_bm_clear_bit(forbidden_pages_map, page_to_pfn(page));
+}
+
+/**
+ *	mark_nosave_pages - set bits corresponding to the page frames the
+ *	contents of which should not be saved in a given bitmap.
+ */
+
+static void mark_nosave_pages(struct memory_bitmap *bm)
+{
+	struct nosave_region *region;
+
+	if (list_empty(&nosave_regions))
+		return;
+
+	list_for_each_entry(region, &nosave_regions, list) {
+		unsigned long pfn;
+
+		printk("swsusp: Marking nosave pages: %016lx - %016lx\n",
+				region->start_pfn << PAGE_SHIFT,
+				region->end_pfn << PAGE_SHIFT);
+
+		for (pfn = region->start_pfn; pfn < region->end_pfn; pfn++)
+			memory_bm_set_bit(bm, pfn);
+	}
+}
+
+/**
+ *	create_basic_memory_bitmaps - create bitmaps needed for marking page
+ *	frames that should not be saved and free page frames.  The pointers
+ *	forbidden_pages_map and free_pages_map are only modified if everything
+ *	goes well, because we don't want the bits to be used before both bitmaps
+ *	are set up.
+ */
+
+int create_basic_memory_bitmaps(void)
+{
+	struct memory_bitmap *bm1, *bm2;
+	int error = 0;
+
+	BUG_ON(forbidden_pages_map || free_pages_map);
+
+	bm1 = kzalloc(sizeof(struct memory_bitmap), GFP_ATOMIC);
+	if (!bm1)
+		return -ENOMEM;
+
+	error = memory_bm_create(bm1, GFP_ATOMIC | __GFP_COLD, PG_ANY);
+	if (error)
+		goto Free_first_object;
+
+	bm2 = kzalloc(sizeof(struct memory_bitmap), GFP_ATOMIC);
+	if (!bm2)
+		goto Free_first_bitmap;
+
+	error = memory_bm_create(bm2, GFP_ATOMIC | __GFP_COLD, PG_ANY);
+	if (error)
+		goto Free_second_object;
+
+	forbidden_pages_map = bm1;
+	free_pages_map = bm2;
+	mark_nosave_pages(forbidden_pages_map);
+
+	printk("swsusp: Basic memory bitmaps created\n");
+
+	return 0;
+
+ Free_second_object:
+	kfree(bm2);
+ Free_first_bitmap:
+ 	memory_bm_free(bm1, PG_UNSAFE_CLEAR);
+ Free_first_object:
+	kfree(bm1);
+	return -ENOMEM;
+}
+
+/**
+ *	free_basic_memory_bitmaps - free memory bitmaps allocated by
+ *	create_basic_memory_bitmaps().  The auxiliary pointers are necessary
+ *	so that the bitmaps themselves are not referred to while they are being
+ *	freed.
+ */
+
+void free_basic_memory_bitmaps(void)
+{
+	struct memory_bitmap *bm1, *bm2;
+
+	BUG_ON(!(forbidden_pages_map && free_pages_map));
+
+	bm1 = forbidden_pages_map;
+	bm2 = free_pages_map;
+	forbidden_pages_map = NULL;
+	free_pages_map = NULL;
+	memory_bm_free(bm1, PG_UNSAFE_CLEAR);
+	kfree(bm1);
+	memory_bm_free(bm2, PG_UNSAFE_CLEAR);
+	kfree(bm2);
+
+	printk("swsusp: Basic memory bitmaps freed\n");
+}
+
+/**
  *	snapshot_additional_pages - estimate the number of additional pages
  *	be needed for setting up the suspend image data structures for given
  *	zone (usually the returned value is greater than the exact number)
Index: linux-2.6.21-rc4-mm1/arch/x86_64/kernel/e820.c
===================================================================
--- linux-2.6.21-rc4-mm1.orig/arch/x86_64/kernel/e820.c	2007-03-20 20:58:38.000000000 +0100
+++ linux-2.6.21-rc4-mm1/arch/x86_64/kernel/e820.c	2007-03-20 21:19:31.000000000 +0100
@@ -17,6 +17,8 @@
 #include <linux/kexec.h>
 #include <linux/module.h>
 #include <linux/mm.h>
+#include <linux/suspend.h>
+#include <linux/pfn.h>
 
 #include <asm/pgtable.h>
 #include <asm/page.h>
@@ -255,22 +257,6 @@ void __init e820_reserve_resources(void)
 	}
 }
 
-/* Mark pages corresponding to given address range as nosave */
-static void __init
-e820_mark_nosave_range(unsigned long start, unsigned long end)
-{
-	unsigned long pfn, max_pfn;
-
-	if (start >= end)
-		return;
-
-	printk("Nosave address range: %016lx - %016lx\n", start, end);
-	max_pfn = end >> PAGE_SHIFT;
-	for (pfn = start >> PAGE_SHIFT; pfn < max_pfn; pfn++)
-		if (pfn_valid(pfn))
-			SetPageNosave(pfn_to_page(pfn));
-}
-
 /*
  * Find the ranges of physical addresses that do not correspond to
  * e820 RAM areas and mark the corresponding pages as nosave for software
@@ -289,13 +275,13 @@ void __init e820_mark_nosave_regions(voi
 		struct e820entry *ei = &e820.map[i];
 
 		if (paddr < ei->addr)
-			e820_mark_nosave_range(paddr,
-					round_up(ei->addr, PAGE_SIZE));
+			register_nosave_region(PFN_DOWN(paddr),
+						PFN_UP(ei->addr));
 
 		paddr = round_down(ei->addr + ei->size, PAGE_SIZE);
 		if (ei->type != E820_RAM)
-			e820_mark_nosave_range(round_up(ei->addr, PAGE_SIZE),
-					paddr);
+			register_nosave_region(PFN_UP(ei->addr),
+						PFN_DOWN(paddr));
 
 		if (paddr >= (end_pfn << PAGE_SHIFT))
 			break;
Index: linux-2.6.21-rc4-mm1/kernel/power/power.h
===================================================================
--- linux-2.6.21-rc4-mm1.orig/kernel/power/power.h	2007-02-04 19:44:54.000000000 +0100
+++ linux-2.6.21-rc4-mm1/kernel/power/power.h	2007-03-20 21:19:31.000000000 +0100
@@ -49,6 +49,8 @@ extern sector_t swsusp_resume_block;
 extern asmlinkage int swsusp_arch_suspend(void);
 extern asmlinkage int swsusp_arch_resume(void);
 
+extern int create_basic_memory_bitmaps(void);
+extern void free_basic_memory_bitmaps(void);
 extern unsigned int count_data_pages(void);
 
 /**
Index: linux-2.6.21-rc4-mm1/kernel/power/user.c
===================================================================
--- linux-2.6.21-rc4-mm1.orig/kernel/power/user.c	2007-03-20 20:58:46.000000000 +0100
+++ linux-2.6.21-rc4-mm1/kernel/power/user.c	2007-03-20 21:19:31.000000000 +0100
@@ -52,6 +52,9 @@ static int snapshot_open(struct inode *i
 	if ((filp->f_flags & O_ACCMODE) == O_RDWR)
 		return -ENOSYS;
 
+	if(create_basic_memory_bitmaps())
+		return -ENOMEM;
+
 	nonseekable_open(inode, filp);
 	data = &snapshot_state;
 	filp->private_data = data;
@@ -77,6 +80,7 @@ static int snapshot_release(struct inode
 	struct snapshot_data *data;
 
 	swsusp_free();
+	free_basic_memory_bitmaps();
 	data = filp->private_data;
 	free_all_swap_pages(data->swap, data->bitmap);
 	free_bitmap(data->bitmap);
Index: linux-2.6.21-rc4-mm1/kernel/power/disk.c
===================================================================
--- linux-2.6.21-rc4-mm1.orig/kernel/power/disk.c	2007-03-20 20:58:46.000000000 +0100
+++ linux-2.6.21-rc4-mm1/kernel/power/disk.c	2007-03-20 21:19:31.000000000 +0100
@@ -128,14 +128,19 @@ int pm_suspend_disk(void)
 		mdelay(5000);
 		goto Thaw;
 	}
+	/* Allocate memory management structures */
+	error = create_basic_memory_bitmaps();
+	if (error)
+		goto Thaw;
+
 	/* Free memory before shutting down devices. */
 	error = swsusp_shrink_memory();
 	if (error)
-		goto Thaw;
+		goto Finish;
 
 	error = platform_prepare();
 	if (error)
-		goto Thaw;
+		goto Finish;
 
 	suspend_console();
 	error = device_suspend(PMSG_FREEZE);
@@ -170,7 +175,7 @@ int pm_suspend_disk(void)
 			power_down(pm_disk_mode);
 		else {
 			swsusp_free();
-			goto Thaw;
+			goto Finish;
 		}
 	} else {
 		pr_debug("PM: Image restored successfully.\n");
@@ -183,6 +188,8 @@ int pm_suspend_disk(void)
 	platform_finish();
 	device_resume();
 	resume_console();
+ Finish:
+	free_basic_memory_bitmaps();
  Thaw:
 	unprepare_processes();
 	return error;
@@ -228,13 +235,15 @@ static int software_resume(void)
 	}
 
 	pr_debug("PM: Checking swsusp image.\n");
-
 	error = swsusp_check();
 	if (error)
-		goto Done;
+		goto Unlock;
 
-	pr_debug("PM: Preparing processes for restore.\n");
+	error = create_basic_memory_bitmaps();
+	if (error)
+		goto Unlock;
 
+	pr_debug("PM: Preparing processes for restore.\n");
 	error = prepare_processes();
 	if (error) {
 		swsusp_close();
@@ -277,7 +286,9 @@ static int software_resume(void)
 	printk(KERN_ERR "PM: Restore failed, recovering.\n");
 	unprepare_processes();
  Done:
+	free_basic_memory_bitmaps();
 	/* For success case, the suspend path will release the lock */
+ Unlock:
 	mutex_unlock(&pm_mutex);
 	pr_debug("PM: Resume from disk failed.\n");
 	return 0;
Index: linux-2.6.21-rc4-mm1/kernel/power/main.c
===================================================================
--- linux-2.6.21-rc4-mm1.orig/kernel/power/main.c	2007-03-20 21:21:37.000000000 +0100
+++ linux-2.6.21-rc4-mm1/kernel/power/main.c	2007-03-20 21:22:19.000000000 +0100
@@ -215,6 +215,7 @@ static int enter_state(suspend_state_t s
 	return error;
 }
 
+#ifdef CONFIG_SOFTWARE_SUSPEND
 /*
  * This is main interface to the outside world. It needs to be
  * called from process context.
@@ -223,6 +224,7 @@ int software_suspend(void)
 {
 	return enter_state(PM_SUSPEND_DISK);
 }
+#endif
 
 
 /**


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

* [PATCH 3/5] mm: remove unused page flags
  2007-03-20 21:18     ` Rafael J. Wysocki
  2007-03-20 21:20       ` [PATCH 1/5] swsusp: Use inline functions for changing " Rafael J. Wysocki
  2007-03-20 21:22       ` [PATCH 2/5] swsusp: do not use " Rafael J. Wysocki
@ 2007-03-20 21:25       ` Rafael J. Wysocki
  2007-03-20 21:26       ` [PATCH 4/5] swsusp: fix error paths in snapshot_open Rafael J. Wysocki
  2007-03-20 21:28       ` [PATCH 5/5] swsusp: Use GFP_KERNEL for creating basic data structures Rafael J. Wysocki
  4 siblings, 0 replies; 24+ messages in thread
From: Rafael J. Wysocki @ 2007-03-20 21:25 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Pavel Machek, Peter Zijlstra, LKML

From: Rafael J. Wysocki <rjw@sisk.pl>

Remove the two page flags that were previously used by swsusp and are no
longer needed.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Pavel Machek <pavel@ucw.cz>
---
 include/linux/page-flags.h |   12 ------------
 1 file changed, 12 deletions(-)

Index: linux-2.6.21-rc4-mm1/include/linux/page-flags.h
===================================================================
--- linux-2.6.21-rc4-mm1.orig/include/linux/page-flags.h	2007-03-20 20:58:46.000000000 +0100
+++ linux-2.6.21-rc4-mm1/include/linux/page-flags.h	2007-03-20 21:23:28.000000000 +0100
@@ -82,13 +82,11 @@
 #define PG_private		11	/* If pagecache, has fs-private data */
 
 #define PG_writeback		12	/* Page is under writeback */
-#define PG_nosave		13	/* Used for system suspend/resume */
 #define PG_compound		14	/* Part of a compound page */
 #define PG_swapcache		15	/* Swap page: swp_entry_t in private */
 
 #define PG_mappedtodisk		16	/* Has blocks allocated on-disk */
 #define PG_reclaim		17	/* To be reclaimed asap */
-#define PG_nosave_free		18	/* Used for system suspend/resume */
 #define PG_buddy		19	/* Page is free, on buddy lists */
 #define PG_booked		20	/* Has blocks reserved on-disk */
 
@@ -195,16 +193,6 @@ static inline void SetPageUptodate(struc
 #define TestClearPageWriteback(page) test_and_clear_bit(PG_writeback,	\
 							&(page)->flags)
 
-#define PageNosave(page)	test_bit(PG_nosave, &(page)->flags)
-#define SetPageNosave(page)	set_bit(PG_nosave, &(page)->flags)
-#define TestSetPageNosave(page)	test_and_set_bit(PG_nosave, &(page)->flags)
-#define ClearPageNosave(page)		clear_bit(PG_nosave, &(page)->flags)
-#define TestClearPageNosave(page)	test_and_clear_bit(PG_nosave, &(page)->flags)
-
-#define PageNosaveFree(page)	test_bit(PG_nosave_free, &(page)->flags)
-#define SetPageNosaveFree(page)	set_bit(PG_nosave_free, &(page)->flags)
-#define ClearPageNosaveFree(page)		clear_bit(PG_nosave_free, &(page)->flags)
-
 #define PageBuddy(page)		test_bit(PG_buddy, &(page)->flags)
 #define __SetPageBuddy(page)	__set_bit(PG_buddy, &(page)->flags)
 #define __ClearPageBuddy(page)	__clear_bit(PG_buddy, &(page)->flags)


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

* [PATCH 4/5] swsusp: fix error paths in snapshot_open
  2007-03-20 21:18     ` Rafael J. Wysocki
                         ` (2 preceding siblings ...)
  2007-03-20 21:25       ` [PATCH 3/5] mm: remove unused " Rafael J. Wysocki
@ 2007-03-20 21:26       ` Rafael J. Wysocki
  2007-03-20 22:16         ` Pavel Machek
  2007-03-20 21:28       ` [PATCH 5/5] swsusp: Use GFP_KERNEL for creating basic data structures Rafael J. Wysocki
  4 siblings, 1 reply; 24+ messages in thread
From: Rafael J. Wysocki @ 2007-03-20 21:26 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Pavel Machek, Peter Zijlstra, LKML

From: Rafael J. Wysocki <rjw@sisk.pl>

We forget to increase device_available if there's an error in
snapshot_open(), so the snapshot device cannot be open at all after
snapshot_open() has returned an error.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Pavel Machek <pavel@ucw.cz>
---
 kernel/power/user.c |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

Index: linux-2.6.21-rc4-mm1/kernel/power/user.c
===================================================================
--- linux-2.6.21-rc4-mm1.orig/kernel/power/user.c	2007-03-20 21:19:31.000000000 +0100
+++ linux-2.6.21-rc4-mm1/kernel/power/user.c	2007-03-20 21:35:59.000000000 +0100
@@ -49,12 +49,14 @@ static int snapshot_open(struct inode *i
 	if (!atomic_add_unless(&device_available, -1, 0))
 		return -EBUSY;
 
-	if ((filp->f_flags & O_ACCMODE) == O_RDWR)
+	if ((filp->f_flags & O_ACCMODE) == O_RDWR) {
+		atomic_inc(&device_available);
 		return -ENOSYS;
-
-	if(create_basic_memory_bitmaps())
+	}
+	if(create_basic_memory_bitmaps()) {
+		atomic_inc(&device_available);
 		return -ENOMEM;
-
+	}
 	nonseekable_open(inode, filp);
 	data = &snapshot_state;
 	filp->private_data = data;


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

* [PATCH 5/5] swsusp: Use GFP_KERNEL for creating basic data structures
  2007-03-20 21:18     ` Rafael J. Wysocki
                         ` (3 preceding siblings ...)
  2007-03-20 21:26       ` [PATCH 4/5] swsusp: fix error paths in snapshot_open Rafael J. Wysocki
@ 2007-03-20 21:28       ` Rafael J. Wysocki
  2007-03-20 22:17         ` Pavel Machek
  4 siblings, 1 reply; 24+ messages in thread
From: Rafael J. Wysocki @ 2007-03-20 21:28 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Pavel Machek, Peter Zijlstra, LKML

From: Rafael J. Wysocki <rjw@sisk.pl>

Make swsusp call create_basic_memory_bitmaps() before processes are frozen,
so that GFP_KERNEL allocations can be made in it.  Additionally, ensure
that the swsusp's userland interface won't be used while either
pm_suspend_disk() or software_resume() is being executed.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
---
 kernel/power/disk.c     |   37 ++++++++++++++++++++++++++-----------
 kernel/power/power.h    |    3 +++
 kernel/power/snapshot.c |    8 ++++----
 kernel/power/user.c     |   10 +++++-----
 4 files changed, 38 insertions(+), 20 deletions(-)

Index: linux-2.6.21-rc4-mm1/kernel/power/disk.c
===================================================================
--- linux-2.6.21-rc4-mm1.orig/kernel/power/disk.c	2007-03-20 21:35:59.000000000 +0100
+++ linux-2.6.21-rc4-mm1/kernel/power/disk.c	2007-03-20 21:36:03.000000000 +0100
@@ -119,28 +119,33 @@ int pm_suspend_disk(void)
 {
 	int error;
 
+	/* The snapshot device should not be opened while we're running */
+	if (!atomic_add_unless(&snapshot_device_available, -1, 0))
+		return -EBUSY;
+
+	/* Allocate memory management structures */
+	error = create_basic_memory_bitmaps();
+	if (error)
+		goto Exit;
+
 	error = prepare_processes();
 	if (error)
-		return error;
+		goto Finish;
 
 	if (pm_disk_mode == PM_DISK_TESTPROC) {
 		printk("swsusp debug: Waiting for 5 seconds.\n");
 		mdelay(5000);
 		goto Thaw;
 	}
-	/* Allocate memory management structures */
-	error = create_basic_memory_bitmaps();
-	if (error)
-		goto Thaw;
 
 	/* Free memory before shutting down devices. */
 	error = swsusp_shrink_memory();
 	if (error)
-		goto Finish;
+		goto Thaw;
 
 	error = platform_prepare();
 	if (error)
-		goto Finish;
+		goto Thaw;
 
 	suspend_console();
 	error = device_suspend(PMSG_FREEZE);
@@ -175,7 +180,7 @@ int pm_suspend_disk(void)
 			power_down(pm_disk_mode);
 		else {
 			swsusp_free();
-			goto Finish;
+			goto Thaw;
 		}
 	} else {
 		pr_debug("PM: Image restored successfully.\n");
@@ -188,10 +193,12 @@ int pm_suspend_disk(void)
 	platform_finish();
 	device_resume();
 	resume_console();
- Finish:
-	free_basic_memory_bitmaps();
  Thaw:
 	unprepare_processes();
+ Finish:
+	free_basic_memory_bitmaps();
+ Exit:
+	atomic_inc(&snapshot_device_available);
 	return error;
 }
 
@@ -239,9 +246,15 @@ static int software_resume(void)
 	if (error)
 		goto Unlock;
 
+	/* The snapshot device should not be opened while we're running */
+	if (!atomic_add_unless(&snapshot_device_available, -1, 0)) {
+		error = -EBUSY;
+		goto Unlock;
+	}
+
 	error = create_basic_memory_bitmaps();
 	if (error)
-		goto Unlock;
+		goto Finish;
 
 	pr_debug("PM: Preparing processes for restore.\n");
 	error = prepare_processes();
@@ -288,6 +301,8 @@ static int software_resume(void)
 	unprepare_processes();
  Done:
 	free_basic_memory_bitmaps();
+ Finish:
+	atomic_inc(&snapshot_device_available);
 	/* For success case, the suspend path will release the lock */
  Unlock:
 	mutex_unlock(&pm_mutex);
Index: linux-2.6.21-rc4-mm1/kernel/power/power.h
===================================================================
--- linux-2.6.21-rc4-mm1.orig/kernel/power/power.h	2007-03-20 21:35:59.000000000 +0100
+++ linux-2.6.21-rc4-mm1/kernel/power/power.h	2007-03-20 21:36:03.000000000 +0100
@@ -141,6 +141,9 @@ struct resume_swap_area {
 #define PMOPS_ENTER	2
 #define PMOPS_FINISH	3
 
+/* If unset, the snapshot device cannot be open. */
+extern atomic_t snapshot_device_available;
+
 /**
  *	The bitmap is used for tracing allocated swap pages
  *
Index: linux-2.6.21-rc4-mm1/kernel/power/snapshot.c
===================================================================
--- linux-2.6.21-rc4-mm1.orig/kernel/power/snapshot.c	2007-03-20 21:35:59.000000000 +0100
+++ linux-2.6.21-rc4-mm1/kernel/power/snapshot.c	2007-03-20 21:36:03.000000000 +0100
@@ -723,19 +723,19 @@ int create_basic_memory_bitmaps(void)
 
 	BUG_ON(forbidden_pages_map || free_pages_map);
 
-	bm1 = kzalloc(sizeof(struct memory_bitmap), GFP_ATOMIC);
+	bm1 = kzalloc(sizeof(struct memory_bitmap), GFP_KERNEL);
 	if (!bm1)
 		return -ENOMEM;
 
-	error = memory_bm_create(bm1, GFP_ATOMIC | __GFP_COLD, PG_ANY);
+	error = memory_bm_create(bm1, GFP_KERNEL, PG_ANY);
 	if (error)
 		goto Free_first_object;
 
-	bm2 = kzalloc(sizeof(struct memory_bitmap), GFP_ATOMIC);
+	bm2 = kzalloc(sizeof(struct memory_bitmap), GFP_KERNEL);
 	if (!bm2)
 		goto Free_first_bitmap;
 
-	error = memory_bm_create(bm2, GFP_ATOMIC | __GFP_COLD, PG_ANY);
+	error = memory_bm_create(bm2, GFP_KERNEL, PG_ANY);
 	if (error)
 		goto Free_second_object;
 
Index: linux-2.6.21-rc4-mm1/kernel/power/user.c
===================================================================
--- linux-2.6.21-rc4-mm1.orig/kernel/power/user.c	2007-03-20 21:35:59.000000000 +0100
+++ linux-2.6.21-rc4-mm1/kernel/power/user.c	2007-03-20 21:36:03.000000000 +0100
@@ -40,21 +40,21 @@ static struct snapshot_data {
 	char platform_suspend;
 } snapshot_state;
 
-static atomic_t device_available = ATOMIC_INIT(1);
+atomic_t snapshot_device_available = ATOMIC_INIT(1);
 
 static int snapshot_open(struct inode *inode, struct file *filp)
 {
 	struct snapshot_data *data;
 
-	if (!atomic_add_unless(&device_available, -1, 0))
+	if (!atomic_add_unless(&snapshot_device_available, -1, 0))
 		return -EBUSY;
 
 	if ((filp->f_flags & O_ACCMODE) == O_RDWR) {
-		atomic_inc(&device_available);
+		atomic_inc(&snapshot_device_available);
 		return -ENOSYS;
 	}
 	if(create_basic_memory_bitmaps()) {
-		atomic_inc(&device_available);
+		atomic_inc(&snapshot_device_available);
 		return -ENOMEM;
 	}
 	nonseekable_open(inode, filp);
@@ -92,7 +92,7 @@ static int snapshot_release(struct inode
 		enable_nonboot_cpus();
 		mutex_unlock(&pm_mutex);
 	}
-	atomic_inc(&device_available);
+	atomic_inc(&snapshot_device_available);
 	return 0;
 }
 

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

* Re: [PATCH 4/5] swsusp: fix error paths in snapshot_open
  2007-03-20 21:26       ` [PATCH 4/5] swsusp: fix error paths in snapshot_open Rafael J. Wysocki
@ 2007-03-20 22:16         ` Pavel Machek
  2007-03-20 22:24           ` Rafael J. Wysocki
  0 siblings, 1 reply; 24+ messages in thread
From: Pavel Machek @ 2007-03-20 22:16 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: Andrew Morton, Peter Zijlstra, LKML

Hi!

> We forget to increase device_available if there's an error in
> snapshot_open(), so the snapshot device cannot be open at all after
> snapshot_open() has returned an error.

Actually, this should go to the beggining of series, as it is
(non-critical) bugfix.

							Pavel
> @@ -49,12 +49,14 @@ static int snapshot_open(struct inode *i
>  	if (!atomic_add_unless(&device_available, -1, 0))
>  		return -EBUSY;
>  
> -	if ((filp->f_flags & O_ACCMODE) == O_RDWR)
> +	if ((filp->f_flags & O_ACCMODE) == O_RDWR) {
> +		atomic_inc(&device_available);
>  		return -ENOSYS;
> -
> -	if(create_basic_memory_bitmaps())
> +	}
> +	if(create_basic_memory_bitmaps()) {
> +		atomic_inc(&device_available);
>  		return -ENOMEM;
> -
> +	}
>  	nonseekable_open(inode, filp);
>  	data = &snapshot_state;
>  	filp->private_data = data;

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

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

* Re: [PATCH 5/5] swsusp: Use GFP_KERNEL for creating basic data structures
  2007-03-20 21:28       ` [PATCH 5/5] swsusp: Use GFP_KERNEL for creating basic data structures Rafael J. Wysocki
@ 2007-03-20 22:17         ` Pavel Machek
  0 siblings, 0 replies; 24+ messages in thread
From: Pavel Machek @ 2007-03-20 22:17 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: Andrew Morton, Peter Zijlstra, LKML

Hi!

> From: Rafael J. Wysocki <rjw@sisk.pl>
> 
> Make swsusp call create_basic_memory_bitmaps() before processes are frozen,
> so that GFP_KERNEL allocations can be made in it.  Additionally, ensure
> that the swsusp's userland interface won't be used while either
> pm_suspend_disk() or software_resume() is being executed.
> 
> Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>

ACK, but I'd prefer it to go before the bitmap patches, as it can be
viewed as bugfix... ok, it probably does not matter much in this case.

									Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

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

* Re: [PATCH 4/5] swsusp: fix error paths in snapshot_open
  2007-03-20 22:24           ` Rafael J. Wysocki
@ 2007-03-20 22:24             ` Pavel Machek
  2007-03-20 22:52               ` Rafael J. Wysocki
  0 siblings, 1 reply; 24+ messages in thread
From: Pavel Machek @ 2007-03-20 22:24 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: Andrew Morton, Peter Zijlstra, LKML

Hi!

> > > We forget to increase device_available if there's an error in
> > > snapshot_open(), so the snapshot device cannot be open at all after
> > > snapshot_open() has returned an error.
> > 
> > Actually, this should go to the beggining of series, as it is
> > (non-critical) bugfix.
> 
> Well, yes.
> 
> I've just kept the original order.  OTOH, I don't think it's as urgent as to go
> into 2.6.21 ("been there forever" kind of thing).

No, it is not urgent enough for 2.6.21... But I have secret plan...
trying to push bitmaps+non-bugfixes for swsusp to 2.6.23, and have
swsusp/s2ram stabilize during 2.6.22. Way too much stuff happened in
2.6.21 series.
								Pavel 

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

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

* Re: [PATCH 4/5] swsusp: fix error paths in snapshot_open
  2007-03-20 22:16         ` Pavel Machek
@ 2007-03-20 22:24           ` Rafael J. Wysocki
  2007-03-20 22:24             ` Pavel Machek
  0 siblings, 1 reply; 24+ messages in thread
From: Rafael J. Wysocki @ 2007-03-20 22:24 UTC (permalink / raw)
  To: Pavel Machek; +Cc: Andrew Morton, Peter Zijlstra, LKML

On Tuesday, 20 March 2007 23:16, Pavel Machek wrote:
> Hi!
> 
> > We forget to increase device_available if there's an error in
> > snapshot_open(), so the snapshot device cannot be open at all after
> > snapshot_open() has returned an error.
> 
> Actually, this should go to the beggining of series, as it is
> (non-critical) bugfix.

Well, yes.

I've just kept the original order.  OTOH, I don't think it's as urgent as to go
into 2.6.21 ("been there forever" kind of thing).

Rafael

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

* Re: [PATCH 4/5] swsusp: fix error paths in snapshot_open
  2007-03-20 22:24             ` Pavel Machek
@ 2007-03-20 22:52               ` Rafael J. Wysocki
  0 siblings, 0 replies; 24+ messages in thread
From: Rafael J. Wysocki @ 2007-03-20 22:52 UTC (permalink / raw)
  To: Pavel Machek; +Cc: Andrew Morton, Peter Zijlstra, LKML

On Tuesday, 20 March 2007 23:24, Pavel Machek wrote:
> Hi!
> 
> > > > We forget to increase device_available if there's an error in
> > > > snapshot_open(), so the snapshot device cannot be open at all after
> > > > snapshot_open() has returned an error.
> > > 
> > > Actually, this should go to the beggining of series, as it is
> > > (non-critical) bugfix.
> > 
> > Well, yes.
> > 
> > I've just kept the original order.  OTOH, I don't think it's as urgent as to go
> > into 2.6.21 ("been there forever" kind of thing).
> 
> No, it is not urgent enough for 2.6.21... But I have secret plan...
> trying to push bitmaps+non-bugfixes for swsusp to 2.6.23, and have
> swsusp/s2ram stabilize during 2.6.22. Way too much stuff happened in
> 2.6.21 series.

OK by me, but I think we'll have to tell Andrew which patches should wait
for 2.6.23 anyway. ;-)

Rafael

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

end of thread, other threads:[~2007-03-20 22:49 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-12 21:14 [PATCH 0/3] swsusp: Stop using page flags Rafael J. Wysocki
2007-03-12 21:16 ` [PATCH 1/3] swsusp: Use inline functions for changing " Rafael J. Wysocki
2007-03-12 21:19 ` [PATCH 2/3] swsusp: Do not use " Rafael J. Wysocki
2007-03-15 19:08   ` Andrew Morton
2007-03-15 21:05     ` Rafael J. Wysocki
2007-03-15 21:29       ` Andrew Morton
2007-03-15 22:19         ` Jiri Kosina
2007-03-15 22:23           ` Andrew Morton
2007-03-16  0:01             ` Rafael J. Wysocki
2007-03-15 23:05         ` Pavel Machek
2007-03-20  0:31   ` Andrew Morton
2007-03-20 13:18     ` Pavel Machek
2007-03-20 21:18     ` Rafael J. Wysocki
2007-03-20 21:20       ` [PATCH 1/5] swsusp: Use inline functions for changing " Rafael J. Wysocki
2007-03-20 21:22       ` [PATCH 2/5] swsusp: do not use " Rafael J. Wysocki
2007-03-20 21:25       ` [PATCH 3/5] mm: remove unused " Rafael J. Wysocki
2007-03-20 21:26       ` [PATCH 4/5] swsusp: fix error paths in snapshot_open Rafael J. Wysocki
2007-03-20 22:16         ` Pavel Machek
2007-03-20 22:24           ` Rafael J. Wysocki
2007-03-20 22:24             ` Pavel Machek
2007-03-20 22:52               ` Rafael J. Wysocki
2007-03-20 21:28       ` [PATCH 5/5] swsusp: Use GFP_KERNEL for creating basic data structures Rafael J. Wysocki
2007-03-20 22:17         ` Pavel Machek
2007-03-12 21:20 ` [PATCH 3/3] mm: Remove unused page flags Rafael J. Wysocki

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.