[Suspend2][ 11/20] [Suspend2] Amount of memory still to be freed.

Nigel Cunningham
2006-06-26T23:29:58Z

Calculate the amount of memory that needs to be freed to meet hard
constraints such as available storage and possibly also the soft
user-defined image size limit.

Signed-off-by: Nigel Cunningham <nigel@suspend2.net>

kernel/power/prepare_image.c | 19 +++++++++++++++++++
1 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/kernel/power/prepare_image.c b/kernel/power/prepare_image.c
index 14ab1a4..c85ce6b 100644
--- a/kernel/power/prepare_image.c
+++ b/kernel/power/prepare_image.c
@@ -343,3 +343,22 @@ static struct pageset_sizes_result count
return result;
}

+/* amount_needed
+ *
+ * Calculates the amount by which the image size needs to be reduced to meet
+ * our constraints.
+ */
+static int amount_needed(int use_image_size_limit)
+{
+
+ int max1 = max( (int) (ram_to_suspend() - real_nr_free_pages() -
+ nr_free_highpages()),
+ ((int) (storage_needed(1, 0) -
+ storage_available)));
+ if (use_image_size_limit)
+ return max( max1,
+ (image_size_limit > 0) ?
+ ((int) (storage_needed(1, 0) - (image_size_limit << 8))) : 0);
+ return max1;