Skip to contentSkip to conversation

swsusp update: supports discontingmem/highmem

PATCH Pavel Machek 3 participants 5 messages Apr 5, 2004 – Apr 6, 2004

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi!

wli did some work on this... It makes swsusp behave correctly w.r.t. discontingmem, and adds highmem handling (very simple-minded, but should work ok with 1GB). It now should behave correctly w.r.t. more than one swap device, and fixes double restoring of console. Please apply,

Pavel

[okay, this probably should receive some -mm testing before going mainline.]

include/linux/suspend.h +1 -1
Index: linux/include/linux/suspend.h
===================================================================
@@ -24,7 +24,7 @@
 #define SWAP_FILENAME_MAXLENGTH	32
 
 struct suspend_header {
-	__u32 version_code;
+	u32 version_code;
 	unsigned long num_physpages;
 	char machine[8];
 	char version[20];
kernel/power/swsusp.c +173 -73

354 lines not on this page · raw message

Signature · 2 lines
When do you have a heart between your knees?
[Johanka's followup: and *two* hearts?]
#1 lore raw
Quoted 3 lines · Pavel Machek

It makes swsusp behave correctly
w.r.t. discontingmem, and adds highmem handling

Some of those ENOMEM panics in save_highmem_zone() look like they might need proper handling instead?

The 256 byte automatic array in read_swapfiles() may bring you a visit from the stack space police, although I don't think it's really a problem. 256 bytes for a pathname may be a bit excessive though.

Please send me an update patch sometime which makes all the new code go away again if !CONFIG_HIGHMEM.

Thanks.

#2 lore raw

Hi!

Quoted 5 lines
Quoted 2 lines

It makes swsusp behave correctly
w.r.t. discontingmem, and adds highmem handling

Some of those ENOMEM panics in save_highmem_zone() look like they might need proper handling instead?

Done.

Quoted 3 lines

The 256 byte automatic array in read_swapfiles() may bring you a visit from the stack space police, although I don't think it's really a problem. 256 bytes for a pathname may be a bit excessive though.

Marked static, its only called once anyway.

Quoted 2 lines

Please send me an update patch sometime which makes all the new code go away again if !CONFIG_HIGHMEM.

Done; plus I added some warnings to swsusp.S (based on discussion with wli). Relative to previous diff, please apply.
Pavel

arch/i386/power/swsusp.S renamed from linux/arch/i386/power/swsusp.S +8 -1
@@ -1,6 +1,13 @@
 .text
 
-/* Originally gcc generated, modified by hand */
+/* Originally gcc generated, modified by hand
+ *
+ * This may not use any stack, nor any variable that is not "NoSave":
+ *
+ * Its rewriting one kernel image with another. What is stack in "old"
+ * image could very well be data page in "new" image, and overwriting
+ * your own stack under you is bad idea.
+ */
 
 #include <linux/linkage.h>
 #include <asm/segment.h>
kernel/power/swsusp.c renamed from linux/kernel/power/swsusp.c +38 -21

159 lines not on this page · raw message

Signature · 2 lines
When do you have a heart between your knees?
[Johanka's followup: and *two* hearts?]
#3 lore raw
In reply to Pavel Machek

Hi.

kernel/power/swsusp.c line 401

Quoted 4 lines · Pavel Machek
kernel/power/swsusp.c +4 -0
+		if (PageReserved(page)) {
+			printk("highmem reserved page?!\n");
+			BUG();
+		}

We dealt with this recently in suspend2. It's perfectly valid to have a Reserved Highmem page. They need to be completely ignored, and whatever driver is responsible for the memory should handle any required state persistance. We're setting NoSave for such pages in the parsing of the e820 table at boot time.

Review

Quoted 2 lines
(quoted diff) +2 -0
+		if (!save)
+			panic("Not enough memory");

Can't you back out nicely if you don't have enough memory for the image?

kernel/power/swsusp.c line 414

Quoted 2 lines
kernel/power/swsusp.c +2 -0
+		if (!save->data)
+			panic("Not enough memory");

(Ditto)

kernel/power/swsusp.c line 713

Quoted 1 line
kernel/power/swsusp.c +1 -0
+	/* Fixme: this is too late; we should do this ASAP to avoid "infinite reboots" problem */

Fully agree. I've been meaning to do this too.

Regards,

Nigel

Signature · 7 lines
Nigel Cunningham
C/- Westminster Presbyterian Church Belconnen
61 Templeton Street, Cook, ACT 2614.
+61 (2) 6251 7727(wk); +61 (2) 6253 0250 (home)

Evolution (n): A hypothetical process whereby infinitely improbable events occur 
with alarming frequency, order arises from chaos, and no one is given credit.
#4 lore raw

Hi!

Quoted 11 lines · Pavel Machek

Review

Quoted 4 lines
(quoted diff) +4 -0
+		if (PageReserved(page)) {
+			printk("highmem reserved page?!\n");
+			BUG();
+		}

We dealt with this recently in suspend2. It's perfectly valid to have a Reserved Highmem page. They need to be completely ignored, and whatever driver is responsible for the memory should handle any required state persistance. We're setting NoSave for such pages in the parsing of the e820 table at boot time.

Okay, I changed BUG() into continue. I still left printk, so that when something goes wrong, we still know.

Quoted 9 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+		if (!save)
+			panic("Not enough memory");

Can't you back out nicely if you don't have enough memory for the image?

Review

Quoted 2 lines
(quoted diff) +2 -0
+		if (!save->data)
+			panic("Not enough memory");

(Ditto)

Ugh. I had this in my tree, unfortunately in my other tree. Here's the diff. (Do not apply it just yet, I'll add #ifdef CONFIG_HIGHMEMs).

Pavel

kernel/power/swsusp.c +27 -18
@@ -374,7 +374,7 @@
 
 struct highmem_page *highmem_copy = NULL;
 
-static void save_highmem_zone(struct zone *zone)
+static int save_highmem_zone(struct zone *zone)
 {
 	unsigned long zone_pfn;
 	for (zone_pfn = 0; zone_pfn < zone->spanned_pages; ++zone_pfn) {
@@ -384,7 +384,7 @@
 		unsigned long pfn = zone_pfn + zone->zone_start_pfn;
 		int chunk_size;
 
-		if (!(pfn%200))
+		if (!(pfn%1000))
 			printk(".");
 		if (!pfn_valid(pfn))
 			continue;
@@ -406,26 +406,33 @@
 		}
 		save = kmalloc(sizeof(struct highmem_page), GFP_ATOMIC);
 		if (!save)
-			panic("Not enough memory");
+			return -ENOMEM;
 		save->next = highmem_copy;
 		save->page = page;
 		save->data = (void *) get_zeroed_page(GFP_ATOMIC);
-		if (!save->data)
-			panic("Not enough memory");
+		if (!save->data) {
+			kfree(save);
+			return -ENOMEM;
+		}
 		kaddr = kmap_atomic(page, KM_USER0);
 		memcpy(save->data, kaddr, PAGE_SIZE);
 		kunmap_atomic(kaddr, KM_USER0);
 		highmem_copy = save;
 	}
+	return 0;
 }
 
-static void save_highmem(void)
+static int save_highmem(void)
 {
 	struct zone *zone;
+	int res = 0;
 	for_each_zone(zone) {
 		if (is_highmem(zone))
-			save_highmem_zone(zone);
+			res = save_highmem_zone(zone);
+		if (res)
+			return res;
 	}
+	return 0;
 }
 
 static int restore_highmem(void)
@@ -460,7 +467,7 @@
 		struct page *page;
 		unsigned long pfn = zone_pfn + zone->zone_start_pfn;
 
-		if (!(pfn%200))
+		if (!(pfn%1000))
 			printk(".");
 		if (!pfn_valid(pfn))
 			continue;
@@ -539,7 +546,7 @@
 	pagedir_order = get_bitmask_order(SUSPEND_PD_PAGES(nr_copy_pages));
 
 	p = pagedir = (suspend_pagedir_t *)__get_free_pages(GFP_ATOMIC | __GFP_COLD, pagedir_order);
-	if(!pagedir)
+	if (!pagedir)
 		return NULL;
 
 	page = virt_to_page(pagedir);
@@ -548,7 +555,7 @@
 		
 	while(nr_copy_pages--) {
 		p->address = get_zeroed_page(GFP_ATOMIC | __GFP_COLD);
-		if(!p->address) {
+		if (!p->address) {
 			free_suspend_pagedir((unsigned long) pagedir);
 			return NULL;
 		}
@@ -590,7 +597,10 @@
 
 	pagedir_nosave = NULL;
 	printk( "/critical section: Handling highmem" );
-	save_highmem();
+	if (save_highmem()) {
+		printk(KERN_CRIT "%sNot enough free pages for highmem\n", name_suspend);
+		return -ENOMEM;
+	}
 
 	printk(", counting pages to copy" );
 	drain_local_pages();
@@ -602,23 +612,22 @@
 		printk(KERN_CRIT "%sCouldn't get enough free pages, on %d pages short\n",
 		       name_suspend, nr_needed_pages-nr_free_pages());
 		root_swap = 0xFFFF;
-		return 1;
+		return -ENOMEM;
 	}
 	si_swapinfo(&i);	/* FIXME: si_swapinfo(&i) returns all swap devices information.
 				   We should only consider resume_device. */
 	if (i.freeswap < nr_needed_pages)  {
 		printk(KERN_CRIT "%sThere's not enough swap space available, on %ld pages short\n",
 		       name_suspend, nr_needed_pages-i.freeswap);
-		return 1;
+		return -ENOSPC;
 	}
 
 	PRINTK( "Alloc pagedir\n" ); 
 	pagedir_save = pagedir_nosave = create_suspend_pagedir(nr_copy_pages);
-	if(!pagedir_nosave) {
-		/* Shouldn't happen */
-		printk(KERN_CRIT "%sCouldn't allocate enough pages\n",name_suspend);
-		panic("Really should not happen");
-		return 1;
+	if (!pagedir_nosave) {
+		/* Pagedir is big, one-chunk allocation. It is easily possible for this allocation to fail */
+		printk(KERN_CRIT "%sCouldn't allocate continuous pagedir\n", name_suspend);
+		return -ENOMEM;
 	}
 	nr_copy_pages_check = nr_copy_pages;
 	pagedir_order_check = pagedir_order;
Signature · 2 lines
When do you have a heart between your knees?
[Johanka's followup: and *two* hearts?]