[PATCH] swsusp: make image size limit tunable
authorRafael J. Wysocki <rjw@sisk.pl>
Fri, 6 Jan 2006 08:15:56 +0000 (00:15 -0800)
committerLinus Torvalds <torvalds@g5.osdl.org>
Fri, 6 Jan 2006 16:33:42 +0000 (08:33 -0800)
Make the suspend image size limit tunable via /sys/power/image_size.

It is necessary for systems on which there is a limited amount of swap
available for suspend.  It can also be useful for optimizing performance of
swsusp on systems with 1 GB of RAM or more.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Documentation/power/interface.txt
Documentation/power/swsusp.txt
kernel/power/disk.c
kernel/power/power.h
kernel/power/swsusp.c

index f5ebda5..bd4ffb5 100644 (file)
@@ -41,3 +41,14 @@ to. Writing to this file will accept one of
 It will only change to 'firmware' or 'platform' if the system supports
 it. 
 
+/sys/power/image_size controls the size of the image created by
+the suspend-to-disk mechanism.  It can be written a string
+representing a non-negative integer that will be used as an upper
+limit of the image size, in megabytes.  The suspend-to-disk mechanism will
+do its best to ensure the image size will not exceed that number.  However,
+if this turns out to be impossible, it will try to suspend anyway using the
+smallest image possible.  In particular, if "0" is written to this file, the
+suspend image will be as small as possible.
+
+Reading from this file will display the current image size limit, which
+is set to 500 MB by default.
index b0d5084..cd0fcd8 100644 (file)
@@ -27,6 +27,11 @@ echo shutdown > /sys/power/disk; echo disk > /sys/power/state
 
 echo platform > /sys/power/disk; echo disk > /sys/power/state
 
+If you want to limit the suspend image size to N megabytes, do
+
+echo N > /sys/power/image_size
+
+before suspend (it is limited to 500 MB by default).
 
 Encrypted suspend image:
 ------------------------
index 9e51cdf..e24446f 100644 (file)
@@ -365,9 +365,29 @@ out:
 
 power_attr(resume);
 
+static ssize_t image_size_show(struct subsystem * subsys, char *buf)
+{
+       return sprintf(buf, "%u\n", image_size);
+}
+
+static ssize_t image_size_store(struct subsystem * subsys, const char * buf, size_t n)
+{
+       unsigned int size;
+
+       if (sscanf(buf, "%u", &size) == 1) {
+               image_size = size;
+               return n;
+       }
+
+       return -EINVAL;
+}
+
+power_attr(image_size);
+
 static struct attribute * g[] = {
        &disk_attr.attr,
        &resume_attr.attr,
+       &image_size_attr.attr,
        NULL,
 };
 
index 9b04599..273a5b1 100644 (file)
@@ -52,11 +52,8 @@ extern const void __nosave_begin, __nosave_end;
 extern unsigned int nr_copy_pages;
 extern struct pbe *pagedir_nosave;
 
-/*
- * Preferred image size in MB (set it to zero to get the smallest
- * image possible)
- */
-#define IMAGE_SIZE     500
+/* Preferred image size in MB (default 500) */
+extern unsigned int image_size;
 
 extern asmlinkage int swsusp_arch_suspend(void);
 extern asmlinkage int swsusp_arch_resume(void);
index 6d5ceaf..d760a6a 100644 (file)
 
 #include "power.h"
 
+/*
+ * Preferred image size in MB (tunable via /sys/power/image_size).
+ * When it is set to N, swsusp will do its best to ensure the image
+ * size will not exceed N MB, but if that is impossible, it will
+ * try to create the smallest image possible.
+ */
+unsigned int image_size = 500;
+
 #ifdef CONFIG_HIGHMEM
 unsigned int count_highmem_pages(void);
 int save_highmem(void);
@@ -647,7 +655,7 @@ int swsusp_shrink_memory(void)
                        if (!tmp)
                                return -ENOMEM;
                        pages += tmp;
-               } else if (size > (IMAGE_SIZE * 1024 * 1024) / PAGE_SIZE) {
+               } else if (size > (image_size * 1024 * 1024) / PAGE_SIZE) {
                        tmp = shrink_all_memory(SHRINK_BITE);
                        pages += tmp;
                }