From: Nigel Cunningham <nigel@suspend2.net>
To: linux-kernel@vger.kernel.org
Subject: [Suspend2][ 19/20] [Suspend2] Prepare an image.
Date: Tue, 27 Jun 2006 08:35:51 +1000 [thread overview]
Message-ID: <20060626223550.4050.47136.stgit@nigel.suspend2.net> (raw)
In-Reply-To: <20060626223446.4050.9897.stgit@nigel.suspend2.net>
Attempt to prepare everything for suspending. This section of the code does
most of the work - freezing processes, allocating storage, freeing memory
and so on. Once it is complete, we are either going to abort or jump
straight into writing the image.
Signed-off-by: Nigel Cunningham <nigel@suspend2.net>
kernel/power/prepare_image.c | 63 ++++++++++++++++++++++++++++++++++++++++++
1 files changed, 63 insertions(+), 0 deletions(-)
diff --git a/kernel/power/prepare_image.c b/kernel/power/prepare_image.c
index 893ba72..10159e5 100644
--- a/kernel/power/prepare_image.c
+++ b/kernel/power/prepare_image.c
@@ -622,3 +622,66 @@ static int eat_memory(void)
return 0;
}
+/* prepare_image
+ *
+ * Entry point to the whole image preparation section.
+ *
+ * We do four things:
+ * - Freeze processes;
+ * - Ensure image size constraints are met;
+ * - Complete all the preparation for saving the image,
+ * including allocation of storage. The only memory
+ * that should be needed when we're finished is that
+ * for actually storing the image (and we know how
+ * much is needed for that because the modules tell
+ * us).
+ * - Make sure that all dirty buffers are written out.
+ */
+#define MAX_TRIES 4
+int suspend_prepare_image(void)
+{
+ int result = 1, tries = 0;
+
+ are_frozen = 0;
+
+ header_space_allocated = 0;
+
+ if (attempt_to_freeze())
+ return 1;
+
+ if (!extra_pd1_pages_allowance)
+ get_extra_pd1_allowance();
+
+ storage_available = suspend_active_writer->storage_available();
+
+ if (!storage_available) {
+ printk(KERN_ERR "You need some storage available to be able to suspend.\n");
+ set_result_state(SUSPEND_ABORTED);
+ set_result_state(SUSPEND_NOSTORAGE_AVAILABLE);
+ return 1;
+ }
+
+ do {
+ suspend_prepare_status(CLEAR_BAR, "Preparing Image.");
+
+ if (eat_memory() || test_result_state(SUSPEND_ABORTED))
+ break;
+
+ result = update_image();
+
+ suspend_cond_pause(0, NULL);
+
+ tries++;
+
+ } while ((result) && (tries < MAX_TRIES) && (!test_result_state(SUSPEND_ABORTED)) &&
+ (!test_result_state(SUSPEND_UNABLE_TO_FREE_ENOUGH_MEMORY)));
+
+ if (tries == MAX_TRIES) {
+ abort_suspend("Unable to successfully prepare the image.\n");
+ display_stats(1, 0);
+ }
+
+ suspend_cond_pause(1, "Image preparation complete.");
+
+ return result;
+}
--
Nigel Cunningham nigel at suspend2 dot net
next prev parent reply other threads:[~2006-06-26 23:27 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-06-26 22:34 [Suspend2][ 00/20] Prepare image Nigel Cunningham
2006-06-26 22:34 ` [Suspend2][ 01/20] [Suspend2] Prepare_image.c header Nigel Cunningham
2006-06-26 22:34 ` [Suspend2][ 02/20] [Suspend2] Get number of pcp pages Nigel Cunningham
2006-06-26 22:34 ` [Suspend2][ 03/20] [Suspend2] Get the real number of free pages (incl. pcp) Nigel Cunningham
2006-06-26 22:35 ` [Suspend2][ 04/20] [Suspend2] Calculate pagedir1 growth allowance Nigel Cunningham
2006-06-26 22:35 ` [Suspend2][ 05/20] [Suspend2] Get the amount of storage needed for the image proper Nigel Cunningham
2006-06-26 22:35 ` [Suspend2][ 06/20] [Suspend2] Calculate header storage needed Nigel Cunningham
2006-06-26 22:35 ` [Suspend2][ 07/20] [Suspend2] Display image vital statistics Nigel Cunningham
2006-06-26 22:35 ` [Suspend2][ 08/20] [Suspend2] Generate free page bitmap Nigel Cunningham
2006-06-26 22:35 ` [Suspend2][ 09/20] [Suspend2] Get size of a free region Nigel Cunningham
2006-06-26 22:35 ` [Suspend2][ 10/20] [Suspend2] Count pages in image parts Nigel Cunningham
2006-06-26 22:35 ` [Suspend2][ 11/20] [Suspend2] Amount of memory still to be freed Nigel Cunningham
2006-06-26 22:35 ` [Suspend2][ 12/20] [Suspend2] Recalculate image contents Nigel Cunningham
2006-06-26 22:35 ` [Suspend2][ 13/20] [Suspend2] Try to refreeze processes Nigel Cunningham
2006-06-26 22:35 ` [Suspend2][ 14/20] [Suspend2] Update the image Nigel Cunningham
2006-06-26 22:35 ` [Suspend2][ 15/20] [Suspend2] Attempt to freeze processes Nigel Cunningham
2006-06-27 13:45 ` Pavel Machek
2006-06-27 23:38 ` Nigel Cunningham
2006-06-28 18:59 ` Hugh Dickins
2006-06-28 22:10 ` Nigel Cunningham
2006-06-26 22:35 ` [Suspend2][ 16/20] [Suspend2] Calculate storage needed for an image Nigel Cunningham
2006-06-26 22:35 ` [Suspend2][ 17/20] [Suspend2] Calculate the amount of free memory needed Nigel Cunningham
2006-06-26 22:35 ` [Suspend2][ 18/20] [Suspend2] Free up memory if necessary Nigel Cunningham
2006-06-26 22:35 ` Nigel Cunningham [this message]
2006-06-26 22:35 ` [Suspend2][ 20/20] [Suspend2] Prepare image header file Nigel Cunningham
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20060626223550.4050.47136.stgit@nigel.suspend2.net \
--to=nigel@suspend2.net \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox