Skip to contentSkip to conversation

swsusp: fix handling of highmem

PATCH In review Rafael J. Wysocki 2 participants 4 messages Dec 4, 2005

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

cover swsusp: fix handling of highmem

Hi,

The following two patches are necessary to fix the way in which swsusp (in the current -mm) handles highmem.

The patches have been acked by Pavel (Pavel, please confirm).

Please apply.

Greetings,
Rafael

Signature · 1 line
Beer is proof that God loves us and wants us to be happy - Benjamin Franklin
#1 lore raw

PATCH 1/2 swsusp: fix counting of highmem pages

This patch fixes a problem with swsusp that causes suspend to fail on systems with the highmem zone, if many highmem pages are in use.

The patch makes swsusp count the non-free highmem pages in a correct way and, consequently, release a sufficient amount of memory before suspend.

 kernel/power/swsusp.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletion(-)
kernel/power/swsusp.c +2 -1
Index: linux-2.6.15-rc3-mm1/kernel/power/swsusp.c
===================================================================
@@ -635,7 +635,8 @@
 	printk("Shrinking memory...  ");
 	do {
 #ifdef FAST_FREE
-		tmp = count_data_pages() + count_highmem_pages();
+		tmp = 2 * count_highmem_pages();
+		tmp += tmp / 50 + count_data_pages();
 		tmp += (tmp + PBES_PER_PAGE - 1) / PBES_PER_PAGE +
 			PAGES_FOR_IO;
 		for_each_zone (zone)
#2 lore raw

PATCH 2/2 swsusp: fix enough_free_mem

In reply to Rafael J. Wysocki

This patch fixes a problem with the function enough_free_mem() used by swsusp to verify if there is a sufficient number of memory pages available to it to create and save the suspend image.

Namely, enough_free_mem() uses nr_free_pages() to obtain the number of free memory pages, which is incorrect, because this function returns the total number of free pages, including free highmem pages, and the highmem pages cannot be used by swsusp for storing the image data.

The patch makes enough_free_mem() avoid counting the free highmem pages as available to swsusp.

 kernel/power/snapshot.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)
kernel/power/snapshot.c +8 -2
Index: linux-2.6.15-rc3-mm1/kernel/power/snapshot.c
===================================================================
@@ -437,8 +437,14 @@
 
 static int enough_free_mem(unsigned int nr_pages)
 {
-	pr_debug("swsusp: available memory: %u pages\n", nr_free_pages());
-	return nr_free_pages() > (nr_pages + PAGES_FOR_IO +
+	struct zone *zone;
+	unsigned int n = 0;
+
+	for_each_zone (zone)
+		if (!is_highmem(zone))
+			n += zone->free_pages;
+	pr_debug("swsusp: available memory: %u pages\n", n);
+	return n > (nr_pages + PAGES_FOR_IO +
 		(nr_pages + PBES_PER_PAGE - 1) / PBES_PER_PAGE);
 }
 
#3 lore raw
In reply to Rafael J. Wysocki

Hi!

Quoted 4 lines

The following two patches are necessary to fix the way in which swsusp (in the current -mm) handles highmem.

The patches have been acked by Pavel (Pavel, please confirm).

ACK and thakns. (Sorry if you get this twice).
Pavel

Signature · 1 line
Thanks, Sharp!