aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/power/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/power/main.c')
-rw-r--r--kernel/power/main.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/kernel/power/main.c b/kernel/power/main.c
index c7eb4a833db5..454434716f35 100644
--- a/kernel/power/main.c
+++ b/kernel/power/main.c
@@ -19,6 +19,9 @@
19 19
20#include "power.h" 20#include "power.h"
21 21
22/*This is just an arbitrary number */
23#define FREE_PAGE_NUMBER (100)
24
22DECLARE_MUTEX(pm_sem); 25DECLARE_MUTEX(pm_sem);
23 26
24struct pm_ops * pm_ops = NULL; 27struct pm_ops * pm_ops = NULL;
@@ -49,6 +52,7 @@ void pm_set_ops(struct pm_ops * ops)
49static int suspend_prepare(suspend_state_t state) 52static int suspend_prepare(suspend_state_t state)
50{ 53{
51 int error = 0; 54 int error = 0;
55 unsigned int free_pages;
52 56
53 if (!pm_ops || !pm_ops->enter) 57 if (!pm_ops || !pm_ops->enter)
54 return -EPERM; 58 return -EPERM;
@@ -60,6 +64,16 @@ static int suspend_prepare(suspend_state_t state)
60 goto Thaw; 64 goto Thaw;
61 } 65 }
62 66
67 if ((free_pages = nr_free_pages()) < FREE_PAGE_NUMBER) {
68 pr_debug("PM: free some memory\n");
69 shrink_all_memory(FREE_PAGE_NUMBER - free_pages);
70 if (nr_free_pages() < FREE_PAGE_NUMBER) {
71 error = -ENOMEM;
72 printk(KERN_ERR "PM: No enough memory\n");
73 goto Thaw;
74 }
75 }
76
63 if (pm_ops->prepare) { 77 if (pm_ops->prepare) {
64 if ((error = pm_ops->prepare(state))) 78 if ((error = pm_ops->prepare(state)))
65 goto Thaw; 79 goto Thaw;