Suspend 2 merge: 28/51: Suspend memory pool hooks.

Nigel Cunningham
2004-11-24T14:55:59Z

We save the image in two pages (LRU and the rest). In order to maintain
a consistent image, we satisfy all page allocations from our own memory
pool while saving the image and reloading the LRU. This allows us to
safely use high level routines which might allocate slab etc and not
free it again by the time we do our atomic copy. We simply save all of
the pages in the pool when making our atomic copy of the non-LRU pages,
without having to worry about exactly how they were or weren't used.

diff -ruN 815-add-suspend-memory-pool-hooks-old/mm/page_alloc.c 815-add-suspend-memory-pool-hooks-new/mm/page_alloc.c
--- 815-add-suspend-memory-pool-hooks-old/mm/page_alloc.c 2004-11-06 09:26:49.168250960 +1100
+++ 815-add-suspend-memory-pool-hooks-new/mm/page_alloc.c 2004-11-04 16:27:41.000000000 +1100
@@ -277,6 +277,11 @@

arch_free_page(page, order);

+ if (unlikely(test_suspend_state(SUSPEND_USE_MEMORY_POOL))) {
+ suspend2_free_pool_pages(page, order);
+ return;
+ }
+
mod_page_state(pgfree, 1 << order);
for (i = 0 ; i < (1 << order) ; ++i)
free_pages_check(__FUNCTION__, page + i);
@@ -507,6 +512,11 @@

arch_free_page(page, 0);

+ if (unlikely(test_suspend_state(SUSPEND_USE_MEMORY_POOL))) {
+ suspend2_free_pool_pages(page, 0);
+ return;
+ }
+
kernel_map_pages(page, 1, 0);
inc_page_state(pgfree);
if (PageAnon(page))
@@ -609,6 +619,20 @@
int do_retry;
int can_try_harder;

+ if (unlikely(test_suspend_state(SUSPEND_USE_MEMORY_POOL))) {
+ /*
+ * When pool enabled, processes get allocations
+ * from a special pool so the image size doesn't
+ * vary (all the pages in the pool are saved,
+ * used or not).
+ *
+ * The only process that should be running is
+ * suspend, so the demand should be very
+ * predicatable.
+ */
+ return suspend2_get_pool_pages(gfp_mask, order);
+ }
+
might_sleep_if(wait);

/*