De-sonyfy LMK
zsmalloc: use 3.10 version of zsmalloc

commit 796ce5a7e4ef88ee0bfbeaa80070a51570650d57
Author: Arnd Bergmann <arnd@arndb.de>
Date:   Tue Apr 23 18:30:48 2013 +0200

    staging/zsmalloc: don't use pgtable-mapping from modules

    Building zsmalloc as a module does not work on ARM because it uses
    an interface that is not exported:

    ERROR: "flush_tlb_kernel_range" [drivers/staging/zsmalloc/zsmalloc.ko] undefined!

    Since this is only used as a performance optimization and only on ARM,
    we can avoid the problem simply by not using that optimization when
    building zsmalloc it is a loadable module.

    flush_tlb_kernel_range is often an inline function, but out of the
    architectures that use an extern function, only powerpc exports
    it.

    Signed-off-by: Arnd Bergmann <arnd@arndb.de>
    Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Cc: Seth Jennings <sjenning@linux.vnet.ibm.com>
    Cc: Nitin Gupta <ngupta@vflare.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit d95abbbb291bf5bce078148f53603ce9c0aa1d44
Author: Joerg Roedel <joro@8bytes.org>
Date:   Wed Mar 27 01:43:14 2013 +0100

    staging: zsmalloc: Fix link error on ARM

    Testing the arm chromebook config against the upstream
    kernel produces a linker error for the zsmalloc module from
    staging. The symbol flush_tlb_kernel_range is not available
    there. Fix this by removing the reimplementation of
    unmap_kernel_range in the zsmalloc module and using the
    function directly. The unmap_kernel_range function is not
    usable by modules, so also disallow building the driver as a
    module for now.

    Cc: stable <stable@vger.kernel.org>
    Signed-off-by: Joerg Roedel <joro@8bytes.org>
    Acked-by: Minchan Kim <minchan@kernel.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit 22b751c3d0376e86a377e3a0aa2ddbbe9d2eefc1
Author: Mel Gorman <mgorman@suse.de>
Date:   Fri Feb 22 16:34:59 2013 -0800

    mm: rename page struct field helpers

    The function names page_xchg_last_nid(), page_last_nid() and
    reset_page_last_nid() were judged to be inconsistent so rename them to a
    struct_field_op style pattern.  As it looked jarring to have
    reset_page_mapcount() and page_nid_reset_last() beside each other in
    memmap_init_zone(), this patch also renames reset_page_mapcount() to
    page_mapcount_reset().  There are others like init_page_count() but as
    it is used throughout the arch code a rename would likely cause more
    conflicts than it is worth.

    [akpm@linux-foundation.org: fix zcache]
    Signed-off-by: Mel Gorman <mgorman@suse.de>
    Suggested-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

commit 0d145a501778042d0411c843ed5b468b41f8a171
Author: Seth Jennings <sjenning@linux.vnet.ibm.com>
Date:   Wed Jan 30 09:36:52 2013 -0600

    staging: zsmalloc: remove unused pool name

    zs_create_pool() currently takes a name argument which is
    never used in any useful way.

    This patch removes it.

    Signed-off-by: Seth Jennings <sjenning@linux.vnet.ibm.com>
    Acked-by: Nitin Gupta <ngupta@vflare.org>
    Acked-by: Rik van Riel <riel@redhat.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit 9915518887e83764269d5b617d01782893877ed3
Author: Minchan Kim <minchan@kernel.org>
Date:   Mon Jan 28 10:00:08 2013 +0900

    staging: zsmalloc: Fix TLB coherency and build problem

    Recently, Matt Sealey reported he fail to build zsmalloc caused by
    using of local_flush_tlb_kernel_range which are architecture dependent
    function so !CONFIG_SMP in ARM couldn't implement it so it ends up
    build error following as.

      MODPOST 216 modules
      LZMA    arch/arm/boot/compressed/piggy.lzma
      AS      arch/arm/boot/compressed/lib1funcs.o
    ERROR: "v7wbi_flush_kern_tlb_range"
    [drivers/staging/zsmalloc/zsmalloc.ko] undefined!
    make[1]: *** [__modpost] Error 1
    make: *** [modules] Error 2
    make: *** Waiting for unfinished jobs....

    The reason we used that function is copy method by [1]
    was really slow in ARM but at that time.

    More severe problem is ARM can prefetch speculatively on other CPUs
    so under us, other TLBs can have an entry only if we do flush local
    CPU. Russell King pointed that. Thanks!
    We don't have many choices except using flush_tlb_kernel_range.

    My experiment in ARMv7 processor 4 core didn't make any difference with
    zsmapbench[2] between local_flush_tlb_kernel_range and flush_tlb_kernel_range
    but still page-table based is much better than copy-based.

    * bigger is better.

    1. local_flush_tlb_kernel_range: 3918795 mappings
    2. flush_tlb_kernel_range : 3989538 mappings
    3. copy-based: 635158 mappings

    This patch replace local_flush_tlb_kernel_range with
    flush_tlb_kernel_range which are avaialbe in all architectures
    because we already have used it in vmalloc allocator which are
    generic one so build problem should go away and performane loss
    shoud be void.

    [1] f553646, zsmalloc: add page table mapping method
    [2] https://github.com/spartacus06/zsmapbench

    Cc: stable@vger.kernel.org
    Cc: Dan Magenheimer <dan.magenheimer@oracle.com>
    Cc: Russell King <linux@arm.linux.org.uk>
    Cc: Konrad Rzeszutek Wilk <konrad@darnok.org>
    Cc: Nitin Gupta <ngupta@vflare.org>
    Cc: Seth Jennings <sjenning@linux.vnet.ibm.com>
    Reported-by: Matt Sealey <matt@genesi-usa.com>
    Signed-off-by: Minchan Kim <minchan@kernel.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit d662b8eba94e9f6d4c036719dbf629ef0c9309cf
Author: Seth Jennings <sjenning@linux.vnet.ibm.com>
Date:   Fri Jan 25 11:46:18 2013 -0600

    staging: zsmalloc: make CLASS_DELTA relative to PAGE_SIZE

    Right now ZS_SIZE_CLASS_DELTA is hardcoded to be 16.  This
    creates 254 classes for systems with 4k pages. However, on
    PPC64 with 64k pages, it creates 4095 classes which is far
    too many.

    This patch makes ZS_SIZE_CLASS_DELTA relative to PAGE_SIZE
    so that regardless of the page size, there will be the same
    number of classes.

    Acked-by: Nitin Gupta <ngupta@vflare.org>
    Acked-by: Minchan Kim <minchan@kernel.org>
    Signed-off-by: Seth Jennings <sjenning@linux.vnet.ibm.com>
    Acked-by: Dan Magenheimer <dan.magenheimer@oracle.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit 4bbc0bc06b8b0cced31ee17beb753ad51a2e47e7
Author: Davidlohr Bueso <davidlohr.bueso@hp.com>
Date:   Fri Jan 4 12:14:00 2013 -0800

    staging: zsmalloc: comment zs_create_pool function

    Just as with zs_malloc() and zs_map_object(), it is worth
    formally commenting the zs_create_pool() function.

    Signed-off-by: Davidlohr Bueso <davidlohr.bueso@hp.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit 0959c63f11c3bbef0a7d6c5011be8d25503f547c
Author: Seth Jennings <sjenning@linux.vnet.ibm.com>
Date:   Wed Aug 8 15:12:17 2012 +0900

    zsmalloc: collapse internal .h into .c

    The patch collapses in the internal zsmalloc_int.h into
    the zsmalloc-main.c file.

    This is done in preparation for the promotion to mm/ where
    separate internal headers are discouraged.

    Signed-off-by: Seth Jennings <sjenning@linux.vnet.ibm.com>
    Signed-off-by: Minchan Kim <minchan@kernel.org>
    Acked-by: Nitin Gupta <ngupta@vflare.org>
    Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit f553646a67cb215577402cb702b67c8cf8fdb46f
