mm: unify module_alloc code for vmalloc

    Four architectures (arm, mips, sparc, x86) use __vmalloc_area() for
    module_init().  Much of the code is duplicated and can be generalized in a
    globally accessible function, __vmalloc_node_range().

    __vmalloc_node() now calls into __vmalloc_node_range() with a range of
    [VMALLOC_START, VMALLOC_END) for functionally equivalent behavior.

    Each architecture may then use __vmalloc_node_range() directly to remove
    the duplication of code.

    Signed-off-by: David Rientjes <rientjes@google.com>
    Cc: Christoph Lameter <cl@linux.com>
    Cc: Russell King <linux@arm.linux.org.uk>
    Cc: Ralf Baechle <ralf@linux-mips.org>
    Cc: "David S. Miller" <davem@davemloft.net>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: "H. Peter Anvin" <hpa@zytor.com>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
cgroups: add per-thread subsystem callbacks
vm: fix vm_pgoff wrap in stack expansion

    commit a626ca6a656450e9f4df91d0dda238fff23285f4 upstream.

    Commit 982134ba6261 ("mm: avoid wrapping vm_pgoff in mremap()") fixed
    the case of a expanding mapping causing vm_pgoff wrapping when you used
    mremap.  But there was another case where we expand mappings hiding in
    plain sight: the automatic stack expansion.

    This fixes that case too.

    This one also found by Robert Święcki, using his nasty system call
    fuzzer tool.  Good job.

    Reported-and-tested-by: Robert Święcki <robert@swiecki.net>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
vmscan: prevent background aging of anon page in no swap system
writeback: do uninterruptible sleep in balance_dirty_pages()

Using TASK_INTERRUPTIBLE in balance_dirty_pages() seems wrong.  If it's
going to do that then it must break out if signal_pending(), otherwise
it's pretty much guaranteed to degenerate into a busywait loop.  Plus we
*do* want these processes to appear in D state and to contribute to load
average.

So it should be TASK_UNINTERRUPTIBLE.                 -- Andrew Morton

Signed-off-by: Wu Fengguang <fengguang.wu@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
deactivate invalidated pages

