Commit graph

718,528 commits

Message SHA1
ANDROID: Incremental fs: Use 64-bit int for file_size when writing hash blocks
Bug: 153210803
Test: manual
Change-Id: Iafc888dbe906cd37e5b28dc2814f52aace175c0f
Signed-off-by: Yurii Zubrytskyi <zyy@google.com>
Signed-off-by: Sorayukii <sorayukii69@gmail.com>

Yurii Zubrytskyi   authored and   Sorayukii   commited 2026-05-15 18:07:13 +07:00
9a8b1c23cb
Revert "ANDROID: Incremental fs: Fix initialization, use of bitfields"
This change was never cherry-picked to other branches,
is just syntactic sugar, and clashes with another change. Revert,
and then apply cleanly over all branches as needed.

This reverts commit 2664a43d88d91eb09f212cb26e111656a4acee49.

Change-Id: I51dca9cb046cc15302c22e8f73e58dcf4849f84d
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Signed-off-by: Sorayukii <sorayukii69@gmail.com>

Paul Lawrence   authored and   Sorayukii   commited 2026-05-15 18:07:13 +07:00
5c41473323
ANDROID: Incremental fs: Fix remount
Bug: 153017385
Test: incfs_test passes
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: I13f3a3c91d746d725e0e21b1e2bcfe0a64a13716
Signed-off-by: Sorayukii <sorayukii69@gmail.com>

Paul Lawrence   authored and   Sorayukii   commited 2026-05-15 18:07:13 +07:00
eec8582273
ANDROID: Incremental fs: Protect get_fill_block, and add a field
Since INCFS_IOC_GET_FILLED_BLOCKS potentially leaks information about usage
patterns, and is only useful to someone filling the file, best protect it in
the same way as INCFS_IOC_FILL_BLOCKS.

Add useful field data_block_out as well

Test: incfs_test passes
Bug: 152983639
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: I126a8cf711e56592479093e9aadbfd0e7f700752
Signed-off-by: Sorayukii <sorayukii69@gmail.com>

Paul Lawrence   authored and   Sorayukii   commited 2026-05-15 18:07:13 +07:00
00de619c1a
ANDROID: Incremental fs: Fix crash polling 0 size read_log
When read log is 0 sized, we still need to init the wait queue to avoid
kernel panics if someone does decide to poll on the read log.

Test: Added test for this condition, incfs_test crashes
	With fix, incfs_test doesn't crash
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Bug: 152909243
Change-Id: Ic3250523bb7ddb1839f8e95852c17103e5ffb782
Signed-off-by: Sorayukii <sorayukii69@gmail.com>

Paul Lawrence   authored and   Sorayukii   commited 2026-05-15 18:07:13 +07:00
c21823b3d1
ANDROID: Incremental fs: get_filled_blocks: better index_out
When returning incomplete results index_out has to be usable to
call the function again and resume from the same location. This
means that if the output buffer was too small the function needs
to check for that when encountering the _beginning_ of a next
output range, not the end of it. Otherwise resuming from the
end of the range that didn't fit into the buffer would cause
the call to never return that range

+ Make the backing file header flags update thread safe

Bug: 152691988
Test: libincfs-test, incfs_test passes
Signed-off-by: Yurii Zubrytskyi <zyy@google.com>
Change-Id: I351156beba0b74e1942a39117279d3fcdb5e0c78
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Signed-off-by: Sorayukii <sorayukii69@gmail.com>

Yurii Zubrytskyi   authored and   Sorayukii   commited 2026-05-15 18:07:13 +07:00
7e8bff859f
ANDROID: Incremental fs: Fix four resource bugs
Without these, you can't unmount a volume on which incfs was
mounted and the tests run.

Also incfs_tests would fail sporadically without the fix to
test_inode

Test: Run incfs_test and unmount underlying volume 1000 times
Bug: 152636070
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: I88f11f5d4269c22d9073e5eb671d0c7cc4629f6c
(cherry picked from commit c062bc8e769f0f6e47cc41fb9b7ab30e3e7f2689)
Signed-off-by: Sorayukii <sorayukii69@gmail.com>

Paul Lawrence   authored and   Sorayukii   commited 2026-05-15 18:07:13 +07:00
b89f5eb166
ANDROID: Incremental fs: Add INCFS_IOC_GET_FILLED_BLOCKS
Test: incfs_test passes
Bug: 151240628
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: I66d0ba1911adc5d68ed404585222e6a81a7eb94f
(cherry picked from commit 8d963bb24076b60cb2de0f2d49deaff1d52e8270)
Signed-off-by: Sorayukii <sorayukii69@gmail.com>

Paul Lawrence   authored and   Sorayukii   commited 2026-05-15 18:07:12 +07:00
dd83044b68
ANDROID: Incremental fs: Fix two typos
Test: incfs_test passes
Bug: 151240628
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: I627e683b562329fd57aedc8393e22449ff09ee1f
(cherry picked from commit 06c715e275dc65e720759cfeacb4120289e2a306)
Signed-off-by: Sorayukii <sorayukii69@gmail.com>

Paul Lawrence   authored and   Sorayukii   commited 2026-05-15 18:07:12 +07:00
1374ad247a
ANDROID: Incremental fs: Add INCFS_IOC_PERMIT_FILL
Provide a securable way to open a file for filling

Test: incfs_test passes
Bug: 138149732
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: Ib4b6fd839ad30ce08e31121d19e2c0d7066d302f
Signed-off-by: Sorayukii <sorayukii69@gmail.com>

Paul Lawrence   authored and   Sorayukii   commited 2026-05-15 18:07:12 +07:00
d3a7d1475b
ANDROID: Incremental fs: Remove signature checks from kernel
Test: selftests pass
Bug: 133435829
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: Ia7e69b1b0176202da4b418ea815b370cbdacd5c2
Signed-off-by: Sorayukii <sorayukii69@gmail.com>

Paul Lawrence   authored and   Sorayukii   commited 2026-05-15 18:07:12 +07:00
e90d6e1ba1
ANDROID: Incremental fs: Pad hash blocks
Test: incfs_test passes
Bug: 133435829
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: I4e6fbd0938f00e7e6883ce1a26cbfd38fdcaa9a5
Signed-off-by: Sorayukii <sorayukii69@gmail.com>

Paul Lawrence   authored and   Sorayukii   commited 2026-05-15 18:07:12 +07:00
a56f2c7565
ANDROID: Incremental fs: Make fill block an ioctl
Filling blocks is not equivalent to writing a file, since they are
constrained by the root hash. selinux policy may wish to treat them
differently, for instance.

Test: incfs_test passes
Bug: 138149732
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: Ic369b84b92547b1cfefe422bd881c4e466090aed
Signed-off-by: Sorayukii <sorayukii69@gmail.com>

Paul Lawrence   authored and   Sorayukii   commited 2026-05-15 18:07:12 +07:00
720964e7e5
ANDROID: Incremental fs: Remove all access_ok checks
They provide no value and simply duplicate a check in copy_from/to_user

Test: incfs_test passes
Bug: 138149732
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: Icc6054a2d6a495c9a03cd1507dda1ab8ca0b0dc4
Signed-off-by: Sorayukii <sorayukii69@gmail.com>

Paul Lawrence   authored and   Sorayukii   commited 2026-05-15 18:07:12 +07:00
445e46f2e5
ANDROID: Incremental fs: Support xattrs
To make selinux work, add xattr support. This is a bit clunky -
it seems like it would be better for the log and pending read
functionality to be ioctls rather than this mixture of real
and virtual files.

Bug: 133435829
Change-Id: I56579fabe2ae7efb88f0344553948dc9573299aa
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Signed-off-by: Sorayukii <sorayukii69@gmail.com>

Paul Lawrence   authored and   Sorayukii   commited 2026-05-15 18:07:11 +07:00
a788b72d8a
ANDROID: Incremental fs: Fix initialization, use of bitfields
Test: incfs_test passes
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Bug: 133435829
Change-Id: I824286b77f665d2409c5e88930057a97da82ce82
Signed-off-by: Sorayukii <sorayukii69@gmail.com>

Paul Lawrence   authored and   Sorayukii   commited 2026-05-15 18:07:11 +07:00
13b297a110
ANDROID: Incremental fs: Fix crash on failed lookup
Don't call dput on error code

Change-Id: Ie63645c9ed67fa231829917ae8ca154e049b4921
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Bug: 133435829
Signed-off-by: Sorayukii <sorayukii69@gmail.com>

Paul Lawrence   authored and   Sorayukii   commited 2026-05-15 18:07:11 +07:00
cf1f0c2a32
ANDROID: Incremental fs: Make files writeable
- added chmod() to +0222 to make all backing files and dirs
  writable. vold/system_server have a umask that clears those
  flags, making incfs unusable

Signed-off-by: Yurii Zubrytskyi <zyy@google.com>
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Bug: 133435829
Change-Id: Id9258401570cc2cc7cd5735aace89d379a9b043d
Signed-off-by: Sorayukii <sorayukii69@gmail.com>

Yurii Zubrytskyi   authored and   Sorayukii   commited 2026-05-15 18:07:11 +07:00
0ca877f004
ANDROID: Incremental fs: Remove C++-style comments
Change-Id: I89e1dc6020e596fb36694f8646f78b98f7ad4a7f
Bug: 133435829
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Signed-off-by: Sorayukii <sorayukii69@gmail.com>

Paul Lawrence   authored and   Sorayukii   commited 2026-05-15 18:07:11 +07:00
3a2eb45fca
ANDROID: Incremental fs: Fix sparse errors
Fix all sparse errors in fs/incfs except
fs/incfs/integrity.c:192:9: warning: Variable length array is used

Test: incfs_test passes
Bug: 133435829
Change-Id: I9c2e26e4e1a06a894977f11a3c8559b968dd115e
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Signed-off-by: Sorayukii <sorayukii69@gmail.com>

Paul Lawrence   authored and   Sorayukii   commited 2026-05-15 18:07:11 +07:00
af821d2733
ANDROID: Fixing incremental fs style issues
Removed WARN_ONs
Removed compatibilty code
Fixed tab issue

Bug: 133435829
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: I8a9e9ead48a65fd09c2d01d22f65d9a352f118e2
Signed-off-by: Sorayukii <sorayukii69@gmail.com>

Paul Lawrence   authored and   Sorayukii   commited 2026-05-15 18:07:11 +07:00
7fcde1d83b
ANDROID: Make incfs selftests pass
Fixed incfs_test build errors
Fixed Kconfig errors
Readded .gitignore

Test: With just enabling CONFIG_INCREMENTAL_FS, both defconfig and
cuttlefish_defconfig build and incfs_test runs and passes

Bug: 133435829
Change-Id: Id3247ffcc63a095f66dcedf554017a06c5a9ce4a
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Signed-off-by: Sorayukii <sorayukii69@gmail.com>

Paul Lawrence   authored and   Sorayukii   commited 2026-05-15 18:07:10 +07:00
7c6007d0b1
ANDROID: Initial commit of Incremental FS
Fully working incremental fs filesystem

Signed-off-by: Eugene Zemtsov <ezemtsov@google.com>
Signed-off-by: Paul Lawrence <paullawrence@google.com>

Bug: 133435829
Change-Id: I14741a61ce7891a0f9054e70f026917712cbef78
Signed-off-by: Sorayukii <sorayukii69@gmail.com>

Eugene Zemtsov   authored and   Sorayukii   commited 2026-05-15 18:07:10 +07:00
d5572a7ec1
arm64: configs: tama: Enable to fuse passthrough
Signed-off-by: Sorayukii <sorayukii69@gmail.com>

Sorayukii   commited 2026-05-15 18:07:10 +07:00
7466595346
arm64: configs: tama: Regenerate defconfig
- Drop lz4hc
- Add zstd
- Enable zram dedup

Signed-off-by: Sorayukii <sorayukii69@gmail.com>

Sorayukii   commited 2026-05-15 18:07:10 +07:00
a050b2589b
zram: switch to 64-bit hash for dedup
The original dedup code does not handle collision from the observation
that it practically does not happen.

For additional peace of mind, use a bigger hash size for reducing the
possibility of collision even further.

Signed-off-by: Juhyung Park <qkrwngud825@gmail.com>
Signed-off-by: Marco Zanin <mrczn.bb@gmail.com>
Signed-off-by: snnbyyds <snnbyyds@gmail.com>
Signed-off-by: Sorayukii <sorayukii69@gmail.com>

Juhyung Park   authored and   Sorayukii   commited 2026-05-15 18:07:10 +07:00
df412d7834
zram: use xxhash instead of jhash in dedup
Reference: 59e1a2f4bf83 ("ksm: replace jhash2 with xxhash")

Signed-off-by: Park Ju Hyung <qkrwngud825@gmail.com>
Signed-off-by: Marco Zanin <mrczn.bb@gmail.com>
Signed-off-by: snnbyyds <snnbyyds@gmail.com>
Signed-off-by: Sorayukii <sorayukii69@gmail.com>

Park Ju Hyung   authored and   Sorayukii   commited 2026-05-15 18:07:10 +07:00
72488bd99b
zram: fix idle/writeback string compare
Makoto report a below KASAN error: zram does out-of-bounds read.  Because
strscpy copies from source up to count bytes unconditionally.  It could
cause out-of-bounds read on next object in slab.

To prevent it, use strlcpy which checks source's length automatically.

   BUG: KASAN: slab-out-of-bounds in strscpy+0x68/0x154
   Read of size 8 at addr ffffffc0c3495a00 by task system_server/1314
   ..
   Call trace:
     strscpy+0x68/0x154
     idle_store+0xc4/0x34c
     dev_attr_store+0x50/0x6c
     sysfs_kf_write+0x98/0xb4
     kernfs_fop_write+0x198/0x260
     __vfs_write+0x10c/0x338
     vfs_write+0x114/0x238
     SyS_write+0xc8/0x168
     __sys_trace_return+0x0/0x4

   Allocated by task 1314:
    __kmalloc+0x280/0x318
    kernfs_fop_write+0xac/0x260
    __vfs_write+0x10c/0x338
    vfs_write+0x114/0x238
    SyS_write+0xc8/0x168
    __sys_trace_return+0x0/0x4

   Freed by task 2855:
    kfree+0x138/0x630
    kernfs_put_open_node+0x10c/0x124
    kernfs_fop_release+0xd8/0x114
    __fput+0x130/0x2a4
    ____fput+0x1c/0x28
    task_work_run+0x16c/0x1c8
    do_notify_resume+0x2bc/0x107c
    work_pending+0x8/0x10

   The buggy address belongs to the object at ffffffc0c3495a00
    which belongs to the cache kmalloc-128 of size 128
   The buggy address is located 0 bytes inside of
    128-byte region [ffffffc0c3495a00, ffffffc0c3495a80)
   The buggy address belongs to the page:
   page:ffffffbf030d2500 count:1 mapcount:0 mapping:          (null) index:0x0 compound_mapcount: 0
   flags: 0x4000000000010200(slab|head)
   page dumped because: kasan: bad access detected

   Memory state around the buggy address:
    ffffffc0c3495900: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    ffffffc0c3495980: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
   >ffffffc0c3495a00: 04 fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
                      ^
    ffffffc0c3495a80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
    ffffffc0c3495b00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

Link: http://lkml.kernel.org/r/20190319231911.145968-1-minchan@kernel.org
Cc: <stable@vger.kernel.org>	[5.0]
Signed-off-by: Minchan Kim <minchan@kernel.org>
Reported-by: Makoto Wu <makotowu@google.com>
Reviewed-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Change-Id: I785c262bc2c95a07e826a6244c21e3d85520b525
Signed-off-by: Marco Zanin <mrczn.bb@gmail.com>
Signed-off-by: snnbyyds <snnbyyds@gmail.com>
Signed-off-by: Sorayukii <sorayukii69@gmail.com>

Minchan Kim   authored and   Sorayukii   commited 2026-05-15 18:07:10 +07:00
28b5785992
zram: do not waste zram_table_entry flags bits
zram_table_entry::flags stores object size in the lower bits and zram
pageflags in the upper bits.  However, for some reason, we use 24 lower
bits, while maximum zram object size is PAGE_SIZE, which requires
PAGE_SHIFT bits (up to 16 on arm64).  This wastes 24 - PAGE_SHIFT bits
that we can use for additional zram pageflags instead.

Also add a BUILD_BUG_ON() to alert us should we run out of bits in
zram_table_entry::flags.

Link: https://lkml.kernel.org/r/20220912152744.527438-1-senozhatsky@chromium.org
Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Reviewed-by: Brian Geffon <bgeffon@google.com>
Acked-by: Minchan Kim <minchan@kernel.org>
Cc: Nitin Gupta <ngupta@vflare.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Marco Zanin <mrczn.bb@gmail.com>
Signed-off-by: snnbyyds <snnbyyds@gmail.com>
Signed-off-by: Sorayukii <sorayukii69@gmail.com>

Sergey Senozhatsky   authored and   Sorayukii   commited 2026-05-15 18:07:09 +07:00
57fd76c189
zram: convert to using memset_l
zram was the motivation for creating memset_l().  Minchan Kim sees a 7%
performance improvement on x86 with 100MB of non-zero deduplicatable
data:

        perf stat -r 10 dd if=/dev/zram0 of=/dev/null

vanilla:        0.232050465 seconds time elapsed ( +-  0.51% )
memset_l:	0.217219387 seconds time elapsed ( +-  0.07% )

Link: http://lkml.kernel.org/r/20170720184539.31609-7-willy@infradead.org
Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com>
Tested-by: Minchan Kim <minchan@kernel.org>
Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: "James E.J. Bottomley" <jejb@linux.vnet.ibm.com>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: David Miller <davem@davemloft.net>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Cc: Matt Turner <mattst88@gmail.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Russell King <rmk+kernel@armlinux.org.uk>
Cc: Sam Ravnborg <sam@ravnborg.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Marco Zanin <mrczn.bb@gmail.com>
Signed-off-by: snnbyyds <snnbyyds@gmail.com>
Signed-off-by: Sorayukii <sorayukii69@gmail.com>

Matthew Wilcox   authored and   Sorayukii   commited 2026-05-15 18:07:09 +07:00
7b4d5dcabe
zram: Convert to hotplug state machine
Install the callbacks via the state machine with multi instance support and let
the core invoke the callbacks on the already online CPUs.

[bigeasy: wire up the multi instance stuff]
[B--B: fixed wrong spacing and newlines]
Signed-off-by: Anna-Maria Gleixner <anna-maria@linutronix.de>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
Cc: Minchan Kim <minchan@kernel.org>
Cc: rt@linutronix.de
Cc: Nitin Gupta <ngupta@vflare.org>
Link: http://lkml.kernel.org/r/20161126231350.10321-19-bigeasy@linutronix.de
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Marco Zanin <mrczn.bb@gmail.com>
Signed-off-by: snnbyyds <snnbyyds@gmail.com>
Signed-off-by: Sorayukii <sorayukii69@gmail.com>

Anna-Maria Gleixner   authored and   Sorayukii   commited 2026-05-15 18:07:09 +07:00
50a038d5ce
zram: Fix __zram_bvec_{read,write}() locking order
Mikhail reported a lockdep spat detailing how __zram_bvec_read() and
__zram_bvec_write() use zstrm->lock and zspage->lock in opposite order.

Reported-by: Mikhail Gavrilov <mikhail.v.gavrilov@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Tested-by: Mikhail Gavrilov <mikhail.v.gavrilov@gmail.com>
Acked-by: Minchan Kim <minchan@kernel.org>
Acked-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Marco Zanin <mrczn.bb@gmail.com>
Signed-off-by: snnbyyds <snnbyyds@gmail.com>
Signed-off-by: Sorayukii <sorayukii69@gmail.com>

Peter Zijlstra   authored and   Sorayukii   commited 2026-05-15 18:07:09 +07:00
320cba7b9a
zram: fix race condition while returning zram_entry refcount
With deduplication enabled, the duplicated zram objects are tracked
using the zram_entry backed by a refcount. The race condition while
decrementing the refcount through zram_dedup_put() is as follows:
Say Task A and task B share the same object and thus the
zram_entry->refcount = 2.
Task A				Task B

zram_dedup_put  		zram_dedup_put
				spin_lock(&hash->lock);
				entry->refcount--; (Now it is 1)
				spin_unlock(&hash->lock);
spin_lock(&hash->lock);
entry->refcount--; (Now it is 0)
spin_unlock(&hash->lock);

return entry->refcount		return entry->refcount

We return 0 in above steps thus leading to double free of the handle,
which is a slab object.

Change-Id: I8dd9bad27140a6e3a295905bf4411050d8eac931
Signed-off-by: Charan Teja Reddy <charante@codeaurora.org>
Signed-off-by: Marco Zanin <mrczn.bb@gmail.com>
Signed-off-by: snnbyyds <snnbyyds@gmail.com>
Signed-off-by: Sorayukii <sorayukii69@gmail.com>

Charan Teja Reddy   authored and   Sorayukii   commited 2026-05-15 18:07:09 +07:00
bd5f7c978f
zram: pass down the bvec we need to read into in the work struct
commit e153abc0739ff77bd89c9ba1688cdb963464af97 upstream.

When scheduling work item to read page we need to pass down the proper
bvec struct which points to the page to read into.  Before this patch it
uses a randomly initialized bvec (only if PAGE_SIZE != 4096) which is
wrong.

Note that without this patch on arch/kernel where PAGE_SIZE != 4096
userspace could read random memory through a zram block device (thought
userspace probably would have no control on the address being read).

Link: http://lkml.kernel.org/r/20190408183219.26377-1-jglisse@redhat.com
Signed-off-by: Jérôme Glisse <jglisse@redhat.com>
Reviewed-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Acked-by: Minchan Kim <minchan@kernel.org>
Cc: Nitin Gupta <ngupta@vflare.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Marco Zanin <mrczn.bb@gmail.com>
Signed-off-by: snnbyyds <snnbyyds@gmail.com>
Signed-off-by: Sorayukii <sorayukii69@gmail.com>

JĂ©rĂ´me Glisse   authored and   Sorayukii   commited 2026-05-15 18:07:09 +07:00
82f02bb7c3
zram: compare all the entries with same checksum for deduplication
Until now, we compare just one entry with same checksum when
checking duplication since it is the simplest way to implement.
However, for the completeness, checking all the entries is better
so this patch implement to compare all the entries with same checksum.
Since this event would be rare so there would be no performance loss.

Change-Id: Ie7d61c14d127a28f5a06d85b0ca66b9fada20cbb
Reviewed-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Acked-by: Minchan Kim <minchan@kernel.org>
Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Link: https://lore.kernel.org/patchwork/patch/787163/
Patch-mainline: linux-kernel@ Thu, 11 May 2017 22:30:29
Signed-off-by: Charan Teja Reddy <charante@codeaurora.org>
Signed-off-by: Marco Zanin <mrczn.bb@gmail.com>
Signed-off-by: snnbyyds <snnbyyds@gmail.com>
Signed-off-by: Sorayukii <sorayukii69@gmail.com>

Joonsoo Kim   authored and   Sorayukii   commited 2026-05-15 18:07:09 +07:00
c00a6ce419
zram: make deduplication feature optional
Benefit of deduplication is dependent on the workload so it's not
preferable to always enable. Therefore, make it optional in Kconfig
and device param. Default is 'off'. This option will be beneficial
for users who use the zram as blockdev and stores build output to it.

Change-Id: If282bb8aa15c5749859a87cf36db7eb9edb3b1ed
Reviewed-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Acked-by: Minchan Kim <minchan@kernel.org>
Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Link: https://lore.kernel.org/patchwork/patch/787164/
Patch-mainline: linux-kernel@ Thu, 11 May 2017 22:30:52
Signed-off-by: Charan Teja Reddy <charante@codeaurora.org>
Signed-off-by: Marco Zanin <mrczn.bb@gmail.com>
Signed-off-by: snnbyyds <snnbyyds@gmail.com>
Signed-off-by: Sorayukii <sorayukii69@gmail.com>

Joonsoo Kim   authored and   Sorayukii   commited 2026-05-15 18:07:09 +07:00
64ef903a86
zram: implement deduplication in zram
This patch implements deduplication feature in zram. The purpose
of this work is naturally to save amount of memory usage by zram.