Author: Seth Jennings <sjenning@linux.vnet.ibm.com>
Date:   Wed Jul 18 11:55:56 2012 -0500

    staging: zsmalloc: add page table mapping method

    This patchset provides page mapping via the page table.
    On some archs, most notably ARM, this method has been
    demonstrated to be faster than copying.

    The logic controlling the method selection (copy vs page table)
    is controlled by the definition of USE_PGTABLE_MAPPING which
    is/can be defined for any arch that performs better with page
    table mapping.

    Signed-off-by: Seth Jennings <sjenning@linux.vnet.ibm.com>
    Acked-by: Minchan Kim <minchan@kernel.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit c60369f011251c60de506994aab088f1afb90bf4
Author: Seth Jennings <sjenning@linux.vnet.ibm.com>
Date:   Wed Jul 18 11:55:55 2012 -0500

    staging: zsmalloc: prevent mappping in interrupt context

    Because we use per-cpu mapping areas shared among the
    pools/users, we can't allow mapping in interrupt context
    because it can corrupt another users mappings.

    Signed-off-by: Seth Jennings <sjenning@linux.vnet.ibm.com>
    Acked-by: Minchan Kim <minchan@kernel.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit 6539a36c0cb9ec7f1c1633b535ac83b2bdf0ae6d
Author: Seth Jennings <sjenning@linux.vnet.ibm.com>
Date:   Wed Jul 18 11:55:54 2012 -0500

    staging: zsmalloc: s/firstpage/page in new copy map funcs

    firstpage already has precedent and meaning the first page
    of a zspage.  In the case of the copy mapping functions,
    it is the first of a pair of pages needing to be mapped.

    This patch just renames the firstpage argument to "page" to
    avoid confusion.

    Signed-off-by: Seth Jennings <sjenning@linux.vnet.ibm.com>
    Acked-by: Minchan Kim <minchan@kernel.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit b74185108668ef966e663878adbad65e03bfcb43
Author: Seth Jennings <sjenning@linux.vnet.ibm.com>
Date:   Mon Jul 2 16:15:52 2012 -0500

    staging: zsmalloc: add mapping modes

    This patch improves mapping performance in zsmalloc by getting
    usage information from the user in the form of a "mapping mode"
    and using it to avoid unnecessary copying for objects that span
    pages.

    Signed-off-by: Seth Jennings <sjenning@linux.vnet.ibm.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit 166cfda752ca22eb6912614993b85f9a997dbd8f
Author: Seth Jennings <sjenning@linux.vnet.ibm.com>
Date:   Mon Jul 2 16:15:51 2012 -0500

    staging: zsmalloc: add details to zs_map_object boiler plate

    Add information on the usage limits of zs_map_object()

    Signed-off-by: Seth Jennings <sjenning@linux.vnet.ibm.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit 103123305c4f695cbb11555d51a32ea14d6bed05
Author: Seth Jennings <sjenning@linux.vnet.ibm.com>
Date:   Mon Jul 2 16:15:50 2012 -0500

    staging: zsmalloc: add single-page object fastpath in unmap

    Improve zs_unmap_object() performance by adding a fast path for
    objects that don't span pages.

    Signed-off-by: Seth Jennings <sjenning@linux.vnet.ibm.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit 5f601902c61e6cda627ec71c10609021067ed0fa
Author: Seth Jennings <sjenning@linux.vnet.ibm.com>
Date:   Mon Jul 2 16:15:49 2012 -0500

    staging: zsmalloc: remove x86 dependency

    This patch replaces the page table assisted object mapping
    method, which has x86 dependencies, with a arch-independent
    method that does a simple copy into a temporary per-cpu
    buffer.

    While a copy seems like it would be worse than mapping the pages,
    tests demonstrate the copying is always faster and, in the case of
    running inside a KVM guest, roughly 4x faster.

    Signed-off-by: Seth Jennings <sjenning@linux.vnet.ibm.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit 069f101fa463351f528773d73b74e9b606b3f66a
Author: Ben Hutchings <ben@decadent.org.uk>
Date:   Wed Jun 20 02:31:11 2012 +0100

    staging: zsmalloc: Finish conversion to a separate module

    ZSMALLOC is tristate, but the code has no MODULE_LICENSE and since it
    depends on GPL-only symbols it cannot be loaded as a module.  This in
    turn breaks zram which now depends on it.  I assume it's meant to be
    Dual BSD/GPL like the other z-stuff.

    There is also no module_exit, which will make it impossible to unload.
    Add the appropriate module_init and module_exit declarations suggested
    by comments.

    Reported-by: Christian Ohm <chr.ohm@gmx.net>
    References: http://bugs.debian.org/677273
    Cc: stable@vger.kernel.org # v3.4
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
    Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit b4b700c5a61c6e6db976f60d4eb6ad369e838aa9
Author: Seth Jennings <sjenning@linux.vnet.ibm.com>
Date:   Wed Jun 13 16:03:42 2012 -0500

    staging: zsmalloc: fix uninit'ed variable warning

    This patch fixes an uninitialized variable warning in
    alloc_zspage().  It also fixes the secondary issue of
    prev_page leaving scope on each loop iteration.  The only
    reason this ever worked was because prev_page was occupying
    the same space on the stack on each iteration.

    Signed-off-by: Seth Jennings <sjenning@linux.vnet.ibm.com>
    Reported-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit 2db51dae56240b52fe08ddbb1a2eb47fe7cfd044
Author: Nitin Gupta <ngupta@vflare.org>
Date:   Sat Jun 9 17:41:14 2012 -0700

    staging: zsmalloc documentation

    Documentation of various struct page fields
    used by zsmalloc.

    Changes for v2:
    	- Regroup descriptions as suggested by Konrad

    Signed-off-by: Nitin Gupta <ngupta@vflare.org>
    Acked-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
    Reviewed-by: Minchan Kim <minchan@kernel.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit c234434835b1f4bad9bdbae6710044cba387c9e5
Author: Minchan Kim <minchan@kernel.org>
Date:   Fri Jun 8 15:39:25 2012 +0900

    staging: zsmalloc: zsmalloc: use unsigned long instead of void *

    We should use unsigned long as handle instead of void * to avoid any
    confusion. Without this, users may just treat zs_malloc return value as
    a pointer and try to deference it.

    This patch passed compile test(zram, zcache and ramster) and zram is
    tested on qemu.

    changelog
      * from v2
    	- remove hval pointed out by Nitin
    	- based on next-20120607
      * from v1
    	- change zcache's zv_create return value
    	- baesd on next-20120604

    Cc: Dan Magenheimer <dan.magenheimer@oracle.com>
    Acked-by: Seth Jennings <sjenning@linux.vnet.ibm.com>
    Acked-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
    Signed-off-by: Minchan Kim <minchan@kernel.org>
    Acked-by: Nitin Gupta <ngupta@vflare.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit 00a61d8618bb7314113eb3ba27c12631cd85c298
Author: Minchan Kim <minchan@kernel.org>
Date:   Thu May 3 15:40:40 2012 +0900

    staging: zsmalloc: add/fix function comment

    Add/fix the comment.

    Signed-off-by: Minchan Kim <minchan@kernel.org>
    Acked-by: Nitin Gupta <ngupta@vflare.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit 2e3b61547191a5934ff6c789aaa4d7e9a9e52f5a
Author: Minchan Kim <minchan@kernel.org>
Date:   Thu May 3 15:40:39 2012 +0900

    staging: zsmalloc: rename zspage_order with zspage_pages

    zspage_order defines how many pages are needed to make a zspage.
    So _order_ is rather awkward naming. It already deceive Jonathan
    - http://lwn.net/Articles/477067/
    " For each size, the code calculates an optimum number of pages (up to 16)"

    Let's change from _order_ to _pages_ and some function names.

    Signed-off-by: Minchan Kim <minchan@kernel.org>
    Acked-by: Nitin Gupta <ngupta@vflare.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit d210267741fb2a8b6d741d9040703683a39087f4
Merge: 69964ea 5bb196a
Author: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Date:   Wed May 2 11:48:07 2012 -0700

    Merge 3.4-rc5 into staging-next

    This resolves the conflict in:
    	drivers/staging/vt6656/ioctl.c

    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit a27545bf0bab9027e5c040901b68956551d9f63e
Author: Minchan Kim <minchan@kernel.org>
Date:   Wed Apr 25 15:23:09 2012 +0900

    zsmalloc: use PageFlag macro instead of [set|test]_bit

    MM code always uses PageXXX to handle page flags.
    Let's keep the consistency.

    Signed-off-by: Minchan Kim <minchan@kernel.org>
    Acked-by: Nitin Gupta <ngupta@vflare.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Change-Id: I542f0b9eaf0264e1c9e38f9669fec8ea0debae7c
Signed-off-by: Larry Bassel <lbassel@codeaurora.org>

Staging: Fixes string split across lines in zsmalloc zsmalloc-main

Fixes the following checkpatch warning:
WARNING: quoted string split across lines

Change-Id: Ia192b2d0213de838d61f77db233169c802a4419f
Signed-off-by: Marlies Ruck <marlies.ruck@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Git-commit: 93ad5ab50476aa7e2b33aac31f41d0efc9f729d7
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>

staging/zsmalloc: Fixed up incorrect formatted comments

The existing comments are using an odd style. Fixed them up to adhere
to the StyleGuide. No code changes.

Change-Id: I24a720787c00a79883cb268ebf1257b525655f7d
Signed-off-by: Sara Bird <sara.bird.iar@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Git-commit: 396b7fd6f9668c04f20ee6daca3054f5c5ec1056
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>

staging: zsmalloc: access page->private by using page_private macro

Change-Id: Ia09720c7787bc03c69d01874437bdc619cae8c7e
Signed-off-by: Sunghan Suh <sunghan.suh@samsung.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Git-commit: e842b976a88a39b447fc34bd0fcb3c0be0a1d9d9
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>

staging: zsmalloc: Rename page_mapcount_reset

The page_mapcount_reset function was renamed from
reset_page_mapcount when back-porting zsmalloc from 3.10 kernel.
Revert this change to enable compilation of zsmalloc.

Change-Id: Iba09fc3f0294dae746d2e2b026e0015711c22f01
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>

staging: zsmalloc: Ensure handle is never 0 on success

zsmalloc encodes a handle using the pfn and an object
index. On hardware platforms with physical memory starting
at 0x0 the pfn can be 0. This causes the encoded handle to be
0 and is incorrectly interpreted as an allocation failure.

This issue affects all current and future SoCs with physical
memory starting at 0x0. All MSM8974 SoCs which includes
Google Nexus 5 devices are affected.

To prevent this false error we ensure that the encoded handle
will not be 0 when allocation succeeds.

Change-Id: I5ad31712be4dd5105ebee81fa95927039c0f6935
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
android/lowmemorykiller: Check all tasks for death pending

The lowmemorykiller uses the TIF_MEMDIE flag to help ensure it doesn't
kill another task until the memory from the previously killed task has
been returned to the system.

However the lowmemorykiller does not currently look at tasks who do not
have a tasks->mm, but just because a process doesn't have a tasks->mm
does not mean that the task's memory has been fully returned to the
system yet.

In order to prevent the lowmemorykiller from unnecessarily killing
multiple applications in a row the lowmemorykiller has been changed to
ensure that previous killed tasks are no longer in the process list
before attempting to kill another task.

Change-Id: I7d8a8fd39ca5625e6448ed2efebfb621f6e93845
Signed-off-by: Liam Mark <lmark@codeaurora.org>
Revert "staging: android: lowmemorykiller: Don't count reserved free memory"

This reverts commit 3a249b547f83e0d5e8a9c764e28bd5b4ee13900d.
android/lowmemorykiller: Wait for memory to be freed

The memory reclaim code needs to give time to the system to
return the memory from a killed process otherwise the memory
reclaim code could run continuously, in multiple threads,
which could starve both the watchdog thread and the thread
which is responsible for returning the memory from the
killed process.

Change-Id: Ieded4bfe038ca936247fa4b638070e979b02eaa1
CRs-fixed: 447740
Signed-off-by: Liam Mark <lmark@codeaurora.org>
android/lowmemorykiller: Ignore tasks with freed mm

A killed task can stay in the task list long after its
memory has been returned to the system, therefore
ignore any tasks whose mm struct has been freed.

Change-Id: I76394b203b4ab2312437c839976f0ecb7b6dde4e
CRs-fixed: 450383
Signed-off-by: Liam Mark <lmark@codeaurora.org>

Conflicts:
	arch/arm/include/asm/thread_info.h
Revert "android/lowmemorykiller: Only consider gfp_mask free pages"

This change is not needed anymore due to a new and improved change to the
android low memory killer that is incompatible with this change. To be able
to apply the new change this change needs to be removed.

This reverts commit cc4baf70665f54305182bfaf98c6236d129e6dad.

Change-Id: I33801faf9ac7371f46cf409009939d853adee95e
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
android: lowmemorykiller: add lmk parameters tunning code.

There are cases that LMK doesn't run, even when it must run.
It is due to LMK shrinker not considering memory status per zone.
So add LMK parameters(other_free, other_file) tunnig code to
consider target zone of LMK shrinker.

Change-Id: I6f1f8660d5da920a0e3af45a160499965032081d
Git-commit: 22d990a58fc17b3f0155e15eb2dc3efa037bea1c
Git-repo: https://android.googlesource.com/kernel/common/
[ohaugan@codeaurora.org: Fix compilation issues]
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
android/lowmemorykiller: Account for total_swapcache_pages

The lowmemorykiller relies on NR_FILE_PAGES when measureing
the amount of reclaimable memory in the system.
However when swap is enabled swap cache pages are counted
in NR_FILE_PAGES, and swap cache pages aren't as reclaimable
in low memory as file cache pages. Therefore a large swap
cache can result in the lowmemorykiller not running and
an OOM occuring.

In order to ensure the lowmemorykiller properly evaluates the
amount of reclaimable memory don't count the swap cache pages.

Change-Id: I38239283e572f814b277c718eaf6be7f92abacbb
Signed-off-by: Liam Mark <lmark@codeaurora.org>
zram: use 3.10 version of zram

commit 25eeb667599b192ea850a062d69383ee864c06ab
Author: Wanpeng Li <liwanp@linux.vnet.ibm.com>
Date:   Wed Mar 13 15:06:16 2013 +0800

    zram: fix zram_bvec_read duplicate dump failure message and stat accumulation

    When zram decompress fails, the code unnecessarily dumps failure messages and
    does stat accumulation in function zram_decompress_page(), this work is already
    done in function zram_decompress_page, the patch skips the redundant work.

    Signed-off-by: Wanpeng Li <liwanp@linux.vnet.ibm.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit 78110bb8dc4a7ff331bfa3cfe7d4e287cfb3f22b
Author: Joe Perches <joe@perches.com>
Date:   Mon Feb 11 09:41:29 2013 -0800

    staging: Remove unnecessary OOM messages

    alloc failures already get standardized OOM
    messages and a dump_stack.

    For the affected mallocs around these OOM messages:

    Converted kzallocs with multiplies to kcalloc.
    Converted kmallocs with multiplies to kmalloc_array.
    Converted a kmalloc/strlen/strncpy to kstrdup.
    Moved a spin_lock below a removed OOM message and
    removed a now unnecessary spin_unlock.
    Neatened alignment and whitespace.

    Signed-off-by: Joe Perches <joe@perches.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit 1e927711c5ecabe76010ed9249f8f3747829f04f
