* [PATCH] zram: Avoid duplicate slots in batched writeback
@ 2026-11-10 6:18 raoxu
2026-11-10 6:40 ` Sergey Senozhatsky
0 siblings, 1 reply; 4+ messages in thread
From: raoxu @ 2026-11-10 6:18 UTC (permalink / raw)
To: minchan; +Cc: senozhatsky, axboe, linux-kernel, linux-block, raoxu
From: Xu Rao <raoxu@uniontech.com>
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@uniontech.com>
---
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] zram: Avoid duplicate slots in batched writeback
2026-11-10 6:18 [PATCH] zram: Avoid duplicate slots in batched writeback raoxu
@ 2026-11-10 6:40 ` Sergey Senozhatsky
2026-11-13 7:26 ` Andrew Morton
0 siblings, 1 reply; 4+ messages in thread
From: Sergey Senozhatsky @ 2026-11-10 6:40 UTC (permalink / raw)
To: Andrew Morton, Jens Axboe, raoxu
Cc: minchan, senozhatsky, linux-kernel, linux-block
On (26/11/10 14:18), raoxu wrote:
> 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@uniontech.com>
LGTM.
Reviewed-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Jens, do you want to pick it up and route via block tree or should
we route via "more traditional" tree (Andrew's tree)?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] zram: Avoid duplicate slots in batched writeback
2026-11-10 6:40 ` Sergey Senozhatsky
@ 2026-11-13 7:26 ` Andrew Morton
2026-11-13 9:50 ` David Hildenbrand (Arm)
0 siblings, 1 reply; 4+ messages in thread
From: Andrew Morton @ 2026-11-13 7:26 UTC (permalink / raw)
To: Sergey Senozhatsky
Cc: Jens Axboe, raoxu, minchan, linux-kernel, linux-block, David Hildenbrand
On Tue, 10 Nov 2026 15:40:13 +0900 Sergey Senozhatsky <senozhatsky@chromium.org> wrote:
> On (26/11/10 14:18), raoxu wrote:
> > 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@uniontech.com>
>
> LGTM.
> Reviewed-by: Sergey Senozhatsky <senozhatsky@chromium.org>
>
> Jens, do you want to pick it up and route via block tree or should
> we route via "more traditional" tree (Andrew's tree)?
I grabbed it.
I did recently attempt to pull zram out of the mm project, by moving it
from mm.git's mm-unstable branch and into mm.git's mm-nonmm-unstable
branch. Because "why does the mm project contain a block device
driver".
I undid that change after about a week - it didn't work out because
zram is joined at the hip with mm/zsmalloc.c. zsmalloc is also used by
mm/zswap.c.
Oh well. afaik the zram story has been going smoothly for a long
time(?).
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] zram: Avoid duplicate slots in batched writeback
2026-11-13 7:26 ` Andrew Morton
@ 2026-11-13 9:50 ` David Hildenbrand (Arm)
0 siblings, 0 replies; 4+ messages in thread
From: David Hildenbrand (Arm) @ 2026-11-13 9:50 UTC (permalink / raw)
To: Andrew Morton, Sergey Senozhatsky
Cc: Jens Axboe, raoxu, minchan, linux-kernel, linux-block
On 11/13/26 08:26, Andrew Morton wrote:
> On Tue, 10 Nov 2026 15:40:13 +0900 Sergey Senozhatsky <senozhatsky@chromium.org> wrote:
>
>> On (26/11/10 14:18), raoxu wrote:
>>> 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@uniontech.com>
>>
>> LGTM.
>> Reviewed-by: Sergey Senozhatsky <senozhatsky@chromium.org>
>>
>> Jens, do you want to pick it up and route via block tree or should
>> we route via "more traditional" tree (Andrew's tree)?
>
> I grabbed it.
>
> I did recently attempt to pull zram out of the mm project, by moving it
> from mm.git's mm-unstable branch and into mm.git's mm-nonmm-unstable
> branch. Because "why does the mm project contain a block device
> driver".
>
> I undid that change after about a week - it didn't work out because
> zram is joined at the hip with mm/zsmalloc.c. zsmalloc is also used by
> mm/zswap.c.
Are there cleaner ways of isolating both things?
Like, many drivers use kmalloc() etc, and they are not part of core-mm :)
--
Cheers,
David
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-13 9:51 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-10 6:18 [PATCH] zram: Avoid duplicate slots in batched writeback raoxu
2026-11-10 6:40 ` Sergey Senozhatsky
2026-11-13 7:26 ` Andrew Morton
2026-11-13 9:50 ` David Hildenbrand (Arm)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®