Re: [PATCH 2/3] mm/zram: handle swap read/write via swap_ops

From: YoungJun Park

Date: Mon Jun 15 2026 - 02:40:23 EST


On Sun, Jun 14, 2026 at 11:35:30PM +0800, Jianyue Wu wrote:

Hello!

> +static void zram_swap_submit_read(struct swap_io_ctx *ctx)
> +{
> + struct zram *zram = ctx->sis->bdev->bd_disk->private_data;

A passing thought. accessing `zram` here is too indirect. We might
need a `private_data` in the swap device struct someday?

(And If there is a real value like some swap-side only private data really needed.)

> + struct swap_iocb *sio = ctx->sio;
> + int nr = swap_iocb_nr_folios(sio);
> + bool failed = false;
> + int i, j;
> + /*
> + * read_from_zspool() and mark_slot_accessed() must run
> + * under the same slot_lock. zram_read_page() unlocks
> + * before returning, which leaves a window where
> + * writeback can pick an idle slot we just read.
> + */

Regarding the comment about the "window" where writeback can pick an
idle slot. I think this reasoning is a bit of a gray area. Writeback
could just as easily pick the slot right before entering this routine,
so the race condition seems fundamentally the same.

Isn't the actual justification here to separate the non-backend logic
and ensure mark_slot_accessed() is called under the lock, given that
zram_read_page() can call the backend device?

If the "window" mentioned in the comment is indeed a valid issue, then
zram_read_page() has the exact same problem and needs to be fixed as
well?

If not, IMHO I suggest revising or removing this comment to clarify
the true(?) intention. :)

> + slot_lock(zram, idx);
> + ret = read_from_zspool(zram, page, idx);
> + if (!ret)
> + mark_slot_accessed(zram, idx);
> + slot_unlock(zram, idx);