Author: Fengguang Wu <fengguang.wu@intel.com>
Date:   Fri Feb 8 10:15:10 2013 +0800

    staging: zram: __zram_reset_device() can be static

    Signed-off-by: Fengguang Wu <fengguang.wu@intel.com>
    Cc: Minchan Kim <minchan@kernel.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit 8b3cc3edb745cbc131560d19e3f32d81c07454b1
Author: Minchan Kim <minchan@kernel.org>
Date:   Wed Feb 6 08:48:53 2013 +0900

    zram: get rid of lockdep warning

    Lockdep complains about recursive deadlock of zram->init_lock.
    [1] made it false positive because we can't request IO to zram
    before setting disksize. Anyway, we should shut lockdep up to
    avoid many reporting from user.

    [1] : zram: force disksize setting before using zram

    Acked-by: Jerome Marchand <jmarchan@redhat.com>
    Acked-by: Nitin Gupta <ngupta@vflare.org>
    Signed-off-by: Minchan Kim <minchan@kernel.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit 152bce6bdd6e6866ff83166ac75177d001c4360d
Author: Minchan Kim <minchan@kernel.org>
Date:   Wed Feb 6 08:45:22 2013 +0900

    zram: fix warning of print format

    kbuild bot whinges due to print format mistmatch caused by
    zram: force disksize setting before using zram.

    This patch fixes it.

    Reported-by: Wu Fengguang <fengguang.wu@intel.com>
    Signed-off-by: Minchan Kim <minchan@kernel.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit 3de738cd30306f754ea35d35b5dad29fdbec84c9
Author: Minchan Kim <minchan@kernel.org>
Date:   Wed Jan 30 11:41:41 2013 +0900

    zram: give up lazy initialization of zram metadata

    1) User of zram normally do mkfs.xxx or mkswap before using
       the zram block device(ex, normally, do it at booting time)
       It ends up allocating such metadata of zram before real usage so
       benefit of lazy initialzation would be mitigated.

    2) Some user want to use zram when memory pressure is high.(ie, load zram
       dynamically, NOT booting time). It does make sense because people don't
       want to waste memory until memory pressure is high(ie, where zram is really
       helpful time). In this case, lazy initialzation could be failed easily
       because we will use GFP_NOIO instead of GFP_KERNEL for avoiding deadlock.
       So the benefit of lazy initialzation would be mitigated, too.

    3) Metadata overhead is not critical and Nitin has a plan to diet it.
       4K : 12 byte(64bit machine) -> 64G : 192M so 0.3% isn't big overhead
       If insane user use such big zram device up to 20, it could consume 6% of ram
       but efficieny of zram will cover the waste.

    So this patch gives up lazy initialization and instead we initialize metadata
    at disksize setting time.

    Acked-by: Jerome Marchand <jmarchand@redhat.com>
    Acked-by: Nitin Gupta <ngupta@vflare.org>
    Signed-off-by: Minchan Kim <minchan@kernel.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit 0231c403bb065307493fe997ad170487b4d55eb8
Author: Minchan Kim <minchan@kernel.org>
Date:   Wed Jan 30 11:41:40 2013 +0900

    zram: force disksize setting before using zram

    Now zram document syas "set disksize is optional"
    but partly it's wrong. When you try to use zram firstly after
    booting, you must set disksize, otherwise zram can't work because
    zram gendisk's size is 0. But once you do it, you can use zram freely
    after reset because reset doesn't reset to zero paradoxically.
    So in this time, disksize setting is optional.:(
    It's inconsitent for user behavior and not straightforward.

    This patch forces always setting disksize firstly before using zram.
    Yes. It changes current behavior so someone could complain when
    he upgrades zram. Apparently it could be a problem if zram is mainline
    but it still lives in staging so behavior could be changed for right
    way to go. Let them excuse.

    Acked-by: Jerome Marchand <jmarchand@redhat.com>
    Acked-by: Nitin Gupta <ngupta@vflare.org>
    Acked-by: Dan Magenheimer <dan.magenheimer@oracle.com>
    Signed-off-by: Minchan Kim <minchan@kernel.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit 7e5a5104c6af709a8d97d5f4711e7c917761d464
Author: Minchan Kim <minchan@kernel.org>
Date:   Wed Jan 30 11:41:39 2013 +0900

    zram: Fix deadlock bug in partial read/write

    Now zram allocates new page with GFP_KERNEL in zram I/O path
    if IO is partial. Unfortunately, It may cause deadlock with
    reclaim path like below.

    write_page from fs
    fs_lock
    allocation(GFP_KERNEL)
    reclaim
    pageout
    				write_page from fs
    				fs_lock <-- deadlock

    This patch fixes it by using GFP_NOIO.  In read path, we
    reorganize code flow so that kmap_atomic is called after the
    GFP_NOIO allocation.

    Cc: stable@vger.kernel.org
    Acked-by: Jerome Marchand <jmarchand@redhat.com>
    Acked-by: Nitin Gupta <ngupta@vflare.org>
    [ penberg@kernel.org: don't use GFP_ATOMIC ]
    Signed-off-by: Pekka Enberg <penberg@kernel.org>
    Signed-off-by: Minchan Kim <minchan@kernel.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit 0d145a501778042d0411c843ed5b468b41f8a171
Author: Seth Jennings <sjenning@linux.vnet.ibm.com>
Date:   Wed Jan 30 09:36:52 2013 -0600

    staging: zsmalloc: remove unused pool name

    zs_create_pool() currently takes a name argument which is
    never used in any useful way.

    This patch removes it.

    Signed-off-by: Seth Jennings <sjenning@linux.vnet.ibm.com>
    Acked-by: Nitin Gupta <ngupta@vflare.org>
    Acked-by: Rik van Riel <riel@redhat.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit 8f5f90a872c38b4e78f3cc95e8a25434b98e4db2
Merge: c0cd2da 949db15
Author: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Date:   Fri Jan 25 21:25:02 2013 -0800

    Merge 3.8-rc5 into staging-next

    This resolves a merge issue with a iio driver, and the zram code.

    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit d178a07c4bd380492b6aca9e5d3985c19ca88fdb
Author: Davidlohr Bueso <davidlohr.bueso@hp.com>
Date:   Tue Jan 1 21:24:29 2013 -0800

    staging: zram: drop zram_stat_dec/inc functions

    It seems like an overkill to have adding and subtracting
    1 functions from the 32bit counters. Just do it directly.

    Signed-off-by: Davidlohr Bueso <davidlohr.bueso@hp.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit cad683fb9d53fa2cbcf82660e663fa1180f86797
Author: Davidlohr Bueso <davidlohr.bueso@hp.com>
Date:   Tue Jan 1 21:24:22 2013 -0800

    staging: zram: show correct disksize

    The ->disksize variable stores values in units of bytes,
    print the correct size in Kb

    Signed-off-by: Davidlohr Bueso <davidlohr.bueso@hp.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit ca3d70bd68455133eabcb8a0ae1b40254d87188b
Author: Davidlohr Bueso <davidlohr.bueso@hp.com>
Date:   Tue Jan 1 21:24:13 2013 -0800

    staging: zram: simplify num_devices paramater

    Simplify dealing with num_devices when initializing zram.
    Also cleanup some of the output messages.

    Signed-off-by: Davidlohr Bueso <davidlohr.bueso@hp.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit 397c60668aa5ae7130b5ad4e73870d7b8a787085
Author: Nitin Gupta <ngupta@vflare.org>
Date:   Wed Jan 2 08:53:41 2013 -0800

    staging: zram: fix invalid memory references during disk write

    Fixes a bug introduced by commit c8f2f0db1 ("zram: Fix handling
    of incompressible pages") which caused invalid memory references
    during disk write. Invalid references could occur in two cases:
     - Incoming data expands on compression: In this case, reference was
    made to kunmap()'ed bio page.
     - Partial (non PAGE_SIZE) write with incompressible data: In this
    case, reference was made to a kfree()'ed buffer.

    Fixes bug 50081:
    https://bugzilla.kernel.org/show_bug.cgi?id=50081

    Signed-off-by: Nitin Gupta <ngupta@vflare.org>
    Cc: stable <stable@vger.kernel.org>
    Reported-by: Mihail Kasadjikov <hamer.mk@gmail.com>
    Reported-by: Tomas M <tomas@slax.org>
    Reviewed-by: Minchan Kim <minchan@kernel.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit dbc320f7490933eb6a073d82aceac75d5e7ce82b
Author: Masanari Iida <standby24x7@gmail.com>
Date:   Mon Jan 7 23:28:10 2013 +0900

    staging: Add angle bracket before and after the URL

    Add missing angle bracket before and after the URL.

    Signed-off-by: Masanari Iida <standby24x7@gmail.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit 26907840e63b3187266db1865e76ea9e98b01b19
Author: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Date:   Tue Oct 30 22:42:31 2012 +0300

    staging: zram: handle mem suffixes in disk size zram_sysfs parameter

    Use memparse() to allow mem suffixes in disksize sysfs number.
    Examples:
        echo 256K > /sys/block/zram0/disksize
        echo 512M > /sys/block/zram0/disksize
        echo 1G > /sys/block/zram0/disksize

    Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
    Reviewed-by: Nitin Gupta <ngupta@vflare.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit 37b51fdddf64e7ba0971d070428655f8d6f36578
Author: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Date:   Tue Oct 30 22:40:23 2012 +0300

    staging: zram: factor-out zram_decompress_page() function

    zram_bvec_read() shared decompress functionality with zram_read_before_write() function.
    Factor-out and make commonly used zram_decompress_page() function, which also simplified
    error handling in zram_bvec_read().

    Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
    Reviewed-by: Nitin Gupta <ngupta@vflare.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit cb1f6268acd7f1bca7153fa9ca187ffb73f60ab8
Merge: d9ff393 8f0d816
Author: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Date:   Mon Oct 29 08:37:12 2012 -0700

    Merge 3.7-rc3 into staging-next

    This resolves the conflict with:
    	drivers/staging/comedi/drivers/amplc_dio200.c
    and syncs up the changes that happened in the staging directory for
    3.7-rc3.

    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit c8f2f0db1d0294aaf37e8a85bea9bbc4aaf5c0fe
Author: Nitin Gupta <ngupta@vflare.org>
Date:   Wed Oct 10 17:42:18 2012 -0700

    staging: zram: Fix handling of incompressible pages

    Change 130f315a (staging: zram: remove special handle of uncompressed page)
    introduced a bug in the handling of incompressible pages which resulted in
    memory allocation failure for such pages.

    When a page expands on compression, say from 4K to 4K+30, we were trying to
    do zsmalloc(pool, 4K+30). However, the maximum size which zsmalloc can
    allocate is PAGE_SIZE (for obvious reasons), so such allocation requests
    always return failure (0).

    For a page that has compressed size larger than the original size (this may
    happen with already compressed or random data), there is no point storing
    the compressed version as that would take more space and would also require
    time for decompression when needed again. So, the fix is to store any page,
    whose compressed size exceeds a threshold (max_zpage_size), as-it-is i.e.
    without compression.  Memory required for storing this uncompressed page can
    then be requested from zsmalloc which supports PAGE_SIZE sized allocations.

    Lastly, the fix checks that we do not attempt to "decompress" the page which
    we stored in the uncompressed form -- we just memcpy() out such pages.

    Signed-off-by: Nitin Gupta <ngupta@vflare.org>
    Reported-by: viechweg@gmail.com
    Reported-by: paerley@gmail.com
    Reported-by: wu.tommy@gmail.com
    Acked-by: Minchan Kim <minchan@kernel.org>
    Cc: stable <stable@vger.kernel.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit 55dcbbb1bf7eef83bcd3e0ba8de0b359a45804ed
Author: Minchan Kim <minchan@kernel.org>
Date:   Wed Oct 10 08:49:52 2012 +0900

    staging: zram: correct obsolete comment on max_zpage_size

    Zram doesn't use xv_malloc any more so it doesn't have
    limitation about zobj_header.

    Signed-off-by: Minchan Kim <minchan@kernel.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit b74185108668ef966e663878adbad65e03bfcb43
Author: Seth Jennings <sjenning@linux.vnet.ibm.com>
Date:   Mon Jul 2 16:15:52 2012 -0500

    staging: zsmalloc: add mapping modes

    This patch improves mapping performance in zsmalloc by getting
    usage information from the user in the form of a "mapping mode"
    and using it to avoid unnecessary copying for objects that span
    pages.

    Signed-off-by: Seth Jennings <sjenning@linux.vnet.ibm.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit 6e2361720b9da9ec830d407da058ca1827e62b12
Author: Seth Jennings <sjenning@linux.vnet.ibm.com>
Date:   Mon Jun 25 11:14:36 2012 -0500

    staging: zram/zcache: swtich Kconfig dependency from X86 to ZSMALLOC

    This patch switches zcache and zram dependency to ZSMALLOC
    rather than X86.  There is no net change since ZSMALLOC
    depends on X86, however, this prevent further changes to
    these files as zsmalloc dependencies change.

    Signed-off-by: Seth Jennings <sjenning@linux.vnet.ibm.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit 80677c2538283678c7b2ef7ebbd653a3fa54d086
Author: Sam Hansen <solid.se7en@gmail.com>
Date:   Thu Jun 7 16:03:48 2012 -0700

    staging: zram: conventions, __aligned() attribute

    Using the __aligned() attribute in favor of __attribute__((aligned(size)))

    Signed-off-by: Sam Hansen <solid.se7en@gmail.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit 94b8435ff4d46dde75173da45564b0d65889dc64
Author: Sam Hansen <solid.se7en@gmail.com>
Date:   Thu Jun 7 16:03:47 2012 -0700

    staging: zram: conventions pr_warning -> pr_warn()

    Porting zram to use the pr_warn() function instead of the deprecated
    pr_warning().

    Signed-off-by: Sam Hansen <solid.se7en@gmail.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit 130f315a174d127cbb90d4d1a4a7088dbcf930b5
Author: Minchan Kim <minchan@kernel.org>
Date:   Fri Jun 8 15:39:27 2012 +0900

    staging: zram: remove special handle of uncompressed page

    xvmalloc can't handle PAGE_SIZE page so that zram have to
    handle it specially but zsmalloc can do it so let's remove
    unnecessary special handling code.

    Quote from Nitin
    "I think page vs handle distinction was added since xvmalloc could not
    handle full page allocation. Now that zsmalloc allows full page
    allocation, we can just use it for both cases. This would also allow
    removing the ZRAM_UNCOMPRESSED flag. The only downside will be slightly
    slower code path for full page allocation but this event is anyways
    supposed to be rare, so should be fine."

    1. This patch reduces code very much.

     drivers/staging/zram/zram_drv.c   |  104 +++++--------------------------------
     drivers/staging/zram/zram_drv.h   |   17 +-----
     drivers/staging/zram/zram_sysfs.c |    6 +--
     3 files changed, 15 insertions(+), 112 deletions(-)

    2. change pages_expand with bad_compress so it can count
       bad compression(above 75%) ratio.

    3. remove zobj_header which is for back-reference for defragmentation
       because firstly, it's not used at the moment and zsmalloc can't handle
       bigger size than PAGE_SIZE so zram can't do it any more without redesign.

    Cc: Seth Jennings <sjenning@linux.vnet.ibm.com>
    Signed-off-by: Minchan Kim <minchan@kernel.org>
    Acked-by: Nitin Gupta <ngupta@vflare.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit 374a69191d12a0525b7ffe1197abc30c4795a230
Author: Minchan Kim <minchan@kernel.org>
Date:   Fri Jun 8 15:39:26 2012 +0900

    staging: zram: fix random data read

    fd1a30de makes a bug that it uses (struct page *) as zsmalloc's handle
    although it's a uncompressed page so that it can access random page,
    return random data or even crashed by get_first_page in zs_map_object.

    Cc: Seth Jennings <sjenning@linux.vnet.ibm.com>
    Cc: Jerome Marchand <jmarchan@redhat.com>
    Signed-off-by: Minchan Kim <minchan@kernel.org>
    Acked-by: Nitin Gupta <ngupta@vflare.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit c234434835b1f4bad9bdbae6710044cba387c9e5
Author: Minchan Kim <minchan@kernel.org>
Date:   Fri Jun 8 15:39:25 2012 +0900

    staging: zsmalloc: zsmalloc: use unsigned long instead of void *

    We should use unsigned long as handle instead of void * to avoid any
    confusion. Without this, users may just treat zs_malloc return value as
    a pointer and try to deference it.

    This patch passed compile test(zram, zcache and ramster) and zram is
    tested on qemu.

    changelog
      * from v2
    	- remove hval pointed out by Nitin
    	- based on next-20120607
      * from v1
    	- change zcache's zv_create return value
    	- baesd on next-20120604

    Cc: Dan Magenheimer <dan.magenheimer@oracle.com>
    Acked-by: Seth Jennings <sjenning@linux.vnet.ibm.com>
    Acked-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
    Signed-off-by: Minchan Kim <minchan@kernel.org>
    Acked-by: Nitin Gupta <ngupta@vflare.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Change-Id: I5157794e120bbae7ba1e5d0f122dae4fba4a079b
Signed-off-by: Larry Bassel <lbassel@codeaurora.org>

Staging: Fixes string split across lines in zram

Fixes the following checkpatch warning in zram_drv.c:
WARNING: quoted string split across lines

Change-Id: Ie74672146a958c2636052f20a6340f67f2641cde
Signed-off-by: Marlies Ruck <marlies.ruck@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Git-commit: 596b3dd4c8e172db7806372c9d0347a4e7d28bc5
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>

zram: avoid invalid memory access in zram_exit()

Memory for zram->disk object may have already been freed after returning
from destroy_device(zram), then it's unsafe for zram_reset_device(zram)
to access zram->disk again.

We can't solve this bug by flipping the order of destroy_device(zram)
and zram_reset_device(zram), that will cause deadlock issues to the
zram sysfs handler.

So fix it by holding an extra reference to zram->disk before calling
destroy_device(zram).

Change-Id: I1022247325ab2ec31a094587e13d5c4c759e5a36
Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
Cc: stable@vger.kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Git-commit: 6030ea9b35971a4200062f010341ab832e878ac9
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>

zram: use zram->lock to protect zram_free_page() in swap free notify path

zram_slot_free_notify() is free-running without any protection from
concurrent operations. So there are race conditions between
zram_bvec_read()/zram_bvec_write() and zram_slot_free_notify(),
and possible consequences include:
1) Trigger BUG_ON(!handle) on zram_bvec_write() side.
2) Access to freed pages on zram_bvec_read() side.
3) Break some fields (bad_compress, good_compress, pages_stored)
   in zram->stats if the swap layer makes concurrently call to
   zram_slot_free_notify().

