Commit f8262d47 authored by Bojan Smojver's avatar Bojan Smojver Committed by Rafael J. Wysocki

PM / Hibernate: fix the number of pages used for hibernate/thaw buffering

Hibernation regression fix, since 3.2.

Calculate the number of required free pages based on non-high memory
pages only, because that is where the buffers will come from.

Commit 081a9d04 introduced a new buffer
page allocation logic during hibernation, in order to improve the
performance. The amount of pages allocated was calculated based on total
amount of pages available, although only non-high memory pages are
usable for this purpose. This caused hibernation code to attempt to over
allocate pages on platforms that have high memory, which led to hangs.
Signed-off-by: default avatarBojan Smojver <bojan@rexursive.com>
Signed-off-by: default avatarRafael J. Wysocki <rjw@suse.de>
parent 66f75a5d
...@@ -51,6 +51,23 @@ ...@@ -51,6 +51,23 @@
#define MAP_PAGE_ENTRIES (PAGE_SIZE / sizeof(sector_t) - 1) #define MAP_PAGE_ENTRIES (PAGE_SIZE / sizeof(sector_t) - 1)
/*
* Number of free pages that are not high.
*/
static inline unsigned long low_free_pages(void)
{
return nr_free_pages() - nr_free_highpages();
}
/*
* Number of pages required to be kept free while writing the image. Always
* half of all available low pages before the writing starts.
*/
static inline unsigned long reqd_free_pages(void)
{
return low_free_pages() / 2;
}
struct swap_map_page { struct swap_map_page {
sector_t entries[MAP_PAGE_ENTRIES]; sector_t entries[MAP_PAGE_ENTRIES];
sector_t next_swap; sector_t next_swap;
...@@ -72,7 +89,7 @@ struct swap_map_handle { ...@@ -72,7 +89,7 @@ struct swap_map_handle {
sector_t cur_swap; sector_t cur_swap;
sector_t first_sector; sector_t first_sector;
unsigned int k; unsigned int k;
unsigned long nr_free_pages, written; unsigned long reqd_free_pages;
u32 crc32; u32 crc32;
}; };
...@@ -316,8 +333,7 @@ static int get_swap_writer(struct swap_map_handle *handle) ...@@ -316,8 +333,7 @@ static int get_swap_writer(struct swap_map_handle *handle)
goto err_rel; goto err_rel;
} }
handle->k = 0; handle->k = 0;
handle->nr_free_pages = nr_free_pages() >> 1; handle->reqd_free_pages = reqd_free_pages();
handle->written = 0;
handle->first_sector = handle->cur_swap; handle->first_sector = handle->cur_swap;
return 0; return 0;
err_rel: err_rel:
...@@ -352,11 +368,11 @@ static int swap_write_page(struct swap_map_handle *handle, void *buf, ...@@ -352,11 +368,11 @@ static int swap_write_page(struct swap_map_handle *handle, void *buf,
handle->cur_swap = offset; handle->cur_swap = offset;
handle->k = 0; handle->k = 0;
} }
if (bio_chain && ++handle->written > handle->nr_free_pages) { if (bio_chain && low_free_pages() <= handle->reqd_free_pages) {
error = hib_wait_on_bio_chain(bio_chain); error = hib_wait_on_bio_chain(bio_chain);
if (error) if (error)
goto out; goto out;
handle->written = 0; handle->reqd_free_pages = reqd_free_pages();
} }
out: out:
return error; return error;
...@@ -618,7 +634,7 @@ static int save_image_lzo(struct swap_map_handle *handle, ...@@ -618,7 +634,7 @@ static int save_image_lzo(struct swap_map_handle *handle,
* Adjust number of free pages after all allocations have been done. * Adjust number of free pages after all allocations have been done.
* We don't want to run out of pages when writing. * We don't want to run out of pages when writing.
*/ */
handle->nr_free_pages = nr_free_pages() >> 1; handle->reqd_free_pages = reqd_free_pages();
/* /*
* Start the CRC32 thread. * Start the CRC32 thread.
......
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