Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

PM / Hibernate: Make default image size depend on total RAM size

The default hibernation image size is currently hard coded and euqal
to 500 MB, which is not a reasonable default on many contemporary
systems. Make it equal 2/5 of the total RAM size (this is slightly
below the maximum, i.e. 1/2 of the total RAM size, and seems to be
generally suitable).

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Tested-by: M. Vefa Bicakci <bicave@superonline.com>

+16 -3
+1 -1
Documentation/power/interface.txt
··· 57 57 suspend image will be as small as possible. 58 58 59 59 Reading from this file will display the current image size limit, which 60 - is set to 500 MB by default. 60 + is set to 2/5 of available RAM by default. 61 61 62 62 /sys/power/pm_trace controls the code which saves the last PM event point in 63 63 the RTC across reboots, so that you can debug a machine that just hangs
+1
kernel/power/main.c
··· 321 321 int error = pm_start_workqueue(); 322 322 if (error) 323 323 return error; 324 + hibernate_image_size_init(); 324 325 power_kobj = kobject_create_and_add("power", NULL); 325 326 if (!power_kobj) 326 327 return -ENOMEM;
+8 -1
kernel/power/power.h
··· 14 14 } __attribute__((aligned(PAGE_SIZE))); 15 15 16 16 #ifdef CONFIG_HIBERNATION 17 + /* kernel/power/snapshot.c */ 18 + extern void __init hibernate_image_size_init(void); 19 + 17 20 #ifdef CONFIG_ARCH_HIBERNATION_HEADER 18 21 /* Maximum size of architecture specific data in a hibernation header */ 19 22 #define MAX_ARCH_HEADER_SIZE (sizeof(struct new_utsname) + 4) ··· 52 49 extern int hibernation_snapshot(int platform_mode); 53 50 extern int hibernation_restore(int platform_mode); 54 51 extern int hibernation_platform_enter(void); 55 - #endif 52 + 53 + #else /* !CONFIG_HIBERNATION */ 54 + 55 + static inline void hibernate_image_size_init(void) {} 56 + #endif /* !CONFIG_HIBERNATION */ 56 57 57 58 extern int pfn_is_nosave(unsigned long); 58 59
+6 -1
kernel/power/snapshot.c
··· 46 46 * size will not exceed N bytes, but if that is impossible, it will 47 47 * try to create the smallest image possible. 48 48 */ 49 - unsigned long image_size = 500 * 1024 * 1024; 49 + unsigned long image_size; 50 + 51 + void __init hibernate_image_size_init(void) 52 + { 53 + image_size = ((totalram_pages * 2) / 5) * PAGE_SIZE; 54 + } 50 55 51 56 /* List of PBEs needed for restoring the pages that were allocated before 52 57 * the suspend and included in the suspend image, but have also been