So enhance zram_slot_free_notify() to acquire writer lock on zram->lock
before calling zram_free_page().

Change-Id: I805806668d91aaf4c8be7359cb1fd9c877c41f72
Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
Cc: stable@vger.kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Git-commit: 57ab048532c0d975538cebd4456491b5c34248f4
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>

zram: destroy all devices on error recovery path in zram_init()

On error recovery path of zram_init(), it leaks the zram device object
causing the failure. So change create_device() to free allocated
resources on error path.

Change-Id: Ia8508ab9aad3201c6fc12634b8e134d78d7d1423
Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
Acked-by: Minchan Kim <minchan@kernel.org>
Acked-by: Jerome Marchand <jmarchan@redhat.com>
Cc: stable@vger.kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Git-commit: 39a9b8ac9333e4268ecff7da6c9d1ab3823ff243
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>

zram: avoid double free in function zram_bvec_write()

When doing a patial write and the whole page is filled with zero,
zram_bvec_write() will free uncmem twice.

Change-Id: I233f44846f29dbf11e05d277506137bc7f11bbd9
Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
Acked-by: Minchan Kim <minchan@kernel.org>
Cc: stable@vger.kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Git-commit: 65c484609a3b25c35e4edcd5f2c38f98f5226093
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>

zram: avoid access beyond the zram device

Function valid_io_request() should verify the entire request are within
the zram device address range. Otherwise it may cause invalid memory
access when accessing/modifying zram->meta->table[index] because the
'index' is out of range. Then it may access non-exist memory, randomly
modify memory belong to other subsystems, which is hard to track down.

Change-Id: Ic6630e8ed5945b7c0f4f63ccc378f9780dfc4567
Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
Cc: stable@vger.kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Git-commit: 12a7ad3b810e77137d0caf97a6dd97591e075b30
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>

zram: kill unused zram_get_num_devices()

Now there's no caller of zram_get_num_devices(), so kill it.
And change zram_devices to static because it's only used in zram_drv.c.

Change-Id: Iaf686cf9ae9673325ba481f001df689cedfa2c66
Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Git-commit: 0f0e3ba346c8d8d2cb409b157df79805931a1c2c
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>

zram: optimize memory operations with clear_page()/copy_page()

Some architectures provides architecture-specific, optimized version of
clear_page()/copy_page(), which may have better performance than
memset()/memcpy(). So use clear_page()/copy_page() to optimize zram
performance if possible.

Change-Id: I6b4530f16d45d0005ff498f48b03f727e73044cb
Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Git-commit: 42e99bd975fdd24d2bf1a24ebb8b0b42bab8ba65
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>

zram: protect sysfs handler from invalid memory access

Use zram->init_lock to protect access to zram->meta, otherwise it
may cause invalid memory access if zram->meta has been freed by
zram_reset_device().

This issue may be triggered by:
Thread 1:
while true; do cat mem_used_total; done
Thread 2:
while true; do echo 8M > disksize; echo 1 > reset; done

Change-Id: Id6105b37f083cfd41d9885a251aeef61f72bb92f
Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
Acked-by: Minchan Kim <minchan@kernel.org>
Cc: stable@vger.kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Git-commit: 5863e10b441e7ea4b492f930f1be180a97d026f3
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>

zram: simplify and optimize dev_to_zram()

Simplify and optimize dev_to_zram() without walking the zram_devices
array.

Change-Id: I7d2031baabfd880ee8479abf3657358cd7db57cb
Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Git-commit: 80de574dca050b734d8413a98a983fba3d06240b
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>

zram: use atomic64_xxx() to replace zram_stat64_xxx()

Use atomic64_xxx() to replace open-coded zram_stat64_xxx().
Some architectures have native support of atomic64 operations,
so we can get rid of the spin_lock() in zram_stat64_xxx().
On the other hand, for platforms use generic version of atomic64
implement, it may cause an extra save/restore of the interrupt
flag.  So it's a tradeoff.

Change-Id: Ic1e5f79328b998ec2d0b571851199dfd2d5560a6
Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Git-commit: da5cc7d338f97886ebf35be92995460289379b73
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>

zram: remove zram_sysfs file (v2)

Move zram sysfs code to zram drv and remove zram_sysfs.c
file. This gives ability to make static a number of previously
exported zram functions, used from zram sysfs, e.g. internal zram
zram_meta_alloc/free(). We also can drop zram_drv wrapper
functions, used from zram sysfs:
e.g. zram_reset_device()/__zram_reset_device() pair.

v2: as suggested by Greg K-H, move MODULE description to the
bottom of the file.

