Commit ae83c5ee authored by Rafael J. Wysocki's avatar Rafael J. Wysocki Committed by Linus Torvalds

[PATCH] swsusp: clean up browsing of pfns

Clean up some loops over pfns for each zone in snapshot.c: reduce the
number of additions to perform, rework detection of saveable pages and make
the code a bit less difficult to understand, hopefully.
Signed-off-by: default avatarRafael J. Wysocki <rjw@sisk.pl>
Acked-by: default avatarPavel Machek <pavel@ucw.cz>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 546e0d27
...@@ -156,7 +156,7 @@ static inline int save_highmem(void) {return 0;} ...@@ -156,7 +156,7 @@ static inline int save_highmem(void) {return 0;}
static inline int restore_highmem(void) {return 0;} static inline int restore_highmem(void) {return 0;}
#endif #endif
static int pfn_is_nosave(unsigned long pfn) static inline int pfn_is_nosave(unsigned long pfn)
{ {
unsigned long nosave_begin_pfn = __pa(&__nosave_begin) >> PAGE_SHIFT; unsigned long nosave_begin_pfn = __pa(&__nosave_begin) >> PAGE_SHIFT;
unsigned long nosave_end_pfn = PAGE_ALIGN(__pa(&__nosave_end)) >> PAGE_SHIFT; unsigned long nosave_end_pfn = PAGE_ALIGN(__pa(&__nosave_end)) >> PAGE_SHIFT;
...@@ -167,43 +167,43 @@ static int pfn_is_nosave(unsigned long pfn) ...@@ -167,43 +167,43 @@ static int pfn_is_nosave(unsigned long pfn)
* saveable - Determine whether a page should be cloned or not. * saveable - Determine whether a page should be cloned or not.
* @pfn: The page * @pfn: The page
* *
* We save a page if it's Reserved, and not in the range of pages * We save a page if it isn't Nosave, and is not in the range of pages
* statically defined as 'unsaveable', or if it isn't reserved, and * statically defined as 'unsaveable', and it
* isn't part of a free chunk of pages. * isn't a part of a free chunk of pages.
*/ */
static int saveable(struct zone *zone, unsigned long *zone_pfn) static struct page *saveable_page(unsigned long pfn)
{ {
unsigned long pfn = *zone_pfn + zone->zone_start_pfn;
struct page *page; struct page *page;
if (!pfn_valid(pfn)) if (!pfn_valid(pfn))
return 0; return NULL;
page = pfn_to_page(pfn); page = pfn_to_page(pfn);
BUG_ON(PageReserved(page) && PageNosave(page));
if (PageNosave(page)) if (PageNosave(page))
return 0; return NULL;
if (PageReserved(page) && pfn_is_nosave(pfn)) if (PageReserved(page) && pfn_is_nosave(pfn))
return 0; return NULL;
if (PageNosaveFree(page)) if (PageNosaveFree(page))
return 0; return NULL;
return 1; return page;
} }
unsigned int count_data_pages(void) unsigned int count_data_pages(void)
{ {
struct zone *zone; struct zone *zone;
unsigned long zone_pfn; unsigned long pfn, max_zone_pfn;
unsigned int n = 0; unsigned int n = 0;
for_each_zone (zone) { for_each_zone (zone) {
if (is_highmem(zone)) if (is_highmem(zone))
continue; continue;
mark_free_pages(zone); mark_free_pages(zone);
for (zone_pfn = 0; zone_pfn < zone->spanned_pages; ++zone_pfn) max_zone_pfn = zone->zone_start_pfn + zone->spanned_pages;
n += saveable(zone, &zone_pfn); for (pfn = zone->zone_start_pfn; pfn < max_zone_pfn; pfn++)
n += !!saveable_page(pfn);
} }
return n; return n;
} }
...@@ -211,7 +211,7 @@ unsigned int count_data_pages(void) ...@@ -211,7 +211,7 @@ unsigned int count_data_pages(void)
static void copy_data_pages(struct pbe *pblist) static void copy_data_pages(struct pbe *pblist)
{ {
struct zone *zone; struct zone *zone;
unsigned long zone_pfn; unsigned long pfn, max_zone_pfn;
struct pbe *pbe, *p; struct pbe *pbe, *p;
pbe = pblist; pbe = pblist;
...@@ -224,13 +224,14 @@ static void copy_data_pages(struct pbe *pblist) ...@@ -224,13 +224,14 @@ static void copy_data_pages(struct pbe *pblist)
SetPageNosaveFree(virt_to_page(p)); SetPageNosaveFree(virt_to_page(p));
for_each_pbe (p, pblist) for_each_pbe (p, pblist)
SetPageNosaveFree(virt_to_page(p->address)); SetPageNosaveFree(virt_to_page(p->address));
for (zone_pfn = 0; zone_pfn < zone->spanned_pages; ++zone_pfn) { max_zone_pfn = zone->zone_start_pfn + zone->spanned_pages;
if (saveable(zone, &zone_pfn)) { for (pfn = zone->zone_start_pfn; pfn < max_zone_pfn; pfn++) {
struct page *page; struct page *page = saveable_page(pfn);
if (page) {
long *src, *dst; long *src, *dst;
int n; int n;
page = pfn_to_page(zone_pfn + zone->zone_start_pfn);
BUG_ON(!pbe); BUG_ON(!pbe);
pbe->orig_address = (unsigned long)page_address(page); pbe->orig_address = (unsigned long)page_address(page);
/* copy_page and memcpy are not usable for copying task structs. */ /* copy_page and memcpy are not usable for copying task structs. */
...@@ -383,13 +384,14 @@ static struct pbe *alloc_pagedir(unsigned int nr_pages, gfp_t gfp_mask, ...@@ -383,13 +384,14 @@ static struct pbe *alloc_pagedir(unsigned int nr_pages, gfp_t gfp_mask,
void swsusp_free(void) void swsusp_free(void)
{ {
struct zone *zone; struct zone *zone;
unsigned long zone_pfn; unsigned long pfn, max_zone_pfn;
for_each_zone(zone) { for_each_zone(zone) {
for (zone_pfn = 0; zone_pfn < zone->spanned_pages; ++zone_pfn) max_zone_pfn = zone->zone_start_pfn + zone->spanned_pages;
if (pfn_valid(zone_pfn + zone->zone_start_pfn)) { for (pfn = zone->zone_start_pfn; pfn < max_zone_pfn; pfn++)
struct page *page; if (pfn_valid(pfn)) {
page = pfn_to_page(zone_pfn + zone->zone_start_pfn); struct page *page = pfn_to_page(pfn);
if (PageNosave(page) && PageNosaveFree(page)) { if (PageNosave(page) && PageNosaveFree(page)) {
ClearPageNosave(page); ClearPageNosave(page);
ClearPageNosaveFree(page); ClearPageNosaveFree(page);
...@@ -598,7 +600,7 @@ int snapshot_read_next(struct snapshot_handle *handle, size_t count) ...@@ -598,7 +600,7 @@ int snapshot_read_next(struct snapshot_handle *handle, size_t count)
static int mark_unsafe_pages(struct pbe *pblist) static int mark_unsafe_pages(struct pbe *pblist)
{ {
struct zone *zone; struct zone *zone;
unsigned long zone_pfn; unsigned long pfn, max_zone_pfn;
struct pbe *p; struct pbe *p;
if (!pblist) /* a sanity check */ if (!pblist) /* a sanity check */
...@@ -606,10 +608,10 @@ static int mark_unsafe_pages(struct pbe *pblist) ...@@ -606,10 +608,10 @@ static int mark_unsafe_pages(struct pbe *pblist)
/* Clear page flags */ /* Clear page flags */
for_each_zone (zone) { for_each_zone (zone) {
for (zone_pfn = 0; zone_pfn < zone->spanned_pages; ++zone_pfn) max_zone_pfn = zone->zone_start_pfn + zone->spanned_pages;
if (pfn_valid(zone_pfn + zone->zone_start_pfn)) for (pfn = zone->zone_start_pfn; pfn < max_zone_pfn; pfn++)
ClearPageNosaveFree(pfn_to_page(zone_pfn + if (pfn_valid(pfn))
zone->zone_start_pfn)); ClearPageNosaveFree(pfn_to_page(pfn));
} }
/* Mark orig addresses */ /* Mark orig addresses */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment