zsmalloc: add to mm/

=========
DO NOT MERGE, FOR REVIEW ONLY
This patch introduces zsmalloc as new code, however, it already
exists in drivers/staging.  In order to build successfully, you
must select EITHER to driver/staging version OR this version.
Once zsmalloc is reviewed in this format (and hopefully accepted),
I will create a new patchset that properly promotes zsmalloc from
staging.
=========

This patchset introduces a new slab-based memory allocator,
zsmalloc, for storing compressed pages.  It is designed for
low fragmentation and high allocation success rate on
large object, but <= PAGE_SIZE allocations.

zsmalloc differs from the kernel slab allocator in two primary
ways to achieve these design goals.

zsmalloc never requires high order page allocations to back
slabs, or "size classes" in zsmalloc terms. Instead it allows
multiple single-order pages to be stitched together into a
"zspage" which backs the slab.  This allows for higher allocation
success rate under memory pressure.

Also, zsmalloc allows objects to span page boundaries within the
zspage.  This allows for lower fragmentation than could be had
with the kernel slab allocator for objects between PAGE_SIZE/2
and PAGE_SIZE.  With the kernel slab allocator, if a page compresses
to 60% of it original size, the memory savings gained through
compression is lost in fragmentation because another object of
the same size can't be stored in the leftover space.

This ability to span pages results in zsmalloc allocations not being
directly addressable by the user.  The user is given an
non-dereferencable handle in response to an allocation request.
That handle must be mapped, using zs_map_object(), which returns
a pointer to the mapped region that can be used.  The mapping is
necessary since the object data may reside in two different
noncontigious pages.

zsmalloc fulfills the allocation needs for zram and zswap.

Acked-by: Nitin Gupta <ngupta@vflare.org>
Acked-by: Minchan Kim <minchan@kernel.org>
Signed-off-by: Seth Jennings <sjenning@linux.vnet.ibm.com>
zsmalloc: add documentation

This patch adds a documentation file for zsmalloc at
Documentation/vm/zsmalloc.txt

Signed-off-by: Seth Jennings <sjenning@linux.vnet.ibm.com>
debugfs: add get/set for atomic types

debugfs currently lack the ability to create attributes
that set/get atomic_t values.

This patch adds support for this through a new
debugfs_create_atomic_t() function.

Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Seth Jennings <sjenning@linux.vnet.ibm.com>
zswap: add to mm/

zswap is a thin compression backend for frontswap. It receives
pages from frontswap and attempts to store them in a compressed
memory pool, resulting in an effective partial memory reclaim and
dramatically reduced swap device I/O.

Additionally, in most cases, pages can be retrieved from this
compressed store much more quickly than reading from tradition
swap devices resulting in faster performance for many workloads.

This patch adds the zswap driver to mm/

Signed-off-by: Seth Jennings <sjenning@linux.vnet.ibm.com>
mm: break up swap_writepage() for frontswap backends

swap_writepage() is currently where frontswap hooks into the swap
write path to capture pages with the frontswap_store() function.
However, if a frontswap backend wants to "resume" the writeback of
a page to the swap device, it can't call swap_writepage() as
the page will simply reenter the backend.

This patch separates swap_writepage() into a top and bottom half, the
bottom half named __swap_writepage() to allow a frontswap backend,
like zswap, to resume writeback beyond the frontswap_store() hook.

__add_to_swap_cache() is also made non-static so that the page for
which writeback is to be resumed can be added to the swap cache.

Acked-by: Minchan Kim <minchan@kernel.org>
Signed-off-by: Seth Jennings <sjenning@linux.vnet.ibm.com>
mm: allow for outstanding swap writeback accounting

To prevent flooding the swap device with writebacks, frontswap
backends need to count and limit the number of outstanding
writebacks.  The incrementing of the counter can be done before
the call to __swap_writepage().  However, the caller must receive
a notification when the writeback completes in order to decrement
the counter.

To achieve this functionality, this patch modifies
__swap_writepage() to take the bio completion callback function
as an argument.

end_swap_bio_write(), the normal bio completion function, is also
made non-static so that code doing the accounting can call it
after the accounting is done.

Acked-by: Minchan Kim <minchan@kernel.org>
Signed-off-by: Seth Jennings <sjenning@linux.vnet.ibm.com>
zswap: add swap page writeback support

This patch adds support for evicting swap pages that are currently
compressed in zswap to the swap device.  This functionality is very
important and make zswap a true cache in that, once the cache is full
or can't grow due to memory pressure, the oldest pages can be moved
out of zswap to the swap device so newer pages can be compressed and
stored in zswap.

This introduces a good amount of new code to guarantee coherency.
Most notably, and LRU list is added to the zswap_tree structure,
and refcounts are added to each entry to ensure that one code path
doesn't free then entry while another code path is operating on it.

Signed-off-by: Seth Jennings <sjenning@linux.vnet.ibm.com>
zswap: add documentation

This patch adds the documentation file for the zswap functionality

Signed-off-by: Seth Jennings <sjenning@linux.vnet.ibm.com>
Revert "Merge remote-tracking branch 'github/3.8/zswap' into 3.8/master"

This reverts commit 636753a4bfe5f5e013ce22684b99e42a454f0804, reversing
changes made to 7a69e9a8db95dd13ff1beb7ad8cdf3c4edac4a32.
Merge branch '3.8/zswap' into 3.8/master