Change-Id: I2338b812daa1fef0ec7015082ecccb8ec6c84b8f
Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Git-commit: 9b3bb7abcdf2df0f1b2657e6cbc9d06bc2b3b36f
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>

zram: allow request end to coincide with disksize

Pass valid_io_request() checks if request end coincides with disksize
(end equals bound), only fail if we attempt to read beyond the bound.

mkfs.ext2 produces numerous errors:
[ 2164.632747] quiet_error: 1 callbacks suppressed
[ 2164.633260] Buffer I/O error on device zram0, logical block 153599
[ 2164.633265] lost page write due to I/O error on zram0

Change-Id: I71f9f52ec11897d0462d3ff54a853040faf36dcd
Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Git-commit: 75c7caf5a052ffd8db3312fa7864ee2d142890c4
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>

staging: zram: protect zram_reset_device() call

Commit 9b3bb7abcdf2df0f1b2657e6cbc9d06bc2b3b36f (remove
zram_sysfs file (v2)) accidentally made zram_reset_device()
racy. Protect zram_reset_device() call with zram->lock.

Change-Id: I93ce19f9b262584f4ef805dce5ed4de9b3968a30
Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Acked-by: Jerome Marchand <jmarchand@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Git-commit: 644d478793c6594277f8ae76954da4ace7ac6f96
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>

staging: zram: Add auto loading of module if user opens /dev/zram.

Greg spotted that said driver is not subscribing to the automagic
mechanism of auto-loading if a user tries to open /dev/zram.

This fixes it.

Change-Id: Ib169a11a1a2717967350015d58d77f431ab5b973
CC: Minchan Kim <minchan@kernel.org>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Git-commit: c70bda992c12e593e411c02a52e4bd6985407539
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>

zram: prevent data loss in error cases of function zram_bvec_write()

In function zram_bvec_write(), previous data at the index is
already freed by function zram_free_page().
When failed to compress or zs_malloc, there is no way to restore old data.
Therefore, free previous data when it's about to update.

Also, no need to check whether table is not empty outside of
function zram_free_page(), because the function properly checks inside.

Change-Id: I8cb3daf146a99d3b5999c7a42e5e2a260f4c3a48
Signed-off-by: Sunghan Suh <sunghan.suh@samsung.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Git-commit: f40ac2ae1b506484dd9261a24bbf3e86b2206ff8
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>

Staging: zram: zram_drv.c: Fixed Error of trailing whitespace

Fixed by removing trailing whitespace

Change-Id: If43b8acf92d4c504c443c8e4c7995de3e410aca0
Signed-off-by: Kumar Gaurav <kumargauravgupta3@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Git-commit: a539c72a195c081d950475c2945cb82d80be9b66
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>

zram: fix invalid memory access

[1] tried to fix invalid memory access on zram->disk but it didn't
fix properly because get_disk failed during module exit path.

Actually, we don't need to reset zram->disk's capacity to zero
in module exit path so that this patch introduces new argument
"reset_capacity" on zram_reset_divice and it only reset it when
reset_store is called.

[1] 6030ea9b,  zram: avoid invalid memory access in zram_exit()

Change-Id: I6616ac8f82aab6d03a47f3cfb91d28a825e6e3a6
Cc: Nitin Gupta <ngupta@vflare.org>
Cc: Jiang Liu <jiang.liu@huawei.com>
Cc: stable@vger.kernel.org
Signed-off-by: Minchan Kim <minchan@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Git-commit: 2b86ab9cc29fcd435cde9378c3b9ffe8b5c76128
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>

zram: don't grab mutex in zram_slot_free_noity

[1] introduced down_write in zram_slot_free_notify to prevent race
between zram_slot_free_notify and zram_bvec_[read|write]. The race
could happen if somebody who has right permission to open swap device
is reading swap device while it is used by swap in parallel.

However, zram_slot_free_notify is called with holding spin_lock of
swap layer so we shouldn't avoid holing mutex. Otherwise, lockdep
warns it.

This patch adds new list to handle free slot and workqueue
so zram_slot_free_notify just registers slot index to be freed and
registers the request to workqueue. If workqueue is expired,
it holds mutex_lock so there is no problem any more.

If any I/O is issued, zram handles pending slot-free request
caused by zram_slot_free_notify right before handling issued
request because workqueue wouldn't be expired yet so zram I/O
request handling function can miss it.

Lastly, when zram is reset, flush_work could handle all of pending
free request so we shouldn't have memory leak.

NOTE: If zram_slot_free_notify's kmalloc with GFP_ATOMIC would be
failed, the slot will be freed when next write I/O write the slot.

[1] [57ab0485, zram: use zram->lock to protect zram_free_page()
    in swap free notify path]

* from v2
  * refactoring

* from v1
  * totally redesign

Change-Id: Ic69dce098c89bb7cb5563566b802375320b90a76
Cc: Nitin Gupta <ngupta@vflare.org>
Cc: Jiang Liu <jiang.liu@huawei.com>
Cc: stable@vger.kernel.org
Signed-off-by: Minchan Kim <minchan@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Git-commit: a0c516cbfc7452c8cbd564525fef66d9f20b46d1
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>

zram: Disable allocation failure logging

Disable the logging of errors when allocations fail
for zram pages. This avoid excessive logging when system is
very low on memory.

Change-Id: Ifabcf8f1b9c3e3717599d6a0a924f7b2061f00ea
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>

zram: Change ratio to 90% for bad compress

Change the ratio for determining whether or not we should store
pages as uncompressed in zram. This will allow zram to fit more
data since more of the pages will be stored as compressed.

Change-Id: I37170cafff7e8a4cc44f1622fe52a6cbff85f218
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>

staging: zram: Rate limit memory allocation errors

If an error occurs allocating memory for zram we will not be able
to fullfill the request to store the page in zram. The swap subsystem
still continues to try to swap out pages to zram even when this error
occurs since there is currently no facility to stop the swap subsystem
from swapping out during such errors. This can cause the system to be
overflowed with logging errors.

Reduce the amount of logging to prevent the kernel log
from being filled with these error messages.

Change-Id: I54b920337749ece59d9ca78fa8b29345ec7b976b
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
slub: tid must be retrieved from the percpu area of the current processor

As Steven Rostedt has pointer out: rescheduling could occur on a
different processor after the determination of the per cpu pointer and
before the tid is retrieved. This could result in allocation from the
wrong node in slab_alloc().

The effect is much more severe in slab_free() where we could free to the
freelist of the wrong page.

The window for something like that occurring is pretty small but it is
possible.

Change-Id: I9e658e97ed2096f658d6e67739764a86151f13e3
Signed-off-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
Git-commit: 7cccd80b4397699902aced1ad3d692d384aaab77
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Matt Wagantall <mattw@codeaurora.org>
mm: methods for teaching filesystems about PG_swapcache pages

In order to teach filesystems to handle swap cache pages, three new page
functions are introduced:

  pgoff_t page_file_index(struct page *);
  loff_t page_file_offset(struct page *);
  struct address_space *page_file_mapping(struct page *);

page_file_index() - gives the offset of this page in the file in
PAGE_CACHE_SIZE blocks.  Like page->index is for mapped pages, this
function also gives the correct index for PG_swapcache pages.

page_file_offset() - uses page_file_index(), so that it will give the
expected result, even for PG_swapcache pages.

page_file_mapping() - gives the mapping backing the actual page; that is
for swap cache pages it will give swap_file->f_mapping.

Change-Id: I13d18bb25be606760eac26cc842eb7c9fc9e4766
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Signed-off-by: Mel Gorman <mgorman@suse.de>
Reviewed-by: Rik van Riel <riel@redhat.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: David S. Miller <davem@davemloft.net>
Cc: Eric B Munson <emunson@mgebm.net>
Cc: Eric Paris <eparis@redhat.com>
Cc: James Morris <jmorris@namei.org>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Mike Christie <michaelc@cs.wisc.edu>
Cc: Neil Brown <neilb@suse.de>
Cc: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
Cc: Trond Myklebust <Trond.Myklebust@netapp.com>
Cc: Xiaotian Feng <dfeng@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: f981c5950fa85916ba49bea5d9a7a5078f47e569
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
[ohaugan@codeaurora.org: Resolved merge issues]
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
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

