static int suspend_prepare_image(void) { int error; pr_debug("swsusp: critical section: \n"); if (save_highmem()) { printk(KERN_CRIT "Suspend machine: Not enough free pages for highmem\n"); restore_highmem(); return -ENOMEM; } drain_local_pages(); count_data_pages(); printk("swsusp: Need to copy %u pages\n",nr_copy_pages); error = swsusp_alloc(); if (error) return error; /* During allocating of suspend pagedir, new cold pages may appear. * Kill them. */ drain_local_pages(); copy_data_pages(); /* * End of critical section. From now on, we can write to memory, * but we should not touch disk. This specially means we must _not_ * touch swap space! Except we must write out our image of course. */ printk("swsusp: critical section/: done (%d pages copied)\n", nr_copy_pages ); return 0; }
asmlinkage int swsusp_save(void) { unsigned int nr_pages; pr_debug("swsusp: critical section: \n"); drain_local_pages(); nr_pages = count_data_pages(); printk("swsusp: Need to copy %u pages\n", nr_pages); if (!enough_free_mem(nr_pages)) { printk(KERN_ERR "swsusp: Not enough free memory\n"); return -ENOMEM; } if (swsusp_alloc(&orig_bm, ©_bm, nr_pages)) return -ENOMEM; /* During allocating of suspend pagedir, new cold pages may appear. * Kill them. */ drain_local_pages(); copy_data_pages(©_bm, &orig_bm); /* * End of critical section. From now on, we can write to memory, * but we should not touch disk. This specially means we must _not_ * touch swap space! Except we must write out our image of course. */ nr_copy_pages = nr_pages; nr_meta_pages = (nr_pages * sizeof(long) + PAGE_SIZE - 1) >> PAGE_SHIFT; printk("swsusp: critical section/: done (%d pages copied)\n", nr_pages); return 0; }