|
@@ -40,6 +40,18 @@ static int swsusp_page_is_free(struct page *);
|
|
|
static void swsusp_set_page_forbidden(struct page *);
|
|
|
static void swsusp_unset_page_forbidden(struct page *);
|
|
|
|
|
|
+/*
|
|
|
+ * Number of bytes to reserve for memory allocations made by device drivers
|
|
|
+ * from their ->freeze() and ->freeze_noirq() callbacks so that they don't
|
|
|
+ * cause image creation to fail (tunable via /sys/power/reserved_size).
|
|
|
+ */
|
|
|
+unsigned long reserved_size;
|
|
|
+
|
|
|
+void __init hibernate_reserved_size_init(void)
|
|
|
+{
|
|
|
+ reserved_size = SPARE_PAGES * PAGE_SIZE;
|
|
|
+}
|
|
|
+
|
|
|
/*
|
|
|
* Preferred image size in bytes (tunable via /sys/power/image_size).
|
|
|
* When it is set to N, the image creating code will do its best to
|
|
@@ -1263,11 +1275,13 @@ static unsigned long minimum_image_size(unsigned long saveable)
|
|
|
* frame in use. We also need a number of page frames to be free during
|
|
|
* hibernation for allocations made while saving the image and for device
|
|
|
* drivers, in case they need to allocate memory from their hibernation
|
|
|
- * callbacks (these two numbers are given by PAGES_FOR_IO and SPARE_PAGES,
|
|
|
- * respectively, both of which are rough estimates). To make this happen, we
|
|
|
- * compute the total number of available page frames and allocate at least
|
|
|
+ * callbacks (these two numbers are given by PAGES_FOR_IO (which is a rough
|
|
|
+ * estimate) and reserverd_size divided by PAGE_SIZE (which is tunable through
|
|
|
+ * /sys/power/reserved_size, respectively). To make this happen, we compute the
|
|
|
+ * total number of available page frames and allocate at least
|
|
|
*
|
|
|
- * ([page frames total] + PAGES_FOR_IO + [metadata pages]) / 2 + 2 * SPARE_PAGES
|
|
|
+ * ([page frames total] + PAGES_FOR_IO + [metadata pages]) / 2
|
|
|
+ * + 2 * DIV_ROUND_UP(reserved_size, PAGE_SIZE)
|
|
|
*
|
|
|
* of them, which corresponds to the maximum size of a hibernation image.
|
|
|
*
|
|
@@ -1322,7 +1336,8 @@ int hibernate_preallocate_memory(void)
|
|
|
count -= totalreserve_pages;
|
|
|
|
|
|
/* Compute the maximum number of saveable pages to leave in memory. */
|
|
|
- max_size = (count - (size + PAGES_FOR_IO)) / 2 - 2 * SPARE_PAGES;
|
|
|
+ max_size = (count - (size + PAGES_FOR_IO)) / 2
|
|
|
+ - 2 * DIV_ROUND_UP(reserved_size, PAGE_SIZE);
|
|
|
/* Compute the desired number of image pages specified by image_size. */
|
|
|
size = DIV_ROUND_UP(image_size, PAGE_SIZE);
|
|
|
if (size > max_size)
|