ZRAM / ZSMALLOC: *squashing updates*

backported for kernel 3.4.y

currently following patches are missing due of missing compatibility:
(they don't improve functionality though)

  -> "block: Abstract out bvec iterator"
  -> "block: Convert bio_for_each_segment() to bvec_iter"

-----------------------------------------------------------------------------

zram: drop `init_done' struct zram member

      Introduce init_done() helper function which allows us to drop `init_done'
      struct zram member.  init_done() uses the fact that ->init_done == 1
      equals to ->meta != NULL.

      Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
      Acked-by: Minchan Kim <minchan@kernel.org>
      Acked-by: Jerome Marchand <jmarchan@redhat.com>
      Cc: Nitin Gupta <ngupta@vflare.org>
      Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
      Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

zram: use atomic64_t for all zram stats

      This is a preparation patch for stats code duplication removal.

      1) use atomic64_t for `pages_zero' and `pages_stored' zram stats.

      2) `compr_size' and `pages_zero' struct zram_stats members did not

	follow the existing device attr naming scheme: zram_stats.ATTR has
	ATTR_show() function.  rename them:

	-- compr_size -> compr_data_size
	-- pages_zero -> zero_pages

      Minchan Kim's note:
      If we really have trouble with atomic stat operation, we could
      change it with percpu_counter so that it could solve atomic overhead and
      unnecessary memory space by introducing unsigned long instead of 64bit
      atomic_t.

      Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
      Acked-by: Minchan Kim <minchan@kernel.org>
      Acked-by: Jerome Marchand <jmarchan@redhat.com>
      Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
      Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

zram: remove good and bad compress stats

      Remove `good' and `bad' compressed sub-requests stats.  RW request may
      cause a number of RW sub-requests.  zram used to account `good' compressed
      sub-queries (with compressed size less than 50% of original size), `bad'
      compressed sub-queries (with compressed size greater that 75% of original
      size), leaving sub-requests with compression size between 50% and 75% of
      original size not accounted and not reported.  zram already accounts each
      sub-request's compression size so we can calculate real device compression
      ratio.

      Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
      Acked-by: Minchan Kim <minchan@kernel.org>
      Acked-by: Jerome Marchand <jmarchan@redhat.com>
      Cc: Nitin Gupta <ngupta@vflare.org>
      Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
      Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

zram: remove zram stats code duplication

      Introduce ZRAM_ATTR_RO macro that generates device_attribute and default
      ATTR show() function for existing atomic64_t zram stats.

      Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
      Acked-by: Minchan Kim <minchan@kernel.org>
      Cc: Jerome Marchand <jmarchan@redhat.com>
      Cc: Nitin Gupta <ngupta@vflare.org>
      Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
      Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

zram: report failed read and write stats

      zram accounted but did not report numbers of failed read and write
      queries.  make these stats available as failed_reads and failed_writes
      attrs.

      Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
      Acked-by: Minchan Kim <minchan@kernel.org>
      Acked-by: Jerome Marchand <jmarchan@redhat.com>
      Cc: Nitin Gupta <ngupta@vflare.org>
      Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
      Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

zram: drop not used table `count' member

      struct table `count' member is not used.

      Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
      Cc: Minchan Kim <minchan@kernel.org>
      Acked-by: Jerome Marchand <jmarchan@redhat.com>
      Cc: Nitin Gupta <ngupta@vflare.org>
      Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
      Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

zram: move zram size warning to documentation

      Move zram warning about disksize and size of memory correlation to zram
      documentation.

      Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
      Acked-by: Minchan Kim <minchan@kernel.org>
      Cc: Jerome Marchand <jmarchan@redhat.com>
      Cc: Nitin Gupta <ngupta@vflare.org>
      Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
      Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

zram: delete zram_init_device()

      allocate new `zram_meta' in disksize_store() only for uninitialised zram
      device, saving a number of allocations and deallocations in case if
      disksize_store() was called on currently used device.  at the same time
      zram_meta stack variable is not necessary, because we can set ->meta
      directly.  there is also no need in setting QUEUE_FLAG_NONROT queue on
      every disksize_store(), set it once during device creation.

      [minchan@kernel.org: handle zram->meta alloc fail case]
      [minchan@kernel.org: prevent lockdep spew of init_lock]
      Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
      Signed-off-by: Minchan Kim <minchan@kernel.org>
      Acked-by: Jerome Marchand <jmarchan@redhat.com>
      Cc: Sasha Levin <sasha.levin@oracle.com>
      Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
      Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

zram: support REQ_DISCARD (modified!)

  Changes in function: static void zram_bio_discard
  From: size_t n = bio->bi_iter.bi_size;
  To: size_t n = bio->bi_size;

      zram is ram based block device and can be used by backend of filesystem.
      When filesystem deletes a file, it normally doesn't do anything on data
      block of that file.  It just marks on metadata of that file.  This
      behavior has no problem on disk based block device, but has problems on
      ram based block device, since we can't free memory used for data block.
      To overcome this disadvantage, there is REQ_DISCARD functionality.  If
      block device support REQ_DISCARD and filesystem is mounted with discard
      option, filesystem sends REQ_DISCARD to block device whenever some data
      blocks are discarded.  All we have to do is to handle this request.

      This patch implements to flag up QUEUE_FLAG_DISCARD and handle this
      REQ_DISCARD request.  With it, we can free memory used by zram if it isn't
      used.

      [akpm@linux-foundation.org: tweak comments]
      Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
      Cc: Minchan Kim <minchan@kernel.org>
      Cc: Nitin Gupta <ngupta@vflare.org>
      Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
      Cc: Jerome Marchand <jmarchan@redhat.com>
      Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
      Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

zram: do not pass rw argument to __zram_make_request()

      Do not pass rw argument down the __zram_make_request() -> zram_bvec_rw()
      chain, decode it in zram_bvec_rw() instead.  Besides, this is the place
      where we distinguish READ and WRITE bio data directions, so account zram
      RW stats here, instead of __zram_make_request().  This also allows to
      account a real number of zram READ/WRITE operations, not just requests
      (single RW request may cause a number of zram RW ops with separate
      locking, compression/decompression, etc).

      Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
      Acked-by: Minchan Kim <minchan@kernel.org>
      Acked-by: Jerome Marchand <jmarchan@redhat.com>
      Cc: Nitin Gupta <ngupta@vflare.org>
      Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
      Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Signed-off-by: moddingg33k <moddingg33k@t-online.de>
mm: remove compressed copy from zram in-memory

Swap subsystem does lazy swap slot free with expecting the page would be
swapped out again so we can avoid unnecessary write.

But the problem in in-memory swap(ex, zram) is that it consumes memory
space until vm_swap_full(ie, used half of all of swap device) condition
meet.  It could be bad if we use multiple swap device, small in-memory
swap and big storage swap or in-memory swap alone.

This patch makes swap subsystem free swap slot as soon as swap-read is
completed and make the swapcache page dirty so the page should be
written out the swap device to reclaim it.  It means we never lose it.

I tested this patch with kernel compile workload.

1. before

   compile time : 9882.42
   zram max wasted space by fragmentation: 13471881 byte
   memory space consumed by zram: 174227456 byte
   the number of slot free notify: 206684

2. after

   compile time : 9653.90
   zram max wasted space by fragmentation: 11805932 byte
   memory space consumed by zram: 154001408 byte
   the number of slot free notify: 426972

[akpm@linux-foundation.org: tweak comment text]
[artem.savkov@gmail.com: fix BUG due to non-swapcache pages in end_swap_bio_read()]
[akpm@linux-foundation.org: invert unlikely() test, augment comment, 80-col cleanup]
Signed-off-by: Dan Magenheimer <dan.magenheimer@oracle.com>
Signed-off-by: Minchan Kim <minchan@kernel.org>
Signed-off-by: Artem Savkov <artem.savkov@gmail.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Seth Jennings <sjenning@linux.vnet.ibm.com>
Cc: Nitin Gupta <ngupta@vflare.org>
Cc: Konrad Rzeszutek Wilk <konrad@darnok.org>
Cc: Shaohua Li <shli@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Conflicts:
	mm/page_io.c

Change-Id: I8f11fb7f0391954435002e7f290352f311c907d4
Enable ZRAM
ZRAM: switched to num_devices=2

Signed-off-by: moddingg33k <moddingg33k@t-online.de>