[PATCH] swsusp: Improve handling of highmem
Currently swsusp saves the contents of highmem pages by copying them to the normal zone which is quite inefficient (eg. it requires two normal pages to be used for saving one highmem page). This may be improved by using highmem for saving the contents of saveable highmem pages. Namely, during the suspend phase of the suspend-resume cycle we try to allocate as many free highmem pages as there are saveable highmem pages. If there are not enough highmem image pages to store the contents of all of the saveable highmem pages, some of them will be stored in the "normal" memory. Next, we allocate as many free "normal" pages as needed to store the (remaining) image data. We use a memory bitmap to mark the allocated free pages (ie. highmem as well as "normal" image pages). Now, we use another memory bitmap to mark all of the saveable pages (highmem as well as "normal") and the contents of the saveable pages are copied into the image pages. Then, the second bitmap is used to save the pfns corresponding to the saveable pages and the first one is used to save their data. During the resume phase the pfns of the pages that were saveable during the suspend are loaded from the image and used to mark the "unsafe" page frames. Next, we try to allocate as many free highmem page frames as to load all of the image data that had been in the highmem before the suspend and we allocate so many free "normal" page frames that the total number of allocated free pages (highmem and "normal") is equal to the size of the image. While doing this we have to make sure that there will be some extra free "normal" and "safe" page frames for two lists of PBEs constructed later. Now, the image data are loaded, if possible, into their "original" page frames. The image data that cannot be written into their "original" page frames are loaded into "safe" page frames and their "original" kernel virtual addresses, as well as the addresses of the "safe" pages containing their copies, are stored in one of two lists of PBEs. One list of PBEs is for the copies of "normal" suspend pages (ie. "normal" pages that were saveable during the suspend) and it is used in the same way as previously (ie. by the architecture-dependent parts of swsusp). The other list of PBEs is for the copies of highmem suspend pages. The pages in this list are restored (in a reversible way) right before the arch-dependent code is called. 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>
This commit is contained in:
parent
bf73bae6ba
commit
8357376d3d
|
@ -9,10 +9,13 @@
|
|||
#include <linux/init.h>
|
||||
#include <linux/pm.h>
|
||||
|
||||
/* page backup entry */
|
||||
/* struct pbe is used for creating lists of pages that should be restored
|
||||
* atomically during the resume from disk, because the page frames they have
|
||||
* occupied before the suspend are in use.
|
||||
*/
|
||||
struct pbe {
|
||||
unsigned long address; /* address of the copy */
|
||||
unsigned long orig_address; /* original address of page */
|
||||
void *address; /* address of the copy */
|
||||
void *orig_address; /* original address of a page */
|
||||
struct pbe *next;
|
||||
};
|
||||
|
||||
|
|
|
@ -103,8 +103,8 @@ struct snapshot_handle {
|
|||
extern unsigned int snapshot_additional_pages(struct zone *zone);
|
||||
extern int snapshot_read_next(struct snapshot_handle *handle, size_t count);
|
||||
extern int snapshot_write_next(struct snapshot_handle *handle, size_t count);
|
||||
extern void snapshot_write_finalize(struct snapshot_handle *handle);
|
||||
extern int snapshot_image_loaded(struct snapshot_handle *handle);
|
||||
extern void snapshot_free_unused_memory(struct snapshot_handle *handle);
|
||||
|
||||
/*
|
||||
* This structure is used to pass the values needed for the identification
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -558,7 +558,7 @@ static int load_image(struct swap_map_handle *handle,
|
|||
error = err2;
|
||||
if (!error) {
|
||||
printk("\b\b\b\bdone\n");
|
||||
snapshot_free_unused_memory(snapshot);
|
||||
snapshot_write_finalize(snapshot);
|
||||
if (!snapshot_image_loaded(snapshot))
|
||||
error = -ENODATA;
|
||||
}
|
||||
|
|
|
@ -64,10 +64,8 @@ int in_suspend __nosavedata = 0;
|
|||
|
||||
#ifdef CONFIG_HIGHMEM
|
||||
unsigned int count_highmem_pages(void);
|
||||
int save_highmem(void);
|
||||
int restore_highmem(void);
|
||||
#else
|
||||
static inline int save_highmem(void) { return 0; }
|
||||
static inline int restore_highmem(void) { return 0; }
|
||||
static inline unsigned int count_highmem_pages(void) { return 0; }
|
||||
#endif
|
||||
|
@ -184,7 +182,7 @@ static inline unsigned long __shrink_memory(long tmp)
|
|||
|
||||
int swsusp_shrink_memory(void)
|
||||
{
|
||||
long size, tmp;
|
||||
long tmp;
|
||||
struct zone *zone;
|
||||
unsigned long pages = 0;
|
||||
unsigned int i = 0;
|
||||
|
@ -192,15 +190,27 @@ int swsusp_shrink_memory(void)
|
|||
|
||||
printk("Shrinking memory... ");
|
||||
do {
|
||||
size = 2 * count_highmem_pages();
|
||||
size += size / 50 + count_data_pages() + PAGES_FOR_IO;
|
||||
long size, highmem_size;
|
||||
|
||||
highmem_size = count_highmem_pages();
|
||||
size = count_data_pages() + PAGES_FOR_IO;
|
||||
tmp = size;
|
||||
size += highmem_size;
|
||||
for_each_zone (zone)
|
||||
if (!is_highmem(zone) && populated_zone(zone)) {
|
||||
tmp -= zone->free_pages;
|
||||
tmp += zone->lowmem_reserve[ZONE_NORMAL];
|
||||
tmp += snapshot_additional_pages(zone);
|
||||
if (populated_zone(zone)) {
|
||||
if (is_highmem(zone)) {
|
||||
highmem_size -= zone->free_pages;
|
||||
} else {
|
||||
tmp -= zone->free_pages;
|
||||
tmp += zone->lowmem_reserve[ZONE_NORMAL];
|
||||
tmp += snapshot_additional_pages(zone);
|
||||
}
|
||||
}
|
||||
|
||||
if (highmem_size < 0)
|
||||
highmem_size = 0;
|
||||
|
||||
tmp += highmem_size;
|
||||
if (tmp > 0) {
|
||||
tmp = __shrink_memory(tmp);
|
||||
if (!tmp)
|
||||
|
@ -223,6 +233,7 @@ int swsusp_suspend(void)
|
|||
|
||||
if ((error = arch_prepare_suspend()))
|
||||
return error;
|
||||
|
||||
local_irq_disable();
|
||||
/* At this point, device_suspend() has been called, but *not*
|
||||
* device_power_down(). We *must* device_power_down() now.
|
||||
|
@ -235,18 +246,11 @@ int swsusp_suspend(void)
|
|||
goto Enable_irqs;
|
||||
}
|
||||
|
||||
if ((error = save_highmem())) {
|
||||
printk(KERN_ERR "swsusp: Not enough free pages for highmem\n");
|
||||
goto Restore_highmem;
|
||||
}
|
||||
|
||||
save_processor_state();
|
||||
if ((error = swsusp_arch_suspend()))
|
||||
printk(KERN_ERR "Error %d suspending\n", error);
|
||||
/* Restore control flow magically appears here */
|
||||
restore_processor_state();
|
||||
Restore_highmem:
|
||||
restore_highmem();
|
||||
/* NOTE: device_power_up() is just a resume() for devices
|
||||
* that suspended with irqs off ... no overall powerup.
|
||||
*/
|
||||
|
@ -268,18 +272,23 @@ int swsusp_resume(void)
|
|||
printk(KERN_ERR "Some devices failed to power down, very bad\n");
|
||||
/* We'll ignore saved state, but this gets preempt count (etc) right */
|
||||
save_processor_state();
|
||||
error = swsusp_arch_resume();
|
||||
/* Code below is only ever reached in case of failure. Otherwise
|
||||
* execution continues at place where swsusp_arch_suspend was called
|
||||
*/
|
||||
BUG_ON(!error);
|
||||
error = restore_highmem();
|
||||
if (!error) {
|
||||
error = swsusp_arch_resume();
|
||||
/* The code below is only ever reached in case of a failure.
|
||||
* Otherwise execution continues at place where
|
||||
* swsusp_arch_suspend() was called
|
||||
*/
|
||||
BUG_ON(!error);
|
||||
/* This call to restore_highmem() undos the previous one */
|
||||
restore_highmem();
|
||||
}
|
||||
/* The only reason why swsusp_arch_resume() can fail is memory being
|
||||
* very tight, so we have to free it as soon as we can to avoid
|
||||
* subsequent failures
|
||||
*/
|
||||
swsusp_free();
|
||||
restore_processor_state();
|
||||
restore_highmem();
|
||||
touch_softlockup_watchdog();
|
||||
device_power_up();
|
||||
local_irq_enable();
|
||||
|
|
|
@ -194,12 +194,12 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
|
|||
break;
|
||||
|
||||
case SNAPSHOT_ATOMIC_RESTORE:
|
||||
snapshot_write_finalize(&data->handle);
|
||||
if (data->mode != O_WRONLY || !data->frozen ||
|
||||
!snapshot_image_loaded(&data->handle)) {
|
||||
error = -EPERM;
|
||||
break;
|
||||
}
|
||||
snapshot_free_unused_memory(&data->handle);
|
||||
down(&pm_sem);
|
||||
pm_prepare_console();
|
||||
suspend_console();
|
||||
|
|
|
@ -1260,6 +1260,9 @@ out:
|
|||
}
|
||||
if (!all_zones_ok) {
|
||||
cond_resched();
|
||||
|
||||
try_to_freeze();
|
||||
|
||||
goto loop_again;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue