[PATCH] zram: Avoid duplicate slots in batched writeback
From: raoxu
Date: Tue Nov 10 2026 - 01:19:30 EST
From: Xu Rao <raoxu@xxxxxxxxxxxxx>
The writeback interface accepts multiple page_index and page_indexes
parameters in one operation. Their ranges can overlap, but
scan_slots_for_writeback() only excludes slots that are already being
written back or marked as same-filled.
A slot selected by an earlier range is placed on the post-processing list
and marked with ZRAM_PP_SLOT. Without checking that flag, an overlapping
range can enqueue the same slot again and submit it for writeback more
than once.
Skip slots already marked ZRAM_PP_SLOT while holding the slot lock. This
keeps each slot in a writeback scan session represented by at most one
post-processing entry and leaves the existing release and reuse paths
unchanged.
Signed-off-by: Xu Rao <raoxu@xxxxxxxxxxxxx>
---
drivers/block/zram/zram_drv.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index ab064c84b092..50a25989a23b 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -1215,6 +1215,9 @@ static void scan_slots_for_writeback(struct zram *zram, u32 mode,
if (!slot_allocated(zram, index))
goto next;
+ if (test_slot_flag(zram, index, ZRAM_PP_SLOT))
+ goto next;
+
if (test_slot_flag(zram, index, ZRAM_WB) ||
test_slot_flag(zram, index, ZRAM_SAME))
goto next;
--
2.50.1