Android is one of the biggest users to use zram as swap and it's
really important to save amount of memory usage. There is a paper
that reports that duplication ratio of Android's memory content is
rather high [1]. And, there is a similar work on zswap that also
reports that experiments has shown that around 10-15% of pages
stored in zswp are duplicates and deduplicate them provides some
benefits [2].

Also, there is a different kind of workload that uses zram as blockdev
and store build outputs into it to reduce wear-out problem of real
blockdev. In this workload, deduplication hit is very high due to
temporary files and intermediate object files. Detailed analysis is
on the bottom of this description.

Anyway, if we can detect duplicated content and avoid to store duplicated
content at different memory space, we can save memory. This patch
tries to do that.

Implementation is almost simple and intuitive but I should note
one thing about implementation detail.

To check duplication, this patch uses checksum of the page and
collision of this checksum could be possible. There would be
many choices to handle this situation but this patch chooses
to allow entry with duplicated checksum to be added to the hash,
but, not to compare all entries with duplicated checksum
when checking duplication. I guess that checksum collision is quite
rare event and we don't need to pay any attention to such a case.
Therefore, I decided the most simplest way to implement the feature.
If there is a different opinion, I can accept and go that way.

Following is the result of this patch.

Test result #1 (Swap):
Android Marshmallow, emulator, x86_64, Backporting to kernel v3.18

orig_data_size: 145297408
compr_data_size: 32408125
mem_used_total: 32276480
dup_data_size: 3188134
meta_data_size: 1444272

Last two metrics added to mm_stat are related to this work.
First one, dup_data_size, is amount of saved memory by avoiding
to store duplicated page. Later one, meta_data_size, is the amount of
data structure to support deduplication. If dup > meta, we can judge
that the patch improves memory usage.

In Adnroid, we can save 5% of memory usage by this work.

Test result #2 (Blockdev):
build the kernel and store output to ext4 FS on zram

<no-dedup>
Elapsed time: 249 s
mm_stat: 430845952 191014886 196898816 0 196898816 28320 0 0 0

<dedup>
Elapsed time: 250 s
mm_stat: 430505984 190971334 148365312 0 148365312 28404 0 47287038  3945792

There is no performance degradation and save 23% memory.

Test result #3 (Blockdev):
copy android build output dir(out/host) to ext4 FS on zram

<no-dedup>
Elapsed time: out/host: 88 s
mm_stat: 8834420736 3658184579 3834208256 0 3834208256 32889 0 0 0

<dedup>
Elapsed time: out/host: 100 s
mm_stat: 8832929792 3657329322 2832015360 0 2832015360 32609 0 952568877 80880336

It shows performance degradation roughly 13% and save 24% memory. Maybe,
it is due to overhead of calculating checksum and comparison.

Test result #4 (Blockdev):
copy android build output dir(out/target/common) to ext4 FS on zram

<no-dedup>
Elapsed time: out/host: 203 s
mm_stat: 4041678848 2310355010 2346577920 0 2346582016 500 4 0 0

<dedup>
Elapsed time: out/host: 201 s
mm_stat: 4041666560 2310488276 1338150912 0 1338150912 476 0 989088794 24564336

Memory is saved by 42% and performance is the same. Even if there is overhead
of calculating checksum and comparison, large hit ratio compensate it since
hit leads to less compression attempt.

I checked the detailed reason of savings on kernel build workload and
there are some cases that deduplication happens.

1) *.cmd
Build command is usually similar in one directory so content of these file
are very similar. In my system, more than 789 lines in fs/ext4/.namei.o.cmd
and fs/ext4/.inode.o.cmd are the same in 944 and 938 lines of the file,
respectively.

2) intermediate object files
built-in.o and temporary object file have the similar contents. More than
50% of fs/ext4/ext4.o is the same with fs/ext4/built-in.o.

3) vmlinux
.tmp_vmlinux1 and .tmp_vmlinux2 and arch/x86/boo/compressed/vmlinux.bin
have the similar contents.

Android test has similar case that some of object files(.class
and .so) are similar with another ones.
(./host/linux-x86/lib/libartd.so and
./host/linux-x86-lib/libartd-comiler.so)

Anyway, benefit seems to be largely dependent on the workload so
following patch will make this feature optional. However, this feature
can help some usecases so is deserved to be merged.

[1]: MemScope: Analyzing Memory Duplication on Android Systems,
dl.acm.org/citation.cfm?id=2797023
[2]: zswap: Optimize compressed pool memory utilization,
lkml.kernel.org/r/1341407574.7551.1471584870761.JavaMail.weblogic@epwas3p2

Change-Id: I8fe80c956c33f88a6af337d50d9e210e5c35ce37
Reviewed-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Acked-by: Minchan Kim <minchan@kernel.org>
Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Link: https://lore.kernel.org/patchwork/patch/787162/
Patch-mainline: linux-kernel@ Thu, 11 May 2017 22:30:26
Signed-off-by: Charan Teja Reddy <charante@codeaurora.org>
Signed-off-by: Marco Zanin <mrczn.bb@gmail.com>
Signed-off-by: snnbyyds <snnbyyds@gmail.com>
Signed-off-by: Sorayukii <sorayukii69@gmail.com>

