diff options
Diffstat (limited to 'kernel/power/swap.c')
| -rw-r--r-- | kernel/power/swap.c | 55 |
1 files changed, 39 insertions, 16 deletions
diff --git a/kernel/power/swap.c b/kernel/power/swap.c index a0e4a86ccf94..8c7e4832b9be 100644 --- a/kernel/power/swap.c +++ b/kernel/power/swap.c | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | * | 6 | * |
| 7 | * Copyright (C) 1998,2001-2005 Pavel Machek <pavel@ucw.cz> | 7 | * Copyright (C) 1998,2001-2005 Pavel Machek <pavel@ucw.cz> |
| 8 | * Copyright (C) 2006 Rafael J. Wysocki <rjw@sisk.pl> | 8 | * Copyright (C) 2006 Rafael J. Wysocki <rjw@sisk.pl> |
| 9 | * Copyright (C) 2010 Bojan Smojver <bojan@rexursive.com> | ||
| 9 | * | 10 | * |
| 10 | * This file is released under the GPLv2. | 11 | * This file is released under the GPLv2. |
| 11 | * | 12 | * |
| @@ -29,7 +30,7 @@ | |||
| 29 | 30 | ||
| 30 | #include "power.h" | 31 | #include "power.h" |
| 31 | 32 | ||
| 32 | #define HIBERNATE_SIG "LINHIB0001" | 33 | #define HIBERNATE_SIG "S1SUSPEND" |
| 33 | 34 | ||
| 34 | /* | 35 | /* |
| 35 | * The swap map is a data structure used for keeping track of each page | 36 | * The swap map is a data structure used for keeping track of each page |
| @@ -753,30 +754,43 @@ static int load_image_lzo(struct swap_map_handle *handle, | |||
| 753 | { | 754 | { |
| 754 | unsigned int m; | 755 | unsigned int m; |
| 755 | int error = 0; | 756 | int error = 0; |
| 757 | struct bio *bio; | ||
| 756 | struct timeval start; | 758 | struct timeval start; |
| 757 | struct timeval stop; | 759 | struct timeval stop; |
| 758 | unsigned nr_pages; | 760 | unsigned nr_pages; |
| 759 | size_t off, unc_len, cmp_len; | 761 | size_t i, off, unc_len, cmp_len; |
| 760 | unsigned char *unc, *cmp, *page; | 762 | unsigned char *unc, *cmp, *page[LZO_CMP_PAGES]; |
| 761 | 763 | ||
| 762 | page = (void *)__get_free_page(__GFP_WAIT | __GFP_HIGH); | 764 | for (i = 0; i < LZO_CMP_PAGES; i++) { |
| 763 | if (!page) { | 765 | page[i] = (void *)__get_free_page(__GFP_WAIT | __GFP_HIGH); |
| 764 | printk(KERN_ERR "PM: Failed to allocate LZO page\n"); | 766 | if (!page[i]) { |
| 765 | return -ENOMEM; | 767 | printk(KERN_ERR "PM: Failed to allocate LZO page\n"); |
| 768 | |||
| 769 | while (i) | ||
| 770 | free_page((unsigned long)page[--i]); | ||
| 771 | |||
| 772 | return -ENOMEM; | ||
| 773 | } | ||
| 766 | } | 774 | } |
| 767 | 775 | ||
| 768 | unc = vmalloc(LZO_UNC_SIZE); | 776 | unc = vmalloc(LZO_UNC_SIZE); |
| 769 | if (!unc) { | 777 | if (!unc) { |
| 770 | printk(KERN_ERR "PM: Failed to allocate LZO uncompressed\n"); | 778 | printk(KERN_ERR "PM: Failed to allocate LZO uncompressed\n"); |
| 771 | free_page((unsigned long)page); | 779 | |
| 780 | for (i = 0; i < LZO_CMP_PAGES; i++) | ||
| 781 | free_page((unsigned long)page[i]); | ||
| 782 | |||
| 772 | return -ENOMEM; | 783 | return -ENOMEM; |
| 773 | } | 784 | } |
| 774 | 785 | ||
| 775 | cmp = vmalloc(LZO_CMP_SIZE); | 786 | cmp = vmalloc(LZO_CMP_SIZE); |
| 776 | if (!cmp) { | 787 | if (!cmp) { |
| 777 | printk(KERN_ERR "PM: Failed to allocate LZO compressed\n"); | 788 | printk(KERN_ERR "PM: Failed to allocate LZO compressed\n"); |
| 789 | |||
| 778 | vfree(unc); | 790 | vfree(unc); |
| 779 | free_page((unsigned long)page); | 791 | for (i = 0; i < LZO_CMP_PAGES; i++) |
| 792 | free_page((unsigned long)page[i]); | ||
| 793 | |||
| 780 | return -ENOMEM; | 794 | return -ENOMEM; |
| 781 | } | 795 | } |
| 782 | 796 | ||
| @@ -787,6 +801,7 @@ static int load_image_lzo(struct swap_map_handle *handle, | |||
| 787 | if (!m) | 801 | if (!m) |
| 788 | m = 1; | 802 | m = 1; |
| 789 | nr_pages = 0; | 803 | nr_pages = 0; |
| 804 | bio = NULL; | ||
| 790 | do_gettimeofday(&start); | 805 | do_gettimeofday(&start); |
| 791 | 806 | ||
| 792 | error = snapshot_write_next(snapshot); | 807 | error = snapshot_write_next(snapshot); |
| @@ -794,11 +809,11 @@ static int load_image_lzo(struct swap_map_handle *handle, | |||
| 794 | goto out_finish; | 809 | goto out_finish; |
| 795 | 810 | ||
| 796 | for (;;) { | 811 | for (;;) { |
| 797 | error = swap_read_page(handle, page, NULL); /* sync */ | 812 | error = swap_read_page(handle, page[0], NULL); /* sync */ |
| 798 | if (error) | 813 | if (error) |
| 799 | break; | 814 | break; |
| 800 | 815 | ||
| 801 | cmp_len = *(size_t *)page; | 816 | cmp_len = *(size_t *)page[0]; |
| 802 | if (unlikely(!cmp_len || | 817 | if (unlikely(!cmp_len || |
| 803 | cmp_len > lzo1x_worst_compress(LZO_UNC_SIZE))) { | 818 | cmp_len > lzo1x_worst_compress(LZO_UNC_SIZE))) { |
| 804 | printk(KERN_ERR "PM: Invalid LZO compressed length\n"); | 819 | printk(KERN_ERR "PM: Invalid LZO compressed length\n"); |
| @@ -806,13 +821,20 @@ static int load_image_lzo(struct swap_map_handle *handle, | |||
| 806 | break; | 821 | break; |
| 807 | } | 822 | } |
| 808 | 823 | ||
| 809 | memcpy(cmp, page, PAGE_SIZE); | 824 | for (off = PAGE_SIZE, i = 1; |
| 810 | for (off = PAGE_SIZE; off < LZO_HEADER + cmp_len; off += PAGE_SIZE) { | 825 | off < LZO_HEADER + cmp_len; off += PAGE_SIZE, i++) { |
| 811 | error = swap_read_page(handle, page, NULL); /* sync */ | 826 | error = swap_read_page(handle, page[i], &bio); |
| 812 | if (error) | 827 | if (error) |
| 813 | goto out_finish; | 828 | goto out_finish; |
| 829 | } | ||
| 814 | 830 | ||
| 815 | memcpy(cmp + off, page, PAGE_SIZE); | 831 | error = hib_wait_on_bio_chain(&bio); /* need all data now */ |
| 832 | if (error) | ||
| 833 | goto out_finish; | ||
| 834 | |||
| 835 | for (off = 0, i = 0; | ||
| 836 | off < LZO_HEADER + cmp_len; off += PAGE_SIZE, i++) { | ||
| 837 | memcpy(cmp + off, page[i], PAGE_SIZE); | ||
| 816 | } | 838 | } |
| 817 | 839 | ||
| 818 | unc_len = LZO_UNC_SIZE; | 840 | unc_len = LZO_UNC_SIZE; |
| @@ -857,7 +879,8 @@ out_finish: | |||
| 857 | 879 | ||
| 858 | vfree(cmp); | 880 | vfree(cmp); |
| 859 | vfree(unc); | 881 | vfree(unc); |
| 860 | free_page((unsigned long)page); | 882 | for (i = 0; i < LZO_CMP_PAGES; i++) |
| 883 | free_page((unsigned long)page[i]); | ||
| 861 | 884 | ||
| 862 | return error; | 885 | return error; |
| 863 | } | 886 | } |
