CHROMIUM: mm: Fix calculation of dirtyable memory

The system uses global_dirtyable_memory() to calculate
number of dirtyable pages/pages that can be allocated
to the page cache.  A bug causes an underflow thus making
the page count look like a big unsigned number.  This in turn
confuses the dirty writeback throttling to aggressively write
back pages as they become dirty (usually 1 page at a time).

Fix is to ensure there is no underflow while doing the math.

Signed-off-by: Sonny Rao <sonnyrao@chromium.org>
Signed-off-by: Puneet Kumar <puneetster@chromium.org>

BUG=chrome-os-partner:16011
TEST=Manual; boot kernel, powerwash, login with testaccount and
make sure no jank occurs on sync of applications

Change-Id: I614e7c3156e014f0f28a4ef9bdd8cb8a2cd07b2a
Reviewed-on: https://gerrit.chromium.org/gerrit/37612
Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Olof Johansson <olofj@chromium.org>
Commit-Ready: Puneet Kumar <puneetster@chromium.org>
Reviewed-by: Puneet Kumar <puneetster@chromium.org>
Tested-by: Puneet Kumar <puneetster@chromium.org>
CHROMIUM: zram: fix 32-bit overflow

The 64-bit division operator is not available in 32-bit kernels,
so have to use do_div.

BUG=chromium:245703
TEST=compiled

Change-Id: I44ab763ea9e115cef6212f6524518cf7d9eac8c7
Signed-off-by: Luigi Semenzato <semenzato@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/64695
Reviewed-by: Doug Anderson <dianders@chromium.org>
CHROMIUM: zram: finish fixing 32-bit overflow

Nasty bug.  PAGE_MASK is unsigned, so it extends to 64 bit with zeros.
The first read in the zram block device is done by mkswap, which
tries to read at the end of device.  zram_set_disksize is a side
effect of the first read, so the disk size is now silently changed
from 6GB to 2GB.  The read fails, but mkswap does not complain either:
it finds the size of the device by trial and error and continues.
Swapon detects the mismatch and fails.

BUG=chromium:245703
TEST=ran before and after change with various printks
Signed-off-by: Luigi Semenzato <semenzato@chromium.org>

Change-Id: I01750554964756c2759375df1f14d7bb8b859ccf
Reviewed-on: https://gerrit.chromium.org/gerrit/65752
Tested-by: Luigi Semenzato <semenzato@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Commit-Queue: Luigi Semenzato <semenzato@chromium.org>
CHROMIUM: BACKPORT: lib/lzo: Update LZO compression to current upstream version

This commit updates the kernel LZO code to the current upsteam version
which features a significant speed improvement - benchmarking the Calgary
and Silesia test corpora typically shows a doubled performance in
both compression and decompression on modern i386/x86_64/powerpc machines.

Signed-off-by: Markus F.X.J. Oberhumer <markus@oberhumer.com>
(cherry picked from commit 8b975bd3f9089f8ee5d7bbfd798537b992bbc7e7)
Signed-off-by: Stephen Barber <smbarber@chromium.org>

BUG=chromium:269723
TEST=Boot and verify that read/write performance has improved by dd'ing
to /dev/zram0. Verify that checksum of decompressed data matches
original data.

Backported from Linux 3.9.

Change-Id: Iea48a73a45c38d4d78d140ed5efc3fcf60d07ca1
Reviewed-on: https://gerrit.chromium.org/gerrit/64995
Reviewed-by: Olof Johansson <olofj@chromium.org>
Commit-Queue: Stephen Barber <smbarber@chromium.org>
Tested-by: Stephen Barber <smbarber@chromium.org>
CHROMIUM: BACKPORT: lib/lzo: huge LZO decompression speedup on ARM by using unaligned access

Signed-off-by: Markus F.X.J. Oberhumer <markus@oberhumer.com>
(cherry picked from commit 42b775abafafdf811ef300e869a4e1480ef1cf95)
Signed-off-by: Stephen Barber <smbarber@chromium.org>

BUG=chromium:269723
TEST=Boot and verify that read/write performance has improved by dd'ing
to /dev/zram0. Verify that checksum of decompressed data matches
original data.

Backported from linux-next (next-20130806).

Change-Id: I382e112b35fbb62439b53c23534c753b14ceb1ff
Reviewed-on: https://gerrit.chromium.org/gerrit/64996
Reviewed-by: Olof Johansson <olofj@chromium.org>
Commit-Queue: Stephen Barber <smbarber@chromium.org>
Tested-by: Stephen Barber <smbarber@chromium.org>