#include "power.h"
+/*This is just an arbitrary number */
+#define FREE_PAGE_NUMBER (100)
+
DECLARE_MUTEX(pm_sem);
struct pm_ops * pm_ops = NULL;
static int suspend_prepare(suspend_state_t state)
{
int error = 0;
+ unsigned int free_pages;
if (!pm_ops || !pm_ops->enter)
return -EPERM;
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;