Re: [PATCHv3 1/4] zram: introduce writeback bio batching support

From: Sergey Senozhatsky
Date: Mon Nov 17 2025 - 22:49:03 EST


On (25/11/18 11:36), Yuwen Chen wrote:
> On Tue, 18 Nov 2025 11:18:56 +0800, Yuwen Chen wrote:
> >> + /*
> >> + * We release slot lock during writeback so slot can change under us:
> >> + * slot_free() or slot_free() and zram_write_page(). In both cases
> >> + * slot loses ZRAM_PP_SLOT flag. No concurrent post-processing can
> >> + * set ZRAM_PP_SLOT on such slots until current post-processing
> >> + * finishes.
> >> + */
> >> + if (!zram_test_flag(zram, index, ZRAM_PP_SLOT))
> >> + goto out;
> >In this place, the index may be leaked.
>
> To be precise, blk_idx may be leaked.

Ah, I see what you mean. Agreed.

I guess I'll just send out v4 later today, given that we have two
fixups in the queue already.

---
drivers/block/zram/zram_drv.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 0a5f11e0c523..8e91dc071b65 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -886,6 +886,7 @@ static int zram_writeback_complete(struct zram *zram, struct zram_wb_req *req)
* (if enabled).
*/
zram_account_writeback_rollback(zram);
+ free_block_bdev(zram, req->blk_idx);
return err;
}

@@ -898,8 +899,10 @@ static int zram_writeback_complete(struct zram *zram, struct zram_wb_req *req)
* set ZRAM_PP_SLOT on such slots until current post-processing
* finishes.
*/
- if (!zram_test_flag(zram, index, ZRAM_PP_SLOT))
+ if (!zram_test_flag(zram, index, ZRAM_PP_SLOT)) {
+ free_block_bdev(zram, req->blk_idx);
goto out;
+ }

zram_free_page(zram, index);
zram_set_flag(zram, index, ZRAM_WB);
--
2.52.0.rc1.455.g30608eb744-goog