linux/drivers/block/zram
Sergey Senozhatsky b0377ee804 zram: do not slot_free() written-back slots
slot_free() basically completely resets the slots by clearing all of
its flags and attributes.  While zram_writeback_complete() restores
some of flags back (those that are necessary for async read
decompression) we still lose a lot of slot's metadata.  For example,
slot's ac-time, or ZRAM_INCOMPRESSIBLE.

More importantly, restoring flags/attrs requires extra attention as
some of the flags are directly affecting zram device stats.  And the
original code did not pay that attention.  Namely ZRAM_HUGE slots
handling in zram_writeback_complete().  The call to slot_free() would
decrement ->huge_pages, however when zram_writeback_complete() restored
the slot's ZRAM_HUGE flag, it would not get reflected in an incremented
->huge_pages.  So when the slot would finally get freed, slot_free()
would decrement ->huge_pages again, leading to underflow.

Fix this by open-coding the required memory free and stats updates in
zram_writeback_complete(), rather than calling the destructive
slot_free().  Since we now preserve the ZRAM_HUGE flag on written-back
slots (for the deferred decompression path), we also update slot_free()
to skip decrementing ->huge_pages if ZRAM_WB is set.

Link: https://lkml.kernel.org/r/20260320023143.2372879-1-senozhatsky@chromium.org
Link: https://lkml.kernel.org/r/20260319034912.1894770-1-senozhatsky@chromium.org
Fixes: d38fab605c ("zram: introduce compressed data writeback")
Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Acked-by: Minchan Kim <minchan@kernel.org>
Cc: Brian Geffon <bgeffon@google.com>
Cc: Richard Chang <richardycc@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2026-03-21 17:36:33 -07:00
..
Kconfig zram: ZRAM_DEF_COMP should depend on ZRAM 2024-11-11 17:22:27 -08:00
Makefile zram: add 842 compression backend support 2024-09-09 16:39:08 -07:00
backend_842.c zram: move immutable comp params away from per-CPU context 2024-09-09 16:39:10 -07:00
backend_842.h zram: add 842 compression backend support 2024-09-09 16:39:08 -07:00
backend_deflate.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
backend_deflate.h zram: add zlib compression backend support 2024-09-09 16:39:08 -07:00
backend_lz4.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
backend_lz4.h zram: add lz4 compression backend support 2024-09-09 16:39:07 -07:00
backend_lz4hc.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
backend_lz4hc.h zram: add lz4hc compression backend support 2024-09-09 16:39:07 -07:00
backend_lzo.c zram: move immutable comp params away from per-CPU context 2024-09-09 16:39:10 -07:00
backend_lzo.h zram: add lzo and lzorle compression backends support 2024-09-09 16:39:07 -07:00
backend_lzorle.c zram: move immutable comp params away from per-CPU context 2024-09-09 16:39:10 -07:00
backend_lzorle.h zram: add lzo and lzorle compression backends support 2024-09-09 16:39:07 -07:00
backend_zstd.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
backend_zstd.h zram: add zstd compression backend support 2024-09-09 16:39:08 -07:00
zcomp.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
zcomp.h zram: pass buffer offset to zcomp_available_show() 2025-07-03 19:56:51 -06:00
zram_drv.c zram: do not slot_free() written-back slots 2026-03-21 17:36:33 -07:00
zram_drv.h zram: rename writeback_compressed device attr 2026-03-04 09:44:23 -08:00