Skip to content

Commit d3aa3d2

Browse files
rjwysockiKali-
authored andcommitted
PM / Hibernate: Make default image size depend on total RAM size
[ upstream commit ac5c24ec1e983313ef0015258fba6f630e54e7cf ] 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 <[email protected]> Tested-by: M. Vefa Bicakci <[email protected]> Signed-off-by: Andi Kleen <[email protected]>
1 parent 152cde8 commit d3aa3d2

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

Documentation/power/interface.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ smallest image possible. In particular, if "0" is written to this file, the
5757
suspend image will be as small as possible.
5858

5959
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.
6161

6262
/sys/power/pm_trace controls the code which saves the last PM event point in
6363
the RTC across reboots, so that you can debug a machine that just hangs

kernel/power/main.c

+1
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ static int __init pm_init(void)
354354
int error = pm_start_workqueue();
355355
if (error)
356356
return error;
357+
hibernate_image_size_init();
357358
power_kobj = kobject_create_and_add("power", NULL);
358359
if (!power_kobj)
359360
return -ENOMEM;

kernel/power/power.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ struct swsusp_info {
1414
} __attribute__((aligned(PAGE_SIZE)));
1515

1616
#ifdef CONFIG_HIBERNATION
17+
/* kernel/power/snapshot.c */
18+
extern void __init hibernate_image_size_init(void);
19+
1720
#ifdef CONFIG_ARCH_HIBERNATION_HEADER
1821
/* Maximum size of architecture specific data in a hibernation header */
1922
#define MAX_ARCH_HEADER_SIZE (sizeof(struct new_utsname) + 4)
@@ -49,7 +52,11 @@ static inline char *check_image_kernel(struct swsusp_info *info)
4952
extern int hibernation_snapshot(int platform_mode);
5053
extern int hibernation_restore(int platform_mode);
5154
extern int hibernation_platform_enter(void);
52-
#endif
55+
56+
#else /* !CONFIG_HIBERNATION */
57+
58+
static inline void hibernate_image_size_init(void) {}
59+
#endif /* !CONFIG_HIBERNATION */
5360

5461
extern int pfn_is_nosave(unsigned long);
5562

kernel/power/snapshot.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@ static void swsusp_unset_page_forbidden(struct page *);
4646
* size will not exceed N bytes, but if that is impossible, it will
4747
* try to create the smallest image possible.
4848
*/
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+
}
5055

5156
/* List of PBEs needed for restoring the pages that were allocated before
5257
* the suspend and included in the suspend image, but have also been

0 commit comments

Comments
 (0)