]> err.no Git - linux-2.6/commitdiff
[ACPI] Suspend to RAM fix
authorDavid Shaohua Li <shaohua.li@intel.com>
Fri, 18 Mar 2005 21:27:13 +0000 (16:27 -0500)
committerLen Brown <len.brown@intel.com>
Tue, 12 Jul 2005 03:21:54 +0000 (23:21 -0400)
Free some RAM before entering S3 so that upon
resume we can be sure early allocations will succeed.

http://bugzilla.kernel.org/show_bug.cgi?id=3469

Signed-off-by: David Shaohua Li <shaohua.li@intel.com>
Signed-off-by: Len Brown <len.brown@intel.com>
kernel/power/main.c

index c7eb4a833db53ce6068c125204fd4bca62922994..454434716f35ccf477c7f7e535a6abc6942e72fe 100644 (file)
@@ -19,6 +19,9 @@
 
 #include "power.h"
 
+/*This is just an arbitrary number */
+#define FREE_PAGE_NUMBER (100)
+
 DECLARE_MUTEX(pm_sem);
 
 struct pm_ops * pm_ops = NULL;
@@ -49,6 +52,7 @@ void pm_set_ops(struct pm_ops * ops)
 static int suspend_prepare(suspend_state_t state)
 {
        int error = 0;
+       unsigned int free_pages;
 
        if (!pm_ops || !pm_ops->enter)
                return -EPERM;
@@ -60,6 +64,16 @@ static int suspend_prepare(suspend_state_t state)
                goto Thaw;
        }
 
+       if ((free_pages = nr_free_pages()) < FREE_PAGE_NUMBER) {
+               pr_debug("PM: free some memory\n");
+               shrink_all_memory(FREE_PAGE_NUMBER - free_pages);
+               if (nr_free_pages() < FREE_PAGE_NUMBER) {
+                       error = -ENOMEM;
+                       printk(KERN_ERR "PM: No enough memory\n");
+                       goto Thaw;
+               }
+       }
+
        if (pm_ops->prepare) {
                if ((error = pm_ops->prepare(state)))
                        goto Thaw;