[PATCH] swsusp: Fix mark_free_pages
authorRafael J. Wysocki <rjw@sisk.pl>
Tue, 26 Sep 2006 06:32:49 +0000 (23:32 -0700)
committerLinus Torvalds <torvalds@g5.osdl.org>
Tue, 26 Sep 2006 15:48:59 +0000 (08:48 -0700)
Clean up mm/page_alloc.c#mark_free_pages() and make it avoid clearing
PageNosaveFree for PageNosave pages.  This allows us to get rid of an ugly
hack in kernel/power/snapshot.c#copy_data_pages().

Additionally, the page-copying loop in copy_data_pages() is moved to an
inline function.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
kernel/power/snapshot.c
mm/page_alloc.c

index 81fe8de9e6040ac68b3e91ff27d25d3dbf91b2dd..4afb7900002bafc7e8d07a9db3c141db4dfa975a 100644 (file)
@@ -208,37 +208,36 @@ unsigned int count_data_pages(void)
        return n;
 }
 
+static inline void copy_data_page(long *dst, long *src)
+{
+       int n;
+
+       /* copy_page and memcpy are not usable for copying task structs. */
+       for (n = PAGE_SIZE / sizeof(long); n; n--)
+               *dst++ = *src++;
+}
+
 static void copy_data_pages(struct pbe *pblist)
 {
        struct zone *zone;
        unsigned long pfn, max_zone_pfn;
-       struct pbe *pbe, *p;
+       struct pbe *pbe;
 
        pbe = pblist;
        for_each_zone (zone) {
                if (is_highmem(zone))
                        continue;
                mark_free_pages(zone);
-               /* This is necessary for swsusp_free() */
-               for_each_pb_page (p, pblist)
-                       SetPageNosaveFree(virt_to_page(p));
-               for_each_pbe (p, pblist)
-                       SetPageNosaveFree(virt_to_page(p->address));
                max_zone_pfn = zone->zone_start_pfn + zone->spanned_pages;
                for (pfn = zone->zone_start_pfn; pfn < max_zone_pfn; pfn++) {
                        struct page *page = saveable_page(pfn);
 
                        if (page) {
-                               long *src, *dst;
-                               int n;
+                               void *ptr = page_address(page);
 
                                BUG_ON(!pbe);
-                               pbe->orig_address = (unsigned long)page_address(page);
-                               /* copy_page and memcpy are not usable for copying task structs. */
-                               dst = (long *)pbe->address;
-                               src = (long *)pbe->orig_address;
-                               for (n = PAGE_SIZE / sizeof(long); n; n--)
-                                       *dst++ = *src++;
+                               copy_data_page((void *)pbe->address, ptr);
+                               pbe->orig_address = (unsigned long)ptr;
                                pbe = pbe->next;
                        }
                }
index 51070b6d593f9b71d12a05d7246a5323b44ea3f3..9810f0a60db7720da211386298422e138341e16e 100644 (file)
@@ -694,7 +694,8 @@ static void __drain_pages(unsigned int cpu)
 
 void mark_free_pages(struct zone *zone)
 {
-       unsigned long zone_pfn, flags;
+       unsigned long pfn, max_zone_pfn;
+       unsigned long flags;
        int order;
        struct list_head *curr;
 
@@ -702,18 +703,25 @@ void mark_free_pages(struct zone *zone)
                return;
 
        spin_lock_irqsave(&zone->lock, flags);
-       for (zone_pfn = 0; zone_pfn < zone->spanned_pages; ++zone_pfn)
-               ClearPageNosaveFree(pfn_to_page(zone_pfn + zone->zone_start_pfn));
+
+       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)) {
+                       struct page *page = pfn_to_page(pfn);
+
+                       if (!PageNosave(page))
+                               ClearPageNosaveFree(page);
+               }
 
        for (order = MAX_ORDER - 1; order >= 0; --order)
                list_for_each(curr, &zone->free_area[order].free_list) {
-                       unsigned long start_pfn, i;
+                       unsigned long i;
 
-                       start_pfn = page_to_pfn(list_entry(curr, struct page, lru));
+                       pfn = page_to_pfn(list_entry(curr, struct page, lru));
+                       for (i = 0; i < (1UL << order); i++)
+                               SetPageNosaveFree(pfn_to_page(pfn + i));
+               }
 
-                       for (i=0; i < (1<<order); i++)
-                               SetPageNosaveFree(pfn_to_page(start_pfn+i));
-       }
        spin_unlock_irqrestore(&zone->lock, flags);
 }