Joonsoo Kim   authored and   Sorayukii   commited 2026-05-15 18:07:08 +07:00
d712a84b0c
zram: introduce zram_entry to prepare dedup functionality
Following patch will implement deduplication functionality
in the zram and it requires an indirection layer to manage
the life cycle of zsmalloc handle. To prepare that, this patch
introduces zram_entry which can be used to manage the life-cycle
of zsmalloc handle. Many lines are changed due to rename but
core change is just simple introduction about newly data structure.

Change-Id: Ibf9912397c8c7dbcf1465550bc83a71f904e41c7
Reviewed-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Acked-by: Minchan Kim <minchan@kernel.org>
Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Link: https://lore.kernel.org/patchwork/patch/787161/
Patch-mainline: linux-kernel@ Thu, 11 May 2017 22:30:21
Signed-off-by: Charan Teja Reddy <charante@codeaurora.org>
Signed-off-by: Marco Zanin <mrczn.bb@gmail.com>
Signed-off-by: snnbyyds <snnbyyds@gmail.com>
Signed-off-by: Sorayukii <sorayukii69@gmail.com>

Joonsoo Kim   authored and   Sorayukii   commited 2026-05-15 18:07:08 +07:00
af5e5830a2
zram: allow reclaim on bio_alloc
The read_from_bdev_async is not called on atomic context.  So GFP_NOIO
is available rather than GFP_ATOMIC.  If there were reclaimable pages
with GFP_NOIO, we can avoid allocation failure and page fault failure.

Link: https://lkml.kernel.org/r/20210908005241.28062-1-jaewon31.kim@samsung.com
Signed-off-by: Jaewon Kim <jaewon31.kim@samsung.com>
Reported-by: Yong-Taek Lee <ytk.lee@samsung.com>
Acked-by: Minchan Kim <minchan@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Marco Zanin <mrczn.bb@gmail.com>
Signed-off-by: snnbyyds <snnbyyds@gmail.com>
Signed-off-by: Sorayukii <sorayukii69@gmail.com>

Jaewon Kim   authored and   Sorayukii   commited 2026-05-15 18:07:08 +07:00
4b69c6df55
zram: replace fsync_bdev with sync_blockdev
When calling fsync_bdev(), zram driver guarantees that the bdev won't be
opened by anyone, then there can't be one active fs/superblock over the
zram bdev, so replace fsync_bdev with sync_blockdev.

Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
Acked-by: Minchan Kim <minchan@kernel.org>
Link: https://lore.kernel.org/r/20211025025426.2815424-5-ming.lei@redhat.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Marco Zanin <mrczn.bb@gmail.com>
Signed-off-by: snnbyyds <snnbyyds@gmail.com>
Signed-off-by: Sorayukii <sorayukii69@gmail.com>

Ming Lei   authored and   Sorayukii   commited 2026-05-15 18:07:08 +07:00
0570a9c44c
zram: fix race between zram_reset_device() and disksize_store()
When the ->init_lock is released in zram_reset_device(), disksize_store()
can come in and try to allocate meta, but zram_reset_device() is freeing
free meta, so cause races.

Link: https://lore.kernel.org/linux-block/20210927163805.808907-1-mcgrof@kernel.org/T/#mc617f865a3fa2778e40f317ddf48f6447c20c073
Reported-by: Luis Chamberlain <mcgrof@kernel.org>
Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
Acked-by: Minchan Kim <minchan@kernel.org>
Link: https://lore.kernel.org/r/20211025025426.2815424-2-ming.lei@redhat.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Marco Zanin <mrczn.bb@gmail.com>
Signed-off-by: snnbyyds <snnbyyds@gmail.com>
Signed-off-by: Sorayukii <sorayukii69@gmail.com>

Ming Lei   authored and   Sorayukii   commited 2026-05-15 18:07:08 +07:00
0955e51826
zram: Use lz4 compression by default if present
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
Signed-off-by: Sorayukii <sorayukii69@gmail.com>

Nathan Chancellor   authored and   Sorayukii   commited 2026-05-15 18:07:08 +07:00
3db37b3c43
lib: zstd: Fix compilation after merging zstd v1.5.7
../lib/zstd/compress/../common/mem.h:18:10: fatal error: 'linux/unaligned.h' file not found
#include <linux/unaligned.h>  /* get_unaligned, put_unaligned* */
         ^~~~~~~~~~~~~~~~~~~

Signed-off-by: Sorayukii <sorayukii69@gmail.com>

Pzqqt   authored and   Sorayukii   commited 2026-05-15 18:07:08 +07:00
c2b240a8ab
lib: zstd: Upgrade to latest upstream zstd version v1.5.7
Follow the steps: https://github.com/facebook/zstd/blob/v1.5.7/contrib/linux-kernel/README.md