Change-Id: Ida7dcf6fbd67408e2429483c28c75f59f83310d3
[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>
Git-commit: b430e9d1c6d416306d44dbf3aa3148be7af78abc
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
[ohaugan@codeaurora.org: Resolved merge issues]
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
swap: add per-partition lock for swapfile

swap_lock is heavily contended when I test swap to 3 fast SSD (even
slightly slower than swap to 2 such SSD).  The main contention comes
from swap_info_get().  This patch tries to fix the gap with adding a new
per-partition lock.

Global data like nr_swapfiles, total_swap_pages, least_priority and
swap_list are still protected by swap_lock.

nr_swap_pages is an atomic now, it can be changed without swap_lock.  In
theory, it's possible get_swap_page() finds no swap pages but actually
there are free swap pages.  But sounds not a big problem.

Accessing partition specific data (like scan_swap_map and so on) is only
protected by swap_info_struct.lock.

Changing swap_info_struct.flags need hold swap_lock and
swap_info_struct.lock, because scan_scan_map() will check it.  read the
flags is ok with either the locks hold.

If both swap_lock and swap_info_struct.lock must be hold, we always hold
the former first to avoid deadlock.

swap_entry_free() can change swap_list.  To delete that code, we add a
new highest_priority_index.  Whenever get_swap_page() is called, we
check it.  If it's valid, we use it.

It's a pity get_swap_page() still holds swap_lock().  But in practice,
swap_lock() isn't heavily contended in my test with this patch (or I can
say there are other much more heavier bottlenecks like TLB flush).  And
BTW, looks get_swap_page() doesn't really need the lock.  We never free
swap_info[] and we check SWAP_WRITEOK flag.  The only risk without the
lock is we could swapout to some low priority swap, but we can quickly
recover after several rounds of swap, so sounds not a big deal to me.
But I'd prefer to fix this if it's a real problem.

"swap: make each swap partition have one address_space" improved the
swapout speed from 1.7G/s to 2G/s.  This patch further improves the
speed to 2.3G/s, so around 15% improvement.  It's a multi-process test,
so TLB flush isn't the biggest bottleneck before the patches.

Change-Id: Ic8d600653479c0e6767f04462c3f057b0fe94332
[arnd@arndb.de: fix it for nommu]
[hughd@google.com: add missing unlock]
[minchan@kernel.org: get rid of lockdep whinge on sys_swapon]
Signed-off-by: Shaohua Li <shli@fusionio.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Rik van Riel <riel@redhat.com>
Cc: Minchan Kim <minchan.kim@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Seth Jennings <sjenning@linux.vnet.ibm.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
Cc: Dan Magenheimer <dan.magenheimer@oracle.com>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Hugh Dickins <hughd@google.com>
Signed-off-by: Minchan Kim <minchan@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: ec8acf20afb8534ed511f6613dd2226b9e301010
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
[lauraa@codeaurora.org: Various context fixups due to backport]
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
mm: vmscan: Move pages that fail swapout to LRU active list

Move pages that fail swapout to the LRU active list to reduce
pressure on swap device when swapping out is already failing.
This helps when using a pseudo swap device such as zram which
starts failing when memory is low.

Change-Id: Ib136cd0a744378aa93d837a24b9143ee818c80b3
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
mm: swap: Rate limit swap write errors

If an error occurs in the swap subsystem when writing pages
out to a swap device the system might get overflowed with
logging errors because the mm subsystem will continously try
to swap out pages even in the event of error on the swap
device.

Reduce the amount of logging to prevent the kernel log
from being filled with these error messages.

Change-Id: Iddaf6c32ae87132817482cc4cb68b909a1c527e6
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
sched: re-calculate a cpu's next_balance point upon sched domain changes

Commit 55ddeb0f (sched: Reset rq->next_interval before going idle) reset
a cpu's rq->next_balance when pulled_task = 0, which will be true when
the cpu failed to pull any task, causing it go idle. However that patch
relied on next_balance being calculated as a result of traversing cpu's
sched domain hierarchy.

A cpu that is the only online cpu will however not be attached to any
sched domain hierarchy. When such a cpu calls into idle_balance(), we
will end up initializing next_balance to be 1sec away! Such a CPU will
defer load balance check for another 1sec, even though we may bring up
more cpus in the meantime requiring it to check for load imbalance more
frequently. This could then lead to increased scheduling latency for
some tasks.

This patch results in a cpu's next_balance being re-calculated when its
attaching to a new sched domain hierarchy.  This should let cpus call
load balance checks at the right time we expect them to!

Change-Id: I855cff8da5ca28d278596c3bb0163b839d4704bc
Signed-off-by: Srivatsa Vaddagiri <vatsa@codeaurora.org>
mm: remove swap token code

The swap token code no longer fits in with the current VM model.  It
does not play well with cgroups or the better NUMA placement code in
development, since we have only one swap token globally.

It also has the potential to mess with scalability of the system, by
increasing the number of non-reclaimable pages on the active and
inactive anon LRU lists.

Last but not least, the swap token code has been broken for a year
without complaints, as reported by Konstantin Khlebnikov.  This suggests
we no longer have much use for it.

The days of sub-1G memory systems with heavy use of swap are over.  If
we ever need thrashing reducing code in the future, we will have to
implement something that does scale.

Change-Id: I6d287cfc3c3206ca24da2de0c1392e5fdfcfabe8
Signed-off-by: Rik van Riel <riel@redhat.com>
Cc: Konstantin Khlebnikov <khlebnikov@openvz.org>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Cc: Mel Gorman <mel@csn.ul.ie>
Cc: Hugh Dickins <hughd@google.com>
Acked-by: Bob Picco <bpicco@meloft.net>
Acked-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: e709ffd6169ccd259eb5874e853303e91e94e829
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
kernel: cgroup: push rcu read locking from css_is_ancestor() to callsite

Library functions should not grab locks when the callsites can do it,
even if the lock nests like the rcu read-side lock does.

Push the rcu_read_lock() from css_is_ancestor() to its single user,
mem_cgroup_same_or_subtree() in preparation for another user that may
already hold the rcu read-side lock.

Change-Id: I0ec7ec0059ed588d8f85bc9be8fdc42ce0ca7f5d
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
Cc: Konstantin Khlebnikov <khlebnikov@openvz.org>
Acked-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Acked-by: Michal Hocko <mhocko@suse.cz>
Acked-by: Li Zefan <lizf@cn.fujitsu.com>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Tejun Heo <tj@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Git-commit: 91c63734f6908425903aed69c04035592f18d398
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
sched: Unthrottle rt runqueues in __disable_runtime()

migrate_tasks() uses _pick_next_task_rt() to get tasks from the
real-time runqueues to be migrated. When rt_rq is throttled
_pick_next_task_rt() won't return anything, in which case
migrate_tasks() can't move all threads over and gets stuck in an
infinite loop.

Instead unthrottle rt runqueues before migrating tasks.

Additionally: move unthrottle_offline_cfs_rqs() to rq_offline_fair()

Change-Id: If8a4a399f1a14b7f4789c1b205dcfadbde555214
Signed-off-by: Peter Boonstoppel <pboonstoppel@nvidia.com>
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Turner <pjt@google.com>
Link: http://lkml.kernel.org/r/5FBF8E85CA34454794F0F7ECBA79798F379D3648B7@HQMAIL04.nvidia.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Git-commit: a4c96ae319b8047f62dedbe1eac79e321c185749
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Syed Rameez Mustafa <rameezmustafa@codeaurora.org>