Force emergency allocations to trigger under low memory conditions

A concept of an emergency allocation was introduced last year to permit
allocations that took excessive periods of time to switch to physical
memory to make forward progress. Emergency allocations currently occur
by setting a flag, telling kmem_cache_alloc() to try again and then
doing the allocation. This is useful, but it might not always trigger
because we do not permit allocations in the spl_cache_grow() to
retry. This permits allocation failures to fail before the timer for
emergency allocations can trigger. This will result in a return to
kmem_cache_alloc(), which will then repeat the process. The result is
that we can loop infinitely without any forward progress under low
memory conditions because the emergency allocations will not trigger.

We change the code to force the worker to retry indefinitely. This
guarentees that the emergency allocations will trigger under low memory
conditions. In addition, we remove the KMC_BIT_DEADLOCKED bit in favor
of immediate use of the emergency allocation.

Signed-off-by: Richard Yao <ryao@gentoo.org>
Use pages for emergency allocations when possible and necessary

A concept of an emergency allocation was introduced last year to permit
allocations that took excessive periods of time to switch to physical
memory to make forward progress.

Unfortunately, the Linux kernel's physical memory allocator does SLAB
allocation for all allocations less than or equal to 8192. This permits memory
fragmentation to cause allocations to hang whenever an allocation is made from
a cache that uses slabs that span multiple pages. In specific, whenever the
allocation is greater than 256-bytes.

Whenever an emergency object is small enough to fit into a single page and is
larger than 256-bytes, we allocate a page for the emergency allocation instead
of going through kmalloc(). Larger object sizes are still at risk, but there is
little we can do for them.

Signed-off-by: Richard Yao <ryao@gentoo.org>
Permit KM_PUSHPAGE to trigger OOM killer

KM_PUSHPAGE is used in situations where we need to dip into emergency
memory reserves to ensure forward progress in operations that can
involve pageout. If the reserves are depleted, then it is acceptable to
invoke the OOM killer, but it is not appropriate to invoke another swap
operation. Currently, KM_PUSHPAGE is the equivalent to ( __GFP_WAIT |
__GFP_HIGH). The OOM killer will only trigger when (gfp_mask & __GFP_FS)
&& !(gfp_mask & __GFP_NORETRY) is true. Therefore, we redefine
KM_PUSHPAGE to be (__GFP_WAIT | __GFP_HIGH | __GFP_FS). The absence of
___GFP_IO prevents swap operations from being triggered while the
presence of __GFP_FS permits the OOM killer to trigger.

Signed-off-by: Richard Yao <ryao@gentoo.org>
Map kmem_alloc() invocations to kmem_cache_alloc()

Signed-off-by: Richard Yao <ryao@gentoo.org>