* [PATCH 0/3] swsusp: simplifications and cleanups
@ 2005-11-01 23:00 Rafael J. Wysocki
2005-11-01 23:04 ` [PATCH 1/3] swsusp: reduce code duplication Rafael J. Wysocki
` (4 more replies)
0 siblings, 5 replies; 12+ messages in thread
From: Rafael J. Wysocki @ 2005-11-01 23:00 UTC (permalink / raw)
To: Andrew Morton; +Cc: LKML, Pavel Machek
Hi,
The following series of patches implements some simplifications
and cleanups of swsusp.
The patches have been acked by Pavel (Pavel, please confirm).
Please apply.
Greetings,
Rafael
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 1/3] swsusp: reduce code duplication
2005-11-01 23:00 [PATCH 0/3] swsusp: simplifications and cleanups Rafael J. Wysocki
@ 2005-11-01 23:04 ` Rafael J. Wysocki
2005-11-01 23:07 ` [PATCH 2/3] swsusp: simplify pagedir relocation Rafael J. Wysocki
` (3 subsequent siblings)
4 siblings, 0 replies; 12+ messages in thread
From: Rafael J. Wysocki @ 2005-11-01 23:04 UTC (permalink / raw)
To: Andrew Morton; +Cc: LKML, Pavel Machek
The changes made by this patch are necessary for the pagedir relocation
simplification in the next patch. Additionally, these changes allow us to
drop check_pagedir() and make get_safe_page() be a one-line wrapper around
alloc_image_page() (get_safe_page() goes to snapshot.c, because
alloc_image_page() is static and it does not make sense to export
it).
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
kernel/power/power.h | 3 +-
kernel/power/snapshot.c | 62 +++++++++++++++++++++++++++++++++++++-----------
kernel/power/swsusp.c | 57 +-------------------------------------------
3 files changed, 52 insertions(+), 70 deletions(-)
Index: linux-2.6.14-git4/kernel/power/power.h
===================================================================
--- linux-2.6.14-git4.orig/kernel/power/power.h 2005-11-01 18:18:31.000000000 +0100
+++ linux-2.6.14-git4/kernel/power/power.h 2005-11-01 18:20:28.000000000 +0100
@@ -66,7 +66,8 @@
extern asmlinkage int swsusp_arch_resume(void);
extern int restore_highmem(void);
-extern struct pbe * alloc_pagedir(unsigned nr_pages);
+extern struct pbe *alloc_pagedir(unsigned nr_pages, gfp_t gfp_mask, int safe_needed);
extern void create_pbe_list(struct pbe *pblist, unsigned nr_pages);
extern void swsusp_free(void);
+extern int alloc_data_pages(struct pbe *pblist, gfp_t gfp_mask, int safe_needed);
extern int enough_swap(unsigned nr_pages);
Index: linux-2.6.14-git4/kernel/power/snapshot.c
===================================================================
--- linux-2.6.14-git4.orig/kernel/power/snapshot.c 2005-11-01 18:18:31.000000000 +0100
+++ linux-2.6.14-git4/kernel/power/snapshot.c 2005-11-01 18:20:28.000000000 +0100
@@ -270,9 +270,30 @@
pr_debug("create_pbe_list(): initialized %d PBEs\n", num);
}
-static void *alloc_image_page(void)
+/**
+ * @safe_needed - on resume, for storing the PBE list and the image,
+ * we can only use memory pages that do not conflict with the pages
+ * which had been used before suspend.
+ *
+ * The unsafe pages are marked with the PG_nosave_free flag
+ *
+ * Allocated but unusable (ie eaten) memory pages should be marked
+ * so that swsusp_free() can release them
+ */
+
+static inline void *alloc_image_page(gfp_t gfp_mask, int safe_needed)
{
- void *res = (void *)get_zeroed_page(GFP_ATOMIC | __GFP_COLD);
+ void *res;
+
+ if (safe_needed)
+ do {
+ res = (void *)get_zeroed_page(gfp_mask);
+ if (res && PageNosaveFree(virt_to_page(res)))
+ /* This is for swsusp_free() */
+ SetPageNosave(virt_to_page(res));
+ } while (res && PageNosaveFree(virt_to_page(res)));
+ else
+ res = (void *)get_zeroed_page(gfp_mask);
if (res) {
SetPageNosave(virt_to_page(res));
SetPageNosaveFree(virt_to_page(res));
@@ -280,6 +301,11 @@
return res;
}
+unsigned long get_safe_page(gfp_t gfp_mask)
+{
+ return (unsigned long)alloc_image_page(gfp_mask, 1);
+}
+
/**
* alloc_pagedir - Allocate the page directory.
*
@@ -293,7 +319,7 @@
* On each page we set up a list of struct_pbe elements.
*/
-struct pbe *alloc_pagedir(unsigned nr_pages)
+struct pbe *alloc_pagedir(unsigned nr_pages, gfp_t gfp_mask, int safe_needed)
{
unsigned num;
struct pbe *pblist, *pbe;
@@ -302,12 +328,12 @@
return NULL;
pr_debug("alloc_pagedir(): nr_pages = %d\n", nr_pages);
- pblist = alloc_image_page();
+ pblist = alloc_image_page(gfp_mask, safe_needed);
/* FIXME: rewrite this ugly loop */
for (pbe = pblist, num = PBES_PER_PAGE; pbe && num < nr_pages;
pbe = pbe->next, num += PBES_PER_PAGE) {
pbe += PB_PAGE_SKIP;
- pbe->next = alloc_image_page();
+ pbe->next = alloc_image_page(gfp_mask, safe_needed);
}
if (!pbe) { /* get_zeroed_page() failed */
free_pagedir(pblist);
@@ -355,24 +381,32 @@
(nr_pages + PBES_PER_PAGE - 1) / PBES_PER_PAGE);
}
+int alloc_data_pages(struct pbe *pblist, gfp_t gfp_mask, int safe_needed)
+{
+ struct pbe *p;
+
+ for_each_pbe (p, pblist) {
+ p->address = (unsigned long)alloc_image_page(gfp_mask, safe_needed);
+ if (!p->address)
+ return -ENOMEM;
+ }
+ return 0;
+}
static struct pbe *swsusp_alloc(unsigned nr_pages)
{
- struct pbe *pblist, *p;
+ struct pbe *pblist;
- if (!(pblist = alloc_pagedir(nr_pages))) {
+ if (!(pblist = alloc_pagedir(nr_pages, GFP_ATOMIC | __GFP_COLD, 0))) {
printk(KERN_ERR "suspend: Allocating pagedir failed.\n");
return NULL;
}
create_pbe_list(pblist, nr_pages);
- for_each_pbe (p, pblist) {
- p->address = (unsigned long)alloc_image_page();
- if (!p->address) {
- printk(KERN_ERR "suspend: Allocating image pages failed.\n");
- swsusp_free();
- return NULL;
- }
+ if (alloc_data_pages(pblist, GFP_ATOMIC | __GFP_COLD, 0)) {
+ printk(KERN_ERR "suspend: Allocating image pages failed.\n");
+ swsusp_free();
+ return NULL;
}
return pblist;
Index: linux-2.6.14-git4/kernel/power/swsusp.c
===================================================================
--- linux-2.6.14-git4.orig/kernel/power/swsusp.c 2005-11-01 18:18:31.000000000 +0100
+++ linux-2.6.14-git4/kernel/power/swsusp.c 2005-11-01 18:20:28.000000000 +0100
@@ -636,59 +636,6 @@
}
/**
- * On resume, for storing the PBE list and the image,
- * we can only use memory pages that do not conflict with the pages
- * which had been used before suspend.
- *
- * We don't know which pages are usable until we allocate them.
- *
- * Allocated but unusable (ie eaten) memory pages are marked so that
- * swsusp_free() can release them
- */
-
-unsigned long get_safe_page(gfp_t gfp_mask)
-{
- unsigned long m;
-
- do {
- m = get_zeroed_page(gfp_mask);
- if (m && PageNosaveFree(virt_to_page(m)))
- /* This is for swsusp_free() */
- SetPageNosave(virt_to_page(m));
- } while (m && PageNosaveFree(virt_to_page(m)));
- if (m) {
- /* This is for swsusp_free() */
- SetPageNosave(virt_to_page(m));
- SetPageNosaveFree(virt_to_page(m));
- }
- return m;
-}
-
-/**
- * check_pagedir - We ensure here that pages that the PBEs point to
- * won't collide with pages where we're going to restore from the loaded
- * pages later
- */
-
-static int check_pagedir(struct pbe *pblist)
-{
- struct pbe *p;
-
- /* This is necessary, so that we can free allocated pages
- * in case of failure
- */
- for_each_pbe (p, pblist)
- p->address = 0UL;
-
- for_each_pbe (p, pblist) {
- p->address = get_safe_page(GFP_ATOMIC);
- if (!p->address)
- return -ENOMEM;
- }
- return 0;
-}
-
-/**
* swsusp_pagedir_relocate - It is possible, that some memory pages
* occupied by the list of PBEs collide with pages where we're going to
* restore from the loaded pages later. We relocate them here.
@@ -997,7 +944,7 @@
int error = 0;
struct pbe *p;
- if (!(p = alloc_pagedir(nr_copy_pages)))
+ if (!(p = alloc_pagedir(nr_copy_pages, GFP_ATOMIC, 0)))
return -ENOMEM;
if ((error = read_pagedir(p)))
@@ -1010,7 +957,7 @@
/* Allocate memory for the image and read the data from swap */
- error = check_pagedir(pagedir_nosave);
+ error = alloc_data_pages(pagedir_nosave, GFP_ATOMIC, 1);
if (!error)
error = data_read(pagedir_nosave);
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 2/3] swsusp: simplify pagedir relocation
2005-11-01 23:00 [PATCH 0/3] swsusp: simplifications and cleanups Rafael J. Wysocki
2005-11-01 23:04 ` [PATCH 1/3] swsusp: reduce code duplication Rafael J. Wysocki
@ 2005-11-01 23:07 ` Rafael J. Wysocki
2005-11-01 23:11 ` [PATCH 3/3] swsusp: rework swsusp_suspend Rafael J. Wysocki
` (2 subsequent siblings)
4 siblings, 0 replies; 12+ messages in thread
From: Rafael J. Wysocki @ 2005-11-01 23:07 UTC (permalink / raw)
To: Andrew Morton; +Cc: LKML, Pavel Machek
This patch simplifies the relocation of the page backup list (aka pagedir)
during resume.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
kernel/power/power.h | 1
kernel/power/snapshot.c | 2 -
kernel/power/swsusp.c | 78 ++++++++++++++++--------------------------------
3 files changed, 28 insertions(+), 53 deletions(-)
Index: linux-2.6.14-git4/kernel/power/swsusp.c
===================================================================
--- linux-2.6.14-git4.orig/kernel/power/swsusp.c 2005-11-01 18:20:28.000000000 +0100
+++ linux-2.6.14-git4/kernel/power/swsusp.c 2005-11-01 18:22:12.000000000 +0100
@@ -636,74 +636,43 @@
}
/**
- * swsusp_pagedir_relocate - It is possible, that some memory pages
- * occupied by the list of PBEs collide with pages where we're going to
- * restore from the loaded pages later. We relocate them here.
+ * mark_unsafe_pages - mark the pages that cannot be used for storing
+ * the image during resume, because they conflict with the pages that
+ * had been used before suspend
*/
-static struct pbe * swsusp_pagedir_relocate(struct pbe *pblist)
+static void mark_unsafe_pages(struct pbe *pblist)
{
struct zone *zone;
unsigned long zone_pfn;
- struct pbe *pbpage, *tail, *p;
- void *m;
- int rel = 0;
+ struct pbe *p;
if (!pblist) /* a sanity check */
- return NULL;
-
- pr_debug("swsusp: Relocating pagedir (%lu pages to check)\n",
- swsusp_info.pagedir_pages);
+ return;
/* Clear page flags */
-
for_each_zone (zone) {
- for (zone_pfn = 0; zone_pfn < zone->spanned_pages; ++zone_pfn)
- if (pfn_valid(zone_pfn + zone->zone_start_pfn))
- ClearPageNosaveFree(pfn_to_page(zone_pfn +
+ for (zone_pfn = 0; zone_pfn < zone->spanned_pages; ++zone_pfn)
+ if (pfn_valid(zone_pfn + zone->zone_start_pfn))
+ ClearPageNosaveFree(pfn_to_page(zone_pfn +
zone->zone_start_pfn));
}
/* Mark orig addresses */
-
for_each_pbe (p, pblist)
SetPageNosaveFree(virt_to_page(p->orig_address));
- tail = pblist + PB_PAGE_SKIP;
-
- /* Relocate colliding pages */
-
- for_each_pb_page (pbpage, pblist) {
- if (PageNosaveFree(virt_to_page((unsigned long)pbpage))) {
- m = (void *)get_safe_page(GFP_ATOMIC | __GFP_COLD);
- if (!m)
- return NULL;
- memcpy(m, (void *)pbpage, PAGE_SIZE);
- if (pbpage == pblist)
- pblist = (struct pbe *)m;
- else
- tail->next = (struct pbe *)m;
- pbpage = (struct pbe *)m;
-
- /* We have to link the PBEs again */
- for (p = pbpage; p < pbpage + PB_PAGE_SKIP; p++)
- if (p->next) /* needed to save the end */
- p->next = p + 1;
-
- rel++;
- }
- tail = pbpage + PB_PAGE_SKIP;
- }
+}
- /* This is for swsusp_free() */
- for_each_pb_page (pbpage, pblist) {
- SetPageNosave(virt_to_page(pbpage));
- SetPageNosaveFree(virt_to_page(pbpage));
+static void copy_page_backup_list(struct pbe *dst, struct pbe *src)
+{
+ /* We assume both lists contain the same number of elements */
+ while (src) {
+ dst->orig_address = src->orig_address;
+ dst->swap_address = src->swap_address;
+ dst = dst->next;
+ src = src->next;
}
-
- printk("swsusp: Relocated %d pages\n", rel);
-
- return pblist;
}
/*
@@ -949,10 +918,15 @@
if ((error = read_pagedir(p)))
return error;
-
create_pbe_list(p, nr_copy_pages);
-
- if (!(pagedir_nosave = swsusp_pagedir_relocate(p)))
+ mark_unsafe_pages(p);
+ pagedir_nosave = alloc_pagedir(nr_copy_pages, GFP_ATOMIC, 1);
+ if (pagedir_nosave) {
+ create_pbe_list(pagedir_nosave, nr_copy_pages);
+ copy_page_backup_list(pagedir_nosave, p);
+ }
+ free_pagedir(p);
+ if (!pagedir_nosave)
return -ENOMEM;
/* Allocate memory for the image and read the data from swap */
Index: linux-2.6.14-git4/kernel/power/power.h
===================================================================
--- linux-2.6.14-git4.orig/kernel/power/power.h 2005-11-01 18:20:28.000000000 +0100
+++ linux-2.6.14-git4/kernel/power/power.h 2005-11-01 18:22:12.000000000 +0100
@@ -66,6 +66,7 @@
extern asmlinkage int swsusp_arch_resume(void);
extern int restore_highmem(void);
+extern void free_pagedir(struct pbe *pblist);
extern struct pbe *alloc_pagedir(unsigned nr_pages, gfp_t gfp_mask, int safe_needed);
extern void create_pbe_list(struct pbe *pblist, unsigned nr_pages);
extern void swsusp_free(void);
Index: linux-2.6.14-git4/kernel/power/snapshot.c
===================================================================
--- linux-2.6.14-git4.orig/kernel/power/snapshot.c 2005-11-01 18:20:28.000000000 +0100
+++ linux-2.6.14-git4/kernel/power/snapshot.c 2005-11-01 18:22:12.000000000 +0100
@@ -217,7 +217,7 @@
* free_pagedir - free pages allocated with alloc_pagedir()
*/
-static void free_pagedir(struct pbe *pblist)
+void free_pagedir(struct pbe *pblist)
{
struct pbe *pbe;
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 3/3] swsusp: rework swsusp_suspend
2005-11-01 23:00 [PATCH 0/3] swsusp: simplifications and cleanups Rafael J. Wysocki
2005-11-01 23:04 ` [PATCH 1/3] swsusp: reduce code duplication Rafael J. Wysocki
2005-11-01 23:07 ` [PATCH 2/3] swsusp: simplify pagedir relocation Rafael J. Wysocki
@ 2005-11-01 23:11 ` Rafael J. Wysocki
2005-11-02 9:49 ` [PATCH 0/3] swsusp: simplifications and cleanups Pavel Machek
2005-11-04 23:04 ` Andrew Morton
4 siblings, 0 replies; 12+ messages in thread
From: Rafael J. Wysocki @ 2005-11-01 23:11 UTC (permalink / raw)
To: Andrew Morton; +Cc: LKML, Pavel Machek
This patch makes only the functions in swsusp.c call functions in
snapshot.c and not both ways. It also moves the check for available swap
out of swsusp_suspend() which is necessary for separating the swap-handling
functions in swsusp from the core code.
This is to replace any previous iteration of the patch called
"rework swsusp_suspend".
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
kernel/power/power.h | 2 -
kernel/power/snapshot.c | 19 +-----------
kernel/power/swsusp.c | 75 ++++++++++++++++++++++++++++--------------------
3 files changed, 47 insertions(+), 49 deletions(-)
Index: linux-2.6.14-git4/kernel/power/snapshot.c
===================================================================
--- linux-2.6.14-git4.orig/kernel/power/snapshot.c 2005-11-01 18:22:12.000000000 +0100
+++ linux-2.6.14-git4/kernel/power/snapshot.c 2005-11-01 18:24:12.000000000 +0100
@@ -88,8 +88,7 @@
return 0;
}
-
-static int save_highmem(void)
+int save_highmem(void)
{
struct zone *zone;
int res = 0;
@@ -120,11 +119,7 @@
}
return 0;
}
-#else
-static int save_highmem(void) { return 0; }
-int restore_highmem(void) { return 0; }
-#endif /* CONFIG_HIGHMEM */
-
+#endif
static int pfn_is_nosave(unsigned long pfn)
{
@@ -417,11 +412,6 @@
unsigned nr_pages;
pr_debug("swsusp: critical section: \n");
- if (save_highmem()) {
- printk(KERN_CRIT "swsusp: Not enough free pages for highmem\n");
- restore_highmem();
- return -ENOMEM;
- }
drain_local_pages();
nr_pages = count_data_pages();
@@ -441,11 +431,6 @@
return -ENOMEM;
}
- if (!enough_swap(nr_pages)) {
- printk(KERN_ERR "swsusp: Not enough free swap\n");
- return -ENOSPC;
- }
-
pagedir_nosave = swsusp_alloc(nr_pages);
if (!pagedir_nosave)
return -ENOMEM;
Index: linux-2.6.14-git4/kernel/power/swsusp.c
===================================================================
--- linux-2.6.14-git4.orig/kernel/power/swsusp.c 2005-11-01 18:22:12.000000000 +0100
+++ linux-2.6.14-git4/kernel/power/swsusp.c 2005-11-01 18:24:12.000000000 +0100
@@ -73,6 +73,14 @@
#include "power.h"
+#ifdef CONFIG_HIGHMEM
+int save_highmem(void);
+int restore_highmem(void);
+#else
+static int save_highmem(void) { return 0; }
+static int restore_highmem(void) { return 0; }
+#endif
+
#define CIPHER "aes"
#define MAXKEY 32
#define MAXIV 32
@@ -507,6 +515,26 @@
}
/**
+ * enough_swap - Make sure we have enough swap to save the image.
+ *
+ * Returns TRUE or FALSE after checking the total amount of swap
+ * space avaiable.
+ *
+ * FIXME: si_swapinfo(&i) returns all swap devices information.
+ * We should only consider resume_device.
+ */
+
+static int enough_swap(unsigned long nr_pages)
+{
+ struct sysinfo i;
+
+ si_swapinfo(&i);
+ pr_debug("swsusp: available swap: %lu pages\n", i.freeswap);
+ return i.freeswap > (nr_pages + PAGES_FOR_IO +
+ (nr_pages + PBES_PER_PAGE - 1) / PBES_PER_PAGE);
+}
+
+/**
* write_suspend_image - Write entire image and metadata.
*
*/
@@ -514,6 +542,11 @@
{
int error;
+ if (!enough_swap(nr_copy_pages)) {
+ printk(KERN_ERR "swsusp: Not enough free swap\n");
+ return -ENOSPC;
+ }
+
init_header();
if ((error = data_write()))
goto FreeData;
@@ -533,27 +566,6 @@
goto Done;
}
-/**
- * enough_swap - Make sure we have enough swap to save the image.
- *
- * Returns TRUE or FALSE after checking the total amount of swap
- * space avaiable.
- *
- * FIXME: si_swapinfo(&i) returns all swap devices information.
- * We should only consider resume_device.
- */
-
-int enough_swap(unsigned nr_pages)
-{
- struct sysinfo i;
-
- si_swapinfo(&i);
- pr_debug("swsusp: available swap: %lu pages\n", i.freeswap);
- return i.freeswap > (nr_pages + PAGES_FOR_IO +
- (nr_pages + PBES_PER_PAGE - 1) / PBES_PER_PAGE);
-}
-
-
/* It is important _NOT_ to umount filesystems at this point. We want
* them synced (in case something goes wrong) but we DO not want to mark
* filesystem clean: it is not. (And it does not matter, if we resume
@@ -563,12 +575,15 @@
{
int error;
+ if ((error = swsusp_swap_check())) {
+ printk(KERN_ERR "swsusp: cannot find swap device, try swapon -a.\n");
+ return error;
+ }
lock_swapdevices();
error = write_suspend_image();
/* This will unlock ignored swap devices since writing is finished */
lock_swapdevices();
return error;
-
}
@@ -576,6 +591,7 @@
int swsusp_suspend(void)
{
int error;
+
if ((error = arch_prepare_suspend()))
return error;
local_irq_disable();
@@ -587,15 +603,12 @@
*/
if ((error = device_power_down(PMSG_FREEZE))) {
printk(KERN_ERR "Some devices failed to power down, aborting suspend\n");
- local_irq_enable();
- return error;
+ goto Enable_irqs;
}
- if ((error = swsusp_swap_check())) {
- printk(KERN_ERR "swsusp: cannot find swap device, try swapon -a.\n");
- device_power_up();
- local_irq_enable();
- return error;
+ if ((error = save_highmem())) {
+ printk(KERN_ERR "swsusp: Not enough free pages for highmem\n");
+ goto Restore_highmem;
}
save_processor_state();
@@ -603,8 +616,10 @@
printk(KERN_ERR "Error %d suspending\n", error);
/* Restore control flow magically appears here */
restore_processor_state();
+Restore_highmem:
restore_highmem();
device_power_up();
+Enable_irqs:
local_irq_enable();
return error;
}
@@ -811,7 +826,7 @@
* Reset swap signature now.
*/
error = bio_write_page(0, &swsusp_header);
- } else {
+ } else {
return -EINVAL;
}
if (!error)
Index: linux-2.6.14-git4/kernel/power/power.h
===================================================================
--- linux-2.6.14-git4.orig/kernel/power/power.h 2005-11-01 18:22:12.000000000 +0100
+++ linux-2.6.14-git4/kernel/power/power.h 2005-11-01 18:24:12.000000000 +0100
@@ -65,10 +65,8 @@
extern asmlinkage int swsusp_arch_suspend(void);
extern asmlinkage int swsusp_arch_resume(void);
-extern int restore_highmem(void);
extern void free_pagedir(struct pbe *pblist);
extern struct pbe *alloc_pagedir(unsigned nr_pages, gfp_t gfp_mask, int safe_needed);
extern void create_pbe_list(struct pbe *pblist, unsigned nr_pages);
extern void swsusp_free(void);
extern int alloc_data_pages(struct pbe *pblist, gfp_t gfp_mask, int safe_needed);
-extern int enough_swap(unsigned nr_pages);
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 0/3] swsusp: simplifications and cleanups
2005-11-01 23:00 [PATCH 0/3] swsusp: simplifications and cleanups Rafael J. Wysocki
` (2 preceding siblings ...)
2005-11-01 23:11 ` [PATCH 3/3] swsusp: rework swsusp_suspend Rafael J. Wysocki
@ 2005-11-02 9:49 ` Pavel Machek
2005-11-04 23:04 ` Andrew Morton
4 siblings, 0 replies; 12+ messages in thread
From: Pavel Machek @ 2005-11-02 9:49 UTC (permalink / raw)
To: Rafael J. Wysocki; +Cc: Andrew Morton, LKML
Hi!
> The following series of patches implements some simplifications
> and cleanups of swsusp.
>
> The patches have been acked by Pavel (Pavel, please confirm).
Yes, I have acked those.
Pavel
--
Thanks, Sharp!
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 0/3] swsusp: simplifications and cleanups
2005-11-01 23:00 [PATCH 0/3] swsusp: simplifications and cleanups Rafael J. Wysocki
` (3 preceding siblings ...)
2005-11-02 9:49 ` [PATCH 0/3] swsusp: simplifications and cleanups Pavel Machek
@ 2005-11-04 23:04 ` Andrew Morton
2005-11-05 0:02 ` Rafael J. Wysocki
2005-11-07 22:53 ` [PATCH 0/3][Resend] " Rafael J. Wysocki
4 siblings, 2 replies; 12+ messages in thread
From: Andrew Morton @ 2005-11-04 23:04 UTC (permalink / raw)
To: Rafael J. Wysocki; +Cc: linux-kernel, pavel
"Rafael J. Wysocki" <rjw@sisk.pl> wrote:
>
> The following series of patches implements some simplifications
> and cleanups of swsusp.
Sorry, they clash significantly with other swsusp patches I have here.
Could you please redo these against next -mm?
(Am currently recovering from a few days out-of-town and have a ~300 patch
backlog. Am trying (and struggling) to get -mm1 out by Sunday. I suck).
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 0/3] swsusp: simplifications and cleanups
2005-11-04 23:04 ` Andrew Morton
@ 2005-11-05 0:02 ` Rafael J. Wysocki
2005-11-07 22:53 ` [PATCH 0/3][Resend] " Rafael J. Wysocki
1 sibling, 0 replies; 12+ messages in thread
From: Rafael J. Wysocki @ 2005-11-05 0:02 UTC (permalink / raw)
To: Andrew Morton; +Cc: linux-kernel, pavel
On Saturday, 5 of November 2005 00:04, Andrew Morton wrote:
> "Rafael J. Wysocki" <rjw@sisk.pl> wrote:
> >
> > The following series of patches implements some simplifications
> > and cleanups of swsusp.
>
> Sorry, they clash significantly with other swsusp patches I have here.
> Could you please redo these against next -mm?
Sure, no problem, I will.
Greetings,
Rafael
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 0/3][Resend] swsusp: simplifications and cleanups
2005-11-04 23:04 ` Andrew Morton
2005-11-05 0:02 ` Rafael J. Wysocki
@ 2005-11-07 22:53 ` Rafael J. Wysocki
2005-11-07 22:56 ` [PATCH 1/3][Resend] swsusp: reduce code duplication Rafael J. Wysocki
` (3 more replies)
1 sibling, 4 replies; 12+ messages in thread
From: Rafael J. Wysocki @ 2005-11-07 22:53 UTC (permalink / raw)
To: Andrew Morton; +Cc: linux-kernel, pavel
Hi,
The following series of patches implements some simplifications
and cleanups of swsusp.
The patches have been redone against 2.6.14-mm1, as requested.
Greetings,
Rafael
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 1/3][Resend] swsusp: reduce code duplication
2005-11-07 22:53 ` [PATCH 0/3][Resend] " Rafael J. Wysocki
@ 2005-11-07 22:56 ` Rafael J. Wysocki
2005-11-07 22:57 ` [PATCH 2/3][Resend] swsusp: simplify pagedir relocation Rafael J. Wysocki
` (2 subsequent siblings)
3 siblings, 0 replies; 12+ messages in thread
From: Rafael J. Wysocki @ 2005-11-07 22:56 UTC (permalink / raw)
To: Andrew Morton; +Cc: linux-kernel, pavel
The changes made by this patch are necessary for the pagedir relocation
simplification in the next patch. Additionally, these changes allow us to
drop check_pagedir() and make get_safe_page() be a one-line wrapper around
alloc_image_page() (get_safe_page() goes to snapshot.c, because
alloc_image_page() is static and it does not make sense to export
it).
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
kernel/power/power.h | 3 +-
kernel/power/snapshot.c | 62 +++++++++++++++++++++++++++++++++++++-----------
kernel/power/swsusp.c | 57 +-------------------------------------------
3 files changed, 52 insertions(+), 70 deletions(-)
Index: linux-2.6.14-mm1/kernel/power/power.h
===================================================================
--- linux-2.6.14-mm1.orig/kernel/power/power.h 2005-11-07 22:16:08.000000000 +0100
+++ linux-2.6.14-mm1/kernel/power/power.h 2005-11-07 22:54:16.000000000 +0100
@@ -66,7 +66,8 @@
extern asmlinkage int swsusp_arch_resume(void);
extern int restore_highmem(void);
-extern struct pbe * alloc_pagedir(unsigned nr_pages);
+extern struct pbe *alloc_pagedir(unsigned nr_pages, gfp_t gfp_mask, int safe_needed);
extern void create_pbe_list(struct pbe *pblist, unsigned nr_pages);
extern void swsusp_free(void);
+extern int alloc_data_pages(struct pbe *pblist, gfp_t gfp_mask, int safe_needed);
extern int enough_swap(unsigned nr_pages);
Index: linux-2.6.14-mm1/kernel/power/snapshot.c
===================================================================
--- linux-2.6.14-mm1.orig/kernel/power/snapshot.c 2005-11-07 22:16:08.000000000 +0100
+++ linux-2.6.14-mm1/kernel/power/snapshot.c 2005-11-07 22:54:16.000000000 +0100
@@ -269,9 +269,30 @@
pr_debug("create_pbe_list(): initialized %d PBEs\n", num);
}
-static void *alloc_image_page(void)
+/**
+ * @safe_needed - on resume, for storing the PBE list and the image,
+ * we can only use memory pages that do not conflict with the pages
+ * which had been used before suspend.
+ *
+ * The unsafe pages are marked with the PG_nosave_free flag
+ *
+ * Allocated but unusable (ie eaten) memory pages should be marked
+ * so that swsusp_free() can release them
+ */
+
+static inline void *alloc_image_page(gfp_t gfp_mask, int safe_needed)
{
- void *res = (void *)get_zeroed_page(GFP_ATOMIC | __GFP_COLD);
+ void *res;
+
+ if (safe_needed)
+ do {
+ res = (void *)get_zeroed_page(gfp_mask);
+ if (res && PageNosaveFree(virt_to_page(res)))
+ /* This is for swsusp_free() */
+ SetPageNosave(virt_to_page(res));
+ } while (res && PageNosaveFree(virt_to_page(res)));
+ else
+ res = (void *)get_zeroed_page(gfp_mask);
if (res) {
SetPageNosave(virt_to_page(res));
SetPageNosaveFree(virt_to_page(res));
@@ -279,6 +300,11 @@
return res;
}
+unsigned long get_safe_page(gfp_t gfp_mask)
+{
+ return (unsigned long)alloc_image_page(gfp_mask, 1);
+}
+
/**
* alloc_pagedir - Allocate the page directory.
*
@@ -292,7 +318,7 @@
* On each page we set up a list of struct_pbe elements.
*/
-struct pbe *alloc_pagedir(unsigned int nr_pages)
+struct pbe *alloc_pagedir(unsigned int nr_pages, gfp_t gfp_mask, int safe_needed)
{
unsigned int num;
struct pbe *pblist, *pbe;
@@ -301,12 +327,12 @@
return NULL;
pr_debug("alloc_pagedir(): nr_pages = %d\n", nr_pages);
- pblist = alloc_image_page();
+ pblist = alloc_image_page(gfp_mask, safe_needed);
/* FIXME: rewrite this ugly loop */
for (pbe = pblist, num = PBES_PER_PAGE; pbe && num < nr_pages;
pbe = pbe->next, num += PBES_PER_PAGE) {
pbe += PB_PAGE_SKIP;
- pbe->next = alloc_image_page();
+ pbe->next = alloc_image_page(gfp_mask, safe_needed);
}
if (!pbe) { /* get_zeroed_page() failed */
free_pagedir(pblist);
@@ -354,24 +380,32 @@
(nr_pages + PBES_PER_PAGE - 1) / PBES_PER_PAGE);
}
+int alloc_data_pages(struct pbe *pblist, gfp_t gfp_mask, int safe_needed)
+{
+ struct pbe *p;
+
+ for_each_pbe (p, pblist) {
+ p->address = (unsigned long)alloc_image_page(gfp_mask, safe_needed);
+ if (!p->address)
+ return -ENOMEM;
+ }
+ return 0;
+}
static struct pbe *swsusp_alloc(unsigned int nr_pages)
{
- struct pbe *pblist, *p;
+ struct pbe *pblist;
- if (!(pblist = alloc_pagedir(nr_pages))) {
+ if (!(pblist = alloc_pagedir(nr_pages, GFP_ATOMIC | __GFP_COLD, 0))) {
printk(KERN_ERR "suspend: Allocating pagedir failed.\n");
return NULL;
}
create_pbe_list(pblist, nr_pages);
- for_each_pbe (p, pblist) {
- p->address = (unsigned long)alloc_image_page();
- if (!p->address) {
- printk(KERN_ERR "suspend: Allocating image pages failed.\n");
- swsusp_free();
- return NULL;
- }
+ if (alloc_data_pages(pblist, GFP_ATOMIC | __GFP_COLD, 0)) {
+ printk(KERN_ERR "suspend: Allocating image pages failed.\n");
+ swsusp_free();
+ return NULL;
}
return pblist;
Index: linux-2.6.14-mm1/kernel/power/swsusp.c
===================================================================
--- linux-2.6.14-mm1.orig/kernel/power/swsusp.c 2005-11-07 22:16:08.000000000 +0100
+++ linux-2.6.14-mm1/kernel/power/swsusp.c 2005-11-07 22:54:16.000000000 +0100
@@ -629,59 +629,6 @@
}
/**
- * On resume, for storing the PBE list and the image,
- * we can only use memory pages that do not conflict with the pages
- * which had been used before suspend.
- *
- * We don't know which pages are usable until we allocate them.
- *
- * Allocated but unusable (ie eaten) memory pages are marked so that
- * swsusp_free() can release them
- */
-
-unsigned long get_safe_page(gfp_t gfp_mask)
-{
- unsigned long m;
-
- do {
- m = get_zeroed_page(gfp_mask);
- if (m && PageNosaveFree(virt_to_page(m)))
- /* This is for swsusp_free() */
- SetPageNosave(virt_to_page(m));
- } while (m && PageNosaveFree(virt_to_page(m)));
- if (m) {
- /* This is for swsusp_free() */
- SetPageNosave(virt_to_page(m));
- SetPageNosaveFree(virt_to_page(m));
- }
- return m;
-}
-
-/**
- * check_pagedir - We ensure here that pages that the PBEs point to
- * won't collide with pages where we're going to restore from the loaded
- * pages later
- */
-
-static int check_pagedir(struct pbe *pblist)
-{
- struct pbe *p;
-
- /* This is necessary, so that we can free allocated pages
- * in case of failure
- */
- for_each_pbe (p, pblist)
- p->address = 0UL;
-
- for_each_pbe (p, pblist) {
- p->address = get_safe_page(GFP_ATOMIC);
- if (!p->address)
- return -ENOMEM;
- }
- return 0;
-}
-
-/**
* swsusp_pagedir_relocate - It is possible, that some memory pages
* occupied by the list of PBEs collide with pages where we're going to
* restore from the loaded pages later. We relocate them here.
@@ -990,7 +937,7 @@
int error = 0;
struct pbe *p;
- if (!(p = alloc_pagedir(nr_copy_pages)))
+ if (!(p = alloc_pagedir(nr_copy_pages, GFP_ATOMIC, 0)))
return -ENOMEM;
if ((error = read_pagedir(p)))
@@ -1003,7 +950,7 @@
/* Allocate memory for the image and read the data from swap */
- error = check_pagedir(pagedir_nosave);
+ error = alloc_data_pages(pagedir_nosave, GFP_ATOMIC, 1);
if (!error)
error = data_read(pagedir_nosave);
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 2/3][Resend] swsusp: simplify pagedir relocation
2005-11-07 22:53 ` [PATCH 0/3][Resend] " Rafael J. Wysocki
2005-11-07 22:56 ` [PATCH 1/3][Resend] swsusp: reduce code duplication Rafael J. Wysocki
@ 2005-11-07 22:57 ` Rafael J. Wysocki
2005-11-07 22:59 ` [PATCH 3/3][Resend] swsusp: rework swsusp_suspend Rafael J. Wysocki
2005-11-08 9:00 ` [PATCH 0/3][Resend] swsusp: simplifications and cleanups Pavel Machek
3 siblings, 0 replies; 12+ messages in thread
From: Rafael J. Wysocki @ 2005-11-07 22:57 UTC (permalink / raw)
To: Andrew Morton; +Cc: linux-kernel, pavel
This patch simplifies the relocation of the page backup list (aka pagedir)
during resume.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
kernel/power/power.h | 1
kernel/power/snapshot.c | 2 -
kernel/power/swsusp.c | 78 ++++++++++++++++--------------------------------
3 files changed, 28 insertions(+), 53 deletions(-)
Index: linux-2.6.14-mm1/kernel/power/swsusp.c
===================================================================
--- linux-2.6.14-mm1.orig/kernel/power/swsusp.c 2005-11-07 22:54:16.000000000 +0100
+++ linux-2.6.14-mm1/kernel/power/swsusp.c 2005-11-07 22:56:05.000000000 +0100
@@ -629,74 +629,43 @@
}
/**
- * swsusp_pagedir_relocate - It is possible, that some memory pages
- * occupied by the list of PBEs collide with pages where we're going to
- * restore from the loaded pages later. We relocate them here.
+ * mark_unsafe_pages - mark the pages that cannot be used for storing
+ * the image during resume, because they conflict with the pages that
+ * had been used before suspend
*/
-static struct pbe *swsusp_pagedir_relocate(struct pbe *pblist)
+static void mark_unsafe_pages(struct pbe *pblist)
{
struct zone *zone;
unsigned long zone_pfn;
- struct pbe *pbpage, *tail, *p;
- void *m;
- int rel = 0;
+ struct pbe *p;
if (!pblist) /* a sanity check */
- return NULL;
-
- pr_debug("swsusp: Relocating pagedir (%lu pages to check)\n",
- swsusp_info.pagedir_pages);
+ return;
/* Clear page flags */
-
for_each_zone (zone) {
- for (zone_pfn = 0; zone_pfn < zone->spanned_pages; ++zone_pfn)
- if (pfn_valid(zone_pfn + zone->zone_start_pfn))
- ClearPageNosaveFree(pfn_to_page(zone_pfn +
+ for (zone_pfn = 0; zone_pfn < zone->spanned_pages; ++zone_pfn)
+ if (pfn_valid(zone_pfn + zone->zone_start_pfn))
+ ClearPageNosaveFree(pfn_to_page(zone_pfn +
zone->zone_start_pfn));
}
/* Mark orig addresses */
-
for_each_pbe (p, pblist)
SetPageNosaveFree(virt_to_page(p->orig_address));
- tail = pblist + PB_PAGE_SKIP;
-
- /* Relocate colliding pages */
-
- for_each_pb_page (pbpage, pblist) {
- if (PageNosaveFree(virt_to_page((unsigned long)pbpage))) {
- m = (void *)get_safe_page(GFP_ATOMIC | __GFP_COLD);
- if (!m)
- return NULL;
- memcpy(m, (void *)pbpage, PAGE_SIZE);
- if (pbpage == pblist)
- pblist = (struct pbe *)m;
- else
- tail->next = (struct pbe *)m;
- pbpage = (struct pbe *)m;
-
- /* We have to link the PBEs again */
- for (p = pbpage; p < pbpage + PB_PAGE_SKIP; p++)
- if (p->next) /* needed to save the end */
- p->next = p + 1;
-
- rel++;
- }
- tail = pbpage + PB_PAGE_SKIP;
- }
+}
- /* This is for swsusp_free() */
- for_each_pb_page (pbpage, pblist) {
- SetPageNosave(virt_to_page(pbpage));
- SetPageNosaveFree(virt_to_page(pbpage));
+static void copy_page_backup_list(struct pbe *dst, struct pbe *src)
+{
+ /* We assume both lists contain the same number of elements */
+ while (src) {
+ dst->orig_address = src->orig_address;
+ dst->swap_address = src->swap_address;
+ dst = dst->next;
+ src = src->next;
}
-
- printk("swsusp: Relocated %d pages\n", rel);
-
- return pblist;
}
/*
@@ -942,10 +911,15 @@
if ((error = read_pagedir(p)))
return error;
-
create_pbe_list(p, nr_copy_pages);
-
- if (!(pagedir_nosave = swsusp_pagedir_relocate(p)))
+ mark_unsafe_pages(p);
+ pagedir_nosave = alloc_pagedir(nr_copy_pages, GFP_ATOMIC, 1);
+ if (pagedir_nosave) {
+ create_pbe_list(pagedir_nosave, nr_copy_pages);
+ copy_page_backup_list(pagedir_nosave, p);
+ }
+ free_pagedir(p);
+ if (!pagedir_nosave)
return -ENOMEM;
/* Allocate memory for the image and read the data from swap */
Index: linux-2.6.14-mm1/kernel/power/power.h
===================================================================
--- linux-2.6.14-mm1.orig/kernel/power/power.h 2005-11-07 22:54:16.000000000 +0100
+++ linux-2.6.14-mm1/kernel/power/power.h 2005-11-07 22:56:05.000000000 +0100
@@ -66,6 +66,7 @@
extern asmlinkage int swsusp_arch_resume(void);
extern int restore_highmem(void);
+extern void free_pagedir(struct pbe *pblist);
extern struct pbe *alloc_pagedir(unsigned nr_pages, gfp_t gfp_mask, int safe_needed);
extern void create_pbe_list(struct pbe *pblist, unsigned nr_pages);
extern void swsusp_free(void);
Index: linux-2.6.14-mm1/kernel/power/snapshot.c
===================================================================
--- linux-2.6.14-mm1.orig/kernel/power/snapshot.c 2005-11-07 22:54:16.000000000 +0100
+++ linux-2.6.14-mm1/kernel/power/snapshot.c 2005-11-07 22:56:05.000000000 +0100
@@ -216,7 +216,7 @@
* free_pagedir - free pages allocated with alloc_pagedir()
*/
-static void free_pagedir(struct pbe *pblist)
+void free_pagedir(struct pbe *pblist)
{
struct pbe *pbe;
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 3/3][Resend] swsusp: rework swsusp_suspend
2005-11-07 22:53 ` [PATCH 0/3][Resend] " Rafael J. Wysocki
2005-11-07 22:56 ` [PATCH 1/3][Resend] swsusp: reduce code duplication Rafael J. Wysocki
2005-11-07 22:57 ` [PATCH 2/3][Resend] swsusp: simplify pagedir relocation Rafael J. Wysocki
@ 2005-11-07 22:59 ` Rafael J. Wysocki
2005-11-08 9:00 ` [PATCH 0/3][Resend] swsusp: simplifications and cleanups Pavel Machek
3 siblings, 0 replies; 12+ messages in thread
From: Rafael J. Wysocki @ 2005-11-07 22:59 UTC (permalink / raw)
To: Andrew Morton; +Cc: linux-kernel, pavel
This patch makes only the functions in swsusp.c call functions in
snapshot.c and not both ways. It also moves the check for available swap
out of swsusp_suspend() which is necessary for separating the swap-handling
functions in swsusp from the core code.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
kernel/power/power.h | 2 -
kernel/power/snapshot.c | 19 +-----------
kernel/power/swsusp.c | 75 ++++++++++++++++++++++++++++--------------------
3 files changed, 47 insertions(+), 49 deletions(-)
Index: linux-2.6.14-mm1/kernel/power/snapshot.c
===================================================================
--- linux-2.6.14-mm1.orig/kernel/power/snapshot.c 2005-11-07 22:56:05.000000000 +0100
+++ linux-2.6.14-mm1/kernel/power/snapshot.c 2005-11-07 22:58:02.000000000 +0100
@@ -88,8 +88,7 @@
return 0;
}
-
-static int save_highmem(void)
+int save_highmem(void)
{
struct zone *zone;
int res = 0;
@@ -120,11 +119,7 @@
}
return 0;
}
-#else
-static int save_highmem(void) { return 0; }
-int restore_highmem(void) { return 0; }
-#endif /* CONFIG_HIGHMEM */
-
+#endif
static int pfn_is_nosave(unsigned long pfn)
{
@@ -416,11 +411,6 @@
unsigned int nr_pages;
pr_debug("swsusp: critical section: \n");
- if (save_highmem()) {
- printk(KERN_CRIT "swsusp: Not enough free pages for highmem\n");
- restore_highmem();
- return -ENOMEM;
- }
drain_local_pages();
nr_pages = count_data_pages();
@@ -440,11 +430,6 @@
return -ENOMEM;
}
- if (!enough_swap(nr_pages)) {
- printk(KERN_ERR "swsusp: Not enough free swap\n");
- return -ENOSPC;
- }
-
pagedir_nosave = swsusp_alloc(nr_pages);
if (!pagedir_nosave)
return -ENOMEM;
Index: linux-2.6.14-mm1/kernel/power/swsusp.c
===================================================================
--- linux-2.6.14-mm1.orig/kernel/power/swsusp.c 2005-11-07 22:56:05.000000000 +0100
+++ linux-2.6.14-mm1/kernel/power/swsusp.c 2005-11-07 22:58:02.000000000 +0100
@@ -73,6 +73,14 @@
#include "power.h"
+#ifdef CONFIG_HIGHMEM
+int save_highmem(void);
+int restore_highmem(void);
+#else
+static int save_highmem(void) { return 0; }
+static int restore_highmem(void) { return 0; }
+#endif
+
#define CIPHER "aes"
#define MAXKEY 32
#define MAXIV 32
@@ -500,6 +508,26 @@
}
/**
+ * enough_swap - Make sure we have enough swap to save the image.
+ *
+ * Returns TRUE or FALSE after checking the total amount of swap
+ * space avaiable.
+ *
+ * FIXME: si_swapinfo(&i) returns all swap devices information.
+ * We should only consider resume_device.
+ */
+
+static int enough_swap(unsigned int nr_pages)
+{
+ struct sysinfo i;
+
+ si_swapinfo(&i);
+ pr_debug("swsusp: available swap: %lu pages\n", i.freeswap);
+ return i.freeswap > (nr_pages + PAGES_FOR_IO +
+ (nr_pages + PBES_PER_PAGE - 1) / PBES_PER_PAGE);
+}
+
+/**
* write_suspend_image - Write entire image and metadata.
*
*/
@@ -507,6 +535,11 @@
{
int error;
+ if (!enough_swap(nr_copy_pages)) {
+ printk(KERN_ERR "swsusp: Not enough free swap\n");
+ return -ENOSPC;
+ }
+
init_header();
if ((error = data_write()))
goto FreeData;
@@ -526,27 +559,6 @@
goto Done;
}
-/**
- * enough_swap - Make sure we have enough swap to save the image.
- *
- * Returns TRUE or FALSE after checking the total amount of swap
- * space avaiable.
- *
- * FIXME: si_swapinfo(&i) returns all swap devices information.
- * We should only consider resume_device.
- */
-
-int enough_swap(unsigned int nr_pages)
-{
- struct sysinfo i;
-
- si_swapinfo(&i);
- pr_debug("swsusp: available swap: %lu pages\n", i.freeswap);
- return i.freeswap > (nr_pages + PAGES_FOR_IO +
- (nr_pages + PBES_PER_PAGE - 1) / PBES_PER_PAGE);
-}
-
-
/* It is important _NOT_ to umount filesystems at this point. We want
* them synced (in case something goes wrong) but we DO not want to mark
* filesystem clean: it is not. (And it does not matter, if we resume
@@ -556,12 +568,15 @@
{
int error;
+ if ((error = swsusp_swap_check())) {
+ printk(KERN_ERR "swsusp: cannot find swap device, try swapon -a.\n");
+ return error;
+ }
lock_swapdevices();
error = write_suspend_image();
/* This will unlock ignored swap devices since writing is finished */
lock_swapdevices();
return error;
-
}
@@ -569,6 +584,7 @@
int swsusp_suspend(void)
{
int error;
+
if ((error = arch_prepare_suspend()))
return error;
local_irq_disable();
@@ -580,15 +596,12 @@
*/
if ((error = device_power_down(PMSG_FREEZE))) {
printk(KERN_ERR "Some devices failed to power down, aborting suspend\n");
- local_irq_enable();
- return error;
+ goto Enable_irqs;
}
- if ((error = swsusp_swap_check())) {
- printk(KERN_ERR "swsusp: cannot find swap device, try swapon -a.\n");
- device_power_up();
- local_irq_enable();
- return error;
+ if ((error = save_highmem())) {
+ printk(KERN_ERR "swsusp: Not enough free pages for highmem\n");
+ goto Restore_highmem;
}
save_processor_state();
@@ -596,8 +609,10 @@
printk(KERN_ERR "Error %d suspending\n", error);
/* Restore control flow magically appears here */
restore_processor_state();
+Restore_highmem:
restore_highmem();
device_power_up();
+Enable_irqs:
local_irq_enable();
return error;
}
@@ -804,7 +819,7 @@
* Reset swap signature now.
*/
error = bio_write_page(0, &swsusp_header);
- } else {
+ } else {
return -EINVAL;
}
if (!error)
Index: linux-2.6.14-mm1/kernel/power/power.h
===================================================================
--- linux-2.6.14-mm1.orig/kernel/power/power.h 2005-11-07 22:56:05.000000000 +0100
+++ linux-2.6.14-mm1/kernel/power/power.h 2005-11-07 22:58:02.000000000 +0100
@@ -65,10 +65,8 @@
extern asmlinkage int swsusp_arch_suspend(void);
extern asmlinkage int swsusp_arch_resume(void);
-extern int restore_highmem(void);
extern void free_pagedir(struct pbe *pblist);
extern struct pbe *alloc_pagedir(unsigned nr_pages, gfp_t gfp_mask, int safe_needed);
extern void create_pbe_list(struct pbe *pblist, unsigned nr_pages);
extern void swsusp_free(void);
extern int alloc_data_pages(struct pbe *pblist, gfp_t gfp_mask, int safe_needed);
-extern int enough_swap(unsigned nr_pages);
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 0/3][Resend] swsusp: simplifications and cleanups
2005-11-07 22:53 ` [PATCH 0/3][Resend] " Rafael J. Wysocki
` (2 preceding siblings ...)
2005-11-07 22:59 ` [PATCH 3/3][Resend] swsusp: rework swsusp_suspend Rafael J. Wysocki
@ 2005-11-08 9:00 ` Pavel Machek
3 siblings, 0 replies; 12+ messages in thread
From: Pavel Machek @ 2005-11-08 9:00 UTC (permalink / raw)
To: Rafael J. Wysocki; +Cc: Andrew Morton, linux-kernel
Hi!
> The following series of patches implements some simplifications
> and cleanups of swsusp.
>
> The patches have been redone against 2.6.14-mm1, as requested.
The patches look good, I have already ACKed them before.
Pavel
--
Thanks, Sharp!
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2005-11-08 9:00 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-01 23:00 [PATCH 0/3] swsusp: simplifications and cleanups Rafael J. Wysocki
2005-11-01 23:04 ` [PATCH 1/3] swsusp: reduce code duplication Rafael J. Wysocki
2005-11-01 23:07 ` [PATCH 2/3] swsusp: simplify pagedir relocation Rafael J. Wysocki
2005-11-01 23:11 ` [PATCH 3/3] swsusp: rework swsusp_suspend Rafael J. Wysocki
2005-11-02 9:49 ` [PATCH 0/3] swsusp: simplifications and cleanups Pavel Machek
2005-11-04 23:04 ` Andrew Morton
2005-11-05 0:02 ` Rafael J. Wysocki
2005-11-07 22:53 ` [PATCH 0/3][Resend] " Rafael J. Wysocki
2005-11-07 22:56 ` [PATCH 1/3][Resend] swsusp: reduce code duplication Rafael J. Wysocki
2005-11-07 22:57 ` [PATCH 2/3][Resend] swsusp: simplify pagedir relocation Rafael J. Wysocki
2005-11-07 22:59 ` [PATCH 3/3][Resend] swsusp: rework swsusp_suspend Rafael J. Wysocki
2005-11-08 9:00 ` [PATCH 0/3][Resend] swsusp: simplifications and cleanups Pavel Machek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).