The following committed changes are also preserved:
70168143b302378ccff178bf28cb140c783dac88 zstd: merge optimization from Samsung <DevriesL>
0b893588096921a258f8ca27d6005da4201c9b58 lib: zstd: Don't inline functions in zstd_opt.c <Nick Terrell>

Signed-off-by: Sorayukii <sorayukii69@gmail.com>

Pzqqt   authored and   Sorayukii   commited 2026-05-15 18:07:07 +07:00
4e67adc266
lib: zstd: Upgrade to latest upstream zstd version v1.5.6
Follow the steps: https://github.com/facebook/zstd/blob/v1.5.6/contrib/linux-kernel/README.md

The following committed changes are also preserved:
c97320470b510a90bac077842630bd49c7cce95e zstd: merge optimization from Samsung <DevriesL>
9df1909b60b40fc7450ebff9b45d7cd2ac70225d lib: zstd: Don't inline functions in zstd_opt.c <Nick Terrell>

Signed-off-by: Sorayukii <sorayukii69@gmail.com>

Pzqqt   authored and   Sorayukii   commited 2026-05-15 18:07:07 +07:00
bc58b0535a
lib: zstd: Fix a warning in zstd_reset_dstream()
- ZSTD_resetDstream() is deprecated hence it is wise to make zstd_reset_dstream() functionally identical to ZSTD_resetDstream() as we have done for the compression stream in [1].
- Also make ZSTD_startingInputLength() visible for the decompression driver to be able to use it.
- This fixes the below warning:

../lib/zstd/zstd_decompress_module.c: In function 'zstd_reset_dstream':
../lib/zstd/zstd_decompress_module.c:80:9: warning: 'ZSTD_resetDStream' is deprecated [-Wdeprecated-declarations]
   80 |         return ZSTD_resetDStream(dstream);
      |         ^~~~~~
In file included from ../include/linux/zstd.h:26,
                 from ../lib/zstd/zstd_decompress_module.c:15:
../include/linux/zstd_lib.h:2569:27: note: declared here
 2569 | ZSTDLIB_STATIC_API size_t ZSTD_resetDStream(ZSTD_DStream* zds);
      |                           ^~~~~~~~~~~~~~~~~

[1]: https://github.com/facebook/zstd/pull/3088

Signed-off-by: Cyber Knight <cyberknight755@gmail.com>
Signed-off-by: Sorayukii <sorayukii69@gmail.com>

Cyber Knight   authored and   Sorayukii   commited 2026-05-15 18:07:07 +07:00
6d1e87e6f2
lib: zstd: Upgrade to latest upstream zstd version v1.5.5
Follow the steps: https://github.com/facebook/zstd/blob/v1.5.5/contrib/linux-kernel/README.md

Signed-off-by: Sorayukii <sorayukii69@gmail.com>

Pzqqt   authored and   Sorayukii   commited 2026-05-15 18:07:07 +07:00
35a2631609
lib: zstd: Upstream codebase to v1.5.3 (dev branch)
Signed-off-by: iusmac <iusico.maxim@libero.it>
Signed-off-by: Sorayukii <sorayukii69@gmail.com>

iusmac   authored and   Sorayukii   commited 2026-05-15 18:07:07 +07:00
7f95d14000
lib: zstd: Workaround duplicate symbols
ld.lld: error: duplicate symbol: ZSTD_isError
>>> defined at error_private.h:47 (../../../../../../src/kernel/xiaomi/rova/lib/zstd/common/error_private.h:47)
>>>            lib/zstd/zstd_compress.o:(ZSTD_isError)
>>> defined at error_private.h:47 (../../../../../../src/kernel/xiaomi/rova/lib/zstd/common/error_private.h:47)
>>>            lib/zstd/zstd_decompress.o:(.text+0x2570)

and many more...

Signed-off-by: iusmac <iusico.maxim@libero.it>
Signed-off-by: Sorayukii <sorayukii69@gmail.com>

iusmac   authored and   Sorayukii   commited 2026-05-15 18:07:06 +07:00
f16a225000
lib: zstd: Fix unknown type name size_t
CC      lib/zstd/compress/zstd_compress_sequences.o
In file included from ../../../../../../src/kernel/xiaomi/rova/lib/zstd/compress/zstd_compress_sequences.c:14:
In file included from ../../../../../../src/kernel/xiaomi/rova/lib/zstd/compress/zstd_compress_sequences.h:14:
../../../../../../src/kernel/xiaomi/rova/lib/zstd/compress/../common/fse.h:64:16: error: unknown type name 'size_t'
FSE_PUBLIC_API size_t FSE_compress(void* dst, size_t dstCapacity,
               ^

Signed-off-by: iusmac <iusico.maxim@libero.it>
Signed-off-by: Sorayukii <sorayukii69@gmail.com>

iusmac   authored and   Sorayukii   commited 2026-05-15 18:07:06 +07:00
d85c181141