Merge branch 'hibernate'

* hibernate:
PM: Fix suspend_console and resume_console to use only one semaphore
PM: Wait for console in resume
PM: Fix pm_notifiers during user mode hibernation
swsusp: clean up shrink_all_zones()
swsusp: dont fiddle with swappiness
PM: fix build for CONFIG_PM unset
PM/hibernate: fix "swap breaks after hibernation failures"
PM/resume: wait for device probing to finish
Consolidate driver_probe_done() loops into one place

+77 -36
+17
drivers/base/dd.c
··· 18 18 */ 19 19 20 20 #include <linux/device.h> 21 + #include <linux/delay.h> 21 22 #include <linux/module.h> 22 23 #include <linux/kthread.h> 23 24 #include <linux/wait.h> 25 + #include <linux/async.h> 24 26 25 27 #include "base.h" 26 28 #include "power/power.h" ··· 166 164 atomic_read(&probe_count)); 167 165 if (atomic_read(&probe_count)) 168 166 return -EBUSY; 167 + return 0; 168 + } 169 + 170 + /** 171 + * wait_for_device_probe 172 + * Wait for device probing to be completed. 173 + * 174 + * Note: this function polls at 100 msec intervals. 175 + */ 176 + int wait_for_device_probe(void) 177 + { 178 + /* wait for the known devices to complete their probing */ 179 + while (driver_probe_done() != 0) 180 + msleep(100); 181 + async_synchronize_full(); 169 182 return 0; 170 183 } 171 184
+2
include/linux/device.h
··· 147 147 extern struct device_driver *driver_find(const char *name, 148 148 struct bus_type *bus); 149 149 extern int driver_probe_done(void); 150 + extern int wait_for_device_probe(void); 151 + 150 152 151 153 /* sysfs interface for exporting driver attributes */ 152 154
+9 -4
init/do_mounts.c
··· 370 370 ssleep(root_delay); 371 371 } 372 372 373 - /* wait for the known devices to complete their probing */ 374 - while (driver_probe_done() != 0) 375 - msleep(100); 376 - async_synchronize_full(); 373 + /* 374 + * wait for the known devices to complete their probing 375 + * 376 + * Note: this is a potential source of long boot delays. 377 + * For example, it is not atypical to wait 5 seconds here 378 + * for the touchpad of a laptop to initialize. 379 + */ 380 + wait_for_device_probe(); 377 381 378 382 md_run_setup(); 379 383 ··· 403 399 while (driver_probe_done() != 0 || 404 400 (ROOT_DEV = name_to_dev_t(saved_root_name)) == 0) 405 401 msleep(100); 402 + async_synchronize_full(); 406 403 } 407 404 408 405 is_floppy = MAJOR(ROOT_DEV) == FLOPPY_MAJOR;
+3 -2
init/do_mounts_md.c
··· 281 281 */ 282 282 printk(KERN_INFO "md: Waiting for all devices to be available before autodetect\n"); 283 283 printk(KERN_INFO "md: If you don't use raid, use raid=noautodetect\n"); 284 - while (driver_probe_done() < 0) 285 - msleep(100); 284 + 285 + wait_for_device_probe(); 286 + 286 287 fd = sys_open("/dev/md0", 0, 0); 287 288 if (fd >= 0) { 288 289 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
+6
kernel/power/console.c
··· 78 78 } 79 79 set_console(orig_fgconsole); 80 80 release_console_sem(); 81 + 82 + if (vt_waitactive(orig_fgconsole)) { 83 + pr_debug("Resume: Can't switch VCs."); 84 + return; 85 + } 86 + 81 87 kmsg_redirect = orig_kmsg; 82 88 } 83 89 #endif
+11
kernel/power/disk.c
··· 595 595 unsigned int flags; 596 596 597 597 /* 598 + * If the user said "noresume".. bail out early. 599 + */ 600 + if (noresume) 601 + return 0; 602 + 603 + /* 598 604 * name_to_dev_t() below takes a sysfs buffer mutex when sysfs 599 605 * is configured into the kernel. Since the regular hibernate 600 606 * trigger path is via sysfs which takes a buffer mutex before ··· 616 610 mutex_unlock(&pm_mutex); 617 611 return -ENOENT; 618 612 } 613 + /* 614 + * Some device discovery might still be in progress; we need 615 + * to wait for this to finish. 616 + */ 617 + wait_for_device_probe(); 619 618 swsusp_resume_device = name_to_dev_t(resume_file); 620 619 pr_debug("PM: Resume from partition %s\n", resume_file); 621 620 } else {
+6 -6
kernel/power/user.c
··· 95 95 data->swap = swsusp_resume_device ? 96 96 swap_type_of(swsusp_resume_device, 0, NULL) : -1; 97 97 data->mode = O_RDONLY; 98 - error = pm_notifier_call_chain(PM_RESTORE_PREPARE); 99 - if (error) 100 - pm_notifier_call_chain(PM_POST_RESTORE); 101 - } else { 102 - data->swap = -1; 103 - data->mode = O_WRONLY; 104 98 error = pm_notifier_call_chain(PM_HIBERNATION_PREPARE); 105 99 if (error) 106 100 pm_notifier_call_chain(PM_POST_HIBERNATION); 101 + } else { 102 + data->swap = -1; 103 + data->mode = O_WRONLY; 104 + error = pm_notifier_call_chain(PM_RESTORE_PREPARE); 105 + if (error) 106 + pm_notifier_call_chain(PM_POST_RESTORE); 107 107 } 108 108 if (error) 109 109 atomic_inc(&snapshot_device_available);
+9 -6
kernel/printk.c
··· 73 73 * driver system. 74 74 */ 75 75 static DECLARE_MUTEX(console_sem); 76 - static DECLARE_MUTEX(secondary_console_sem); 77 76 struct console *console_drivers; 78 77 EXPORT_SYMBOL_GPL(console_drivers); 79 78 ··· 890 891 printk("Suspending console(s) (use no_console_suspend to debug)\n"); 891 892 acquire_console_sem(); 892 893 console_suspended = 1; 894 + up(&console_sem); 893 895 } 894 896 895 897 void resume_console(void) 896 898 { 897 899 if (!console_suspend_enabled) 898 900 return; 901 + down(&console_sem); 899 902 console_suspended = 0; 900 903 release_console_sem(); 901 904 } ··· 913 912 void acquire_console_sem(void) 914 913 { 915 914 BUG_ON(in_interrupt()); 916 - if (console_suspended) { 917 - down(&secondary_console_sem); 918 - return; 919 - } 920 915 down(&console_sem); 916 + if (console_suspended) 917 + return; 921 918 console_locked = 1; 922 919 console_may_schedule = 1; 923 920 } ··· 925 926 { 926 927 if (down_trylock(&console_sem)) 927 928 return -1; 929 + if (console_suspended) { 930 + up(&console_sem); 931 + return -1; 932 + } 928 933 console_locked = 1; 929 934 console_may_schedule = 0; 930 935 return 0; ··· 982 979 unsigned wake_klogd = 0; 983 980 984 981 if (console_suspended) { 985 - up(&secondary_console_sem); 982 + up(&console_sem); 986 983 return; 987 984 } 988 985
+2 -2
mm/swapfile.c
··· 635 635 636 636 if (!bdev) { 637 637 if (bdev_p) 638 - *bdev_p = sis->bdev; 638 + *bdev_p = bdget(sis->bdev->bd_dev); 639 639 640 640 spin_unlock(&swap_lock); 641 641 return i; ··· 647 647 struct swap_extent, list); 648 648 if (se->start_block == offset) { 649 649 if (bdev_p) 650 - *bdev_p = sis->bdev; 650 + *bdev_p = bdget(sis->bdev->bd_dev); 651 651 652 652 spin_unlock(&swap_lock); 653 653 bdput(bdev);
+12 -16
mm/vmscan.c
··· 2057 2057 int pass, struct scan_control *sc) 2058 2058 { 2059 2059 struct zone *zone; 2060 - unsigned long nr_to_scan, ret = 0; 2061 - enum lru_list l; 2060 + unsigned long ret = 0; 2062 2061 2063 2062 for_each_zone(zone) { 2063 + enum lru_list l; 2064 2064 2065 2065 if (!populated_zone(zone)) 2066 2066 continue; 2067 - 2068 2067 if (zone_is_all_unreclaimable(zone) && prio != DEF_PRIORITY) 2069 2068 continue; 2070 2069 2071 2070 for_each_evictable_lru(l) { 2071 + enum zone_stat_item ls = NR_LRU_BASE + l; 2072 + unsigned long lru_pages = zone_page_state(zone, ls); 2073 + 2072 2074 /* For pass = 0, we don't shrink the active list */ 2073 - if (pass == 0 && 2074 - (l == LRU_ACTIVE || l == LRU_ACTIVE_FILE)) 2075 + if (pass == 0 && (l == LRU_ACTIVE_ANON || 2076 + l == LRU_ACTIVE_FILE)) 2075 2077 continue; 2076 2078 2077 - zone->lru[l].nr_scan += 2078 - (zone_page_state(zone, NR_LRU_BASE + l) 2079 - >> prio) + 1; 2079 + zone->lru[l].nr_scan += (lru_pages >> prio) + 1; 2080 2080 if (zone->lru[l].nr_scan >= nr_pages || pass > 3) { 2081 + unsigned long nr_to_scan; 2082 + 2081 2083 zone->lru[l].nr_scan = 0; 2082 - nr_to_scan = min(nr_pages, 2083 - zone_page_state(zone, 2084 - NR_LRU_BASE + l)); 2084 + nr_to_scan = min(nr_pages, lru_pages); 2085 2085 ret += shrink_list(l, nr_to_scan, zone, 2086 2086 sc, prio); 2087 2087 if (ret >= nr_pages) ··· 2089 2089 } 2090 2090 } 2091 2091 } 2092 - 2093 2092 return ret; 2094 2093 } 2095 2094 ··· 2111 2112 .may_swap = 0, 2112 2113 .swap_cluster_max = nr_pages, 2113 2114 .may_writepage = 1, 2114 - .swappiness = vm_swappiness, 2115 2115 .isolate_pages = isolate_pages_global, 2116 2116 }; 2117 2117 ··· 2144 2146 int prio; 2145 2147 2146 2148 /* Force reclaiming mapped pages in the passes #3 and #4 */ 2147 - if (pass > 2) { 2149 + if (pass > 2) 2148 2150 sc.may_swap = 1; 2149 - sc.swappiness = 100; 2150 - } 2151 2151 2152 2152 for (prio = DEF_PRIORITY; prio >= 0; prio--) { 2153 2153 unsigned long nr_to_scan = nr_pages - ret;