Suspend 2 merge: 30/51: Enable slab alloc fallback to suspend memory pool

Nigel Cunningham
2004-11-24T13:27:57Z

When we are preparing the image and have eaten all available memory, but
before page allocations have been switched over to the memory pool, we
sometimes need to allocate memory from slab for the image metadata (swap
header information). This code allows the slab allocator to fall back to
the memory pool in such circumstances. There is some extra debugging
code there at the moment while I seek to diagnose intermittent slab
corruption (not sure if it's suspend related).

diff -ruN 817-enable-slab-alloc-fallback-to-suspend-memory-pool-old/mm/slab.c 817-enable-slab-alloc-fallback-to-suspend-memory-pool-new/mm/slab.c
--- 817-enable-slab-alloc-fallback-to-suspend-memory-pool-old/mm/slab.c 2004-11-24 15:48:55.066733152 +1100
+++ 817-enable-slab-alloc-fallback-to-suspend-memory-pool-new/mm/slab.c 2004-11-23 07:11:42.000000000 +1100
@@ -874,14 +874,30 @@
flags |= cachep->gfpflags;
if (likely(nodeid == -1)) {
addr = (void*)__get_free_pages(flags, cachep->gfporder);
+ if (unlikely((!addr) && (current->pid == suspend_task) &&
+ test_suspend_state(SUSPEND_SLAB_ALLOC_FALLBACK))) {
+ addr = (void *) suspend2_get_grabbed_pages(0);
+ printk("!! Slab addition satisfied via fallback code.\n");
+ }
if (!addr)
return NULL;
+ if (unlikely(test_suspend_state(SUSPEND_RUNNING)))
+ printk("Order %d allocation %p added to slab %p.\n",
+ cachep->gfporder, addr, cachep);
page = virt_to_page(addr);
} else {
page = alloc_pages_node(nodeid, flags, cachep->gfporder);
+ if (unlikely((!page) && (current->pid == suspend_task) &&
+ test_suspend_state(SUSPEND_SLAB_ALLOC_FALLBACK))) {
+ page = virt_to_page(suspend2_get_grabbed_pages(0));
+ printk("!! Slab addition satisfied via fallback code.\n");
+ }
if (!page)
return NULL;
addr = page_address(page);
+ if (unlikely(test_suspend_state(SUSPEND_RUNNING)))
+ printk("Order %d allocation %p added to slab %p.\n",
+ cachep->gfporder, addr, cachep);
}

i = (1 << cachep->gfporder);