Recently, there are reported problem about thrashing.
(http://marc.info/?l=rsync&amp;m=128885034930933&amp;w=2)
It happens by backup workloads(ex, nightly rsync).
That's because the workload makes just use-once pages
and touches pages twice. It promotes the page into
active list so that it results in working set page eviction.

Some app developer want to support POSIX_FADV_NOREUSE.
But other OSes don't support it, either.
(http://marc.info/?l=linux-mm&amp;m=128928979512086&amp;w=2)

By other approach, app developers use POSIX_FADV_DONTNEED.
But it has a problem. If kernel meets page is writing
during invalidate_mapping_pages, it can't work.
It makes for application programmer to use it since they always
have to sync data before calling fadivse(..POSIX_FADV_DONTNEED) to
make sure the pages could be discardable. At last, they can't use
deferred write of kernel so that they could see performance loss.
(http://insights.oetiker.ch/linux/fadvise.html)

In fact, invalidation is very big hint to reclaimer.
It means we don't use the page any more. So let's move
the writing page into inactive list's head if we can't truncate
it right now.

Why I move page to head of lru on this patch, Dirty/Writeback page
would be flushed sooner or later. It can prevent writeout of pageout
which is less effective than flusher's writeout.

Originally, I reused lru_demote of Peter with some change so added
his Signed-off-by.

Reported-by: Ben Gamari <bgamari.foss@gmail.com>
Signed-off-by: Peter Zijlstra <peterz@infradead.org>
Acked-by: Rik van Riel <riel@redhat.com>
Acked-by: Mel Gorman <mel@csn.ul.ie>
Reviewed-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Nick Piggin <npiggin@kernel.dk>
Signed-off-by: Minchan Kim <minchan.kim@gmail.com>
vmscan: move referenced VM_EXEC pages to active list

    In commit 64574746, "vmscan: detect mapped file pages used only once",
    Johannes Weiner, added logic to page_check_reference to cycle again
    used once pages.

    In commit 8cab4754, "vmscan: make mapped executable pages the first
    class citizen", Wu Fengguang, added logic to shrink_active_list which
    protects file-backed VM_EXEC pages by keeping them in the active_list if
    they are referenced.

    This patch adds logic to move such pages from the inactive list to the
    active list immediately if they have been referenced. If a VM_EXEC page
    is seen as referenced during an inactive list scan, that reference must
    have occurred after the page was put on the inactive list. There is no
    need to wait for the page to be referenced again.
mm: Allow compaction without HugeTLB

    Memory compaction can be enabled without enabling
    HUGETLB support.

    Change-Id: I449ee24205f8139dbe0c198b045c5a66917801b2
    Signed-off-by: Brian Steuer <bsteuer@codeaurora.org>
ADD: Frontswap

Conflicts:

	mm/Kconfig
mm: check PageUnevictable in lru_deactivate_fn()

    The lru_deactivate_fn should not move page which in on unevictable lru
    into inactive list.  Otherwise, we can meet BUG when we use
    isolate_lru_pages as __isolate_lru_page could return -EINVAL.

    Reported-by: Ying Han <yinghan@google.com>
    Tested-by: Ying Han <yinghan@google.com>
    Signed-off-by: Minchan Kim <minchan.kim@gmail.com>
    Reviewed-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
    Reviewed-by: Rik van Riel<riel@redhat.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
mm: filter unevictable page out in deactivate_page()

    It's pointless that deactive_page's operates on unevictable pages.  This
    patch removes unnecessary overhead which might be a bit problem in case
    that there are many unevictable page in system(ex, mprotect workload)

    [akpm@linux-foundation.org: tidy up comment]
    Reviewed-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
    Signed-off-by: Minchan Kim <minchan.kim@gmail.com>
    Reviewed-by: Rik van Riel<riel@redhat.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
mm: batch activate_page() to reduce lock contention

    The zone->lru_lock is heavily contented in workload where activate_page()
    is frequently used.  We could do batch activate_page() to reduce the lock
    contention.  The batched pages will be added into zone list when the pool
    is full or page reclaim is trying to drain them.

    For example, in a 4 socket 64 CPU system, create a sparse file and 64
    processes, processes shared map to the file.  Each process read access the
    whole file and then exit.  The process exit will do unmap_vmas() and cause
    a lot of activate_page() call.  In such workload, we saw about 58% total
    time reduction with below patch.  Other workloads with a lot of
    activate_page also benefits a lot too.

    Andrew Morton suggested activate_page() and putback_lru_pages() should
    follow the same path to active pages, but this is hard to implement (see
    commit 7a608572a282a ("Revert "mm: batch activate_page() to reduce lock
    contention")).  On the other hand, do we really need putback_lru_pages()
    to follow the same path?  I tested several FIO/FFSB benchmark (about 20
    scripts for each benchmark) in 3 machines here from 2 sockets to 4
    sockets.  My test doesn't show anything significant with/without below
    patch (there is slight difference but mostly some noise which we found
    even without below patch before).  Below patch basically returns to the
    same as my first post.

    I tested some microbenchmarks:
      case-anon-cow-rand-mt         0.58%
      case-anon-cow-rand           -3.30%
      case-anon-cow-seq-mt         -0.51%
      case-anon-cow-seq            -5.68%
      case-anon-r-rand-mt           0.23%
      case-anon-r-rand              0.81%
      case-anon-r-seq-mt           -0.71%
      case-anon-r-seq              -1.99%
      case-anon-rx-rand-mt          2.11%
      case-anon-rx-seq-mt           3.46%
      case-anon-w-rand-mt          -0.03%
      case-anon-w-rand             -0.50%
      case-anon-w-seq-mt           -1.08%
      case-anon-w-seq              -0.12%
      case-anon-wx-rand-mt         -5.02%
      case-anon-wx-seq-mt          -1.43%
      case-fork                     1.65%
      case-fork-sleep              -0.07%
      case-fork-withmem             1.39%
      case-hugetlb                 -0.59%
      case-lru-file-mmap-read-mt   -0.54%
      case-lru-file-mmap-read       0.61%
      case-lru-file-mmap-read-rand -2.24%
      case-lru-file-readonce       -0.64%
      case-lru-file-readtwice     -11.69%
      case-lru-memcg               -1.35%
      case-mmap-pread-rand-mt       1.88%
      case-mmap-pread-rand        -15.26%
      case-mmap-pread-seq-mt        0.89%
      case-mmap-pread-seq         -69.72%
      case-mmap-xread-rand-mt       0.71%
      case-mmap-xread-seq-mt        0.38%

    The most significent are:
      case-lru-file-readtwice     -11.69%
      case-mmap-pread-rand        -15.26%
      case-mmap-pread-seq         -69.72%

    which use activate_page a lot.  others are basically variations because
    each run has slightly difference.

    In UP case, 'size mm/swap.o'
    before the two patches:
       text    data     bss     dec     hex filename
       6466     896       4    7366    1cc6 mm/swap.o
    after the two patches:
       text    data     bss     dec     hex filename
       6343     896       4    7243    1c4b mm/swap.o

    Signed-off-by: Shaohua Li <shaohua.li@intel.com>
    Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
    Cc: Hiroyuki Kamezawa <kamezawa.hiroyuki@gmail.com>
    Cc: Andi Kleen <andi@firstfloor.org>
    Cc: Minchan Kim <minchan.kim@gmail.com>
    Cc: Rik van Riel <riel@redhat.com>
    Cc: Mel Gorman <mel@csn.ul.ie>
    Cc: Johannes Weiner <hannes@cmpxchg.org>
    Cc: Hugh Dickins <hughd@google.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Conflicts:

	mm/swap.c
cgroups: read-write lock CLONE_THREAD forking per threadgroup
cgroup: remove the ns_cgroup
sched: Rate-limit nohz
mm: enable_swaptoken_only_when_swap_full
incorrect unlikely() and likely() cleanups (Signed-off-by:

Steven Rostedt)
deactivate invalidated pages

Recently, there are reported problem about thrashing.
(http://marc.info/?l=rsync&amp;m=128885034930933&amp;w=2)
It happens by backup workloads(ex, nightly rsync).
That's because the workload makes just use-once pages
and touches pages twice. It promotes the page into
active list so that it results in working set page eviction.

Some app developer want to support POSIX_FADV_NOREUSE.
But other OSes don't support it, either.
(http://marc.info/?l=linux-mm&amp;m=128928979512086&amp;w=2)

By other approach, app developers use POSIX_FADV_DONTNEED.
But it has a problem. If kernel meets page is writing
during invalidate_mapping_pages, it can't work.
It makes for application programmer to use it since they always
have to sync data before calling fadivse(..POSIX_FADV_DONTNEED) to
make sure the pages could be discardable. At last, they can't use
deferred write of kernel so that they could see performance loss.
(http://insights.oetiker.ch/linux/fadvise.html)

In fact, invalidation is very big hint to reclaimer.
It means we don't use the page any more. So let's move
the writing page into inactive list's head if we can't truncate
it right now.

Why I move page to head of lru on this patch, Dirty/Writeback page
would be flushed sooner or later. It can prevent writeout of pageout
which is less effective than flusher's writeout.

Originally, I reused lru_demote of Peter with some change so added
his Signed-off-by.

Reported-by: Ben Gamari <bgamari.foss@gmail.com>
Signed-off-by: Peter Zijlstra <peterz@infradead.org>
Acked-by: Rik van Riel <riel@redhat.com>
Acked-by: Mel Gorman <mel@csn.ul.ie>
Reviewed-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Nick Piggin <npiggin@kernel.dk>
Signed-off-by: Minchan Kim <minchan.kim@gmail.com>

Conflicts:

	mm/swap.c