Re: [RFC PATCHv5 1/6] zram: introduce writeback bio batching
From: Sergey Senozhatsky
Date: Fri Nov 21 2025 - 02:47:11 EST
On (25/11/21 08:40), Hannes Reinecke wrote:
> > +static int zram_complete_done_reqs(struct zram *zram,
> > + struct zram_wb_ctl *wb_ctl)
> > +{
> > + struct zram_wb_req *req;
> > + unsigned long flags;
> > int ret = 0, err;
> > - u32 index;
> > - page = alloc_page(GFP_KERNEL);
> > - if (!page)
> > - return -ENOMEM;
> > + while (1) {
> > + spin_lock_irqsave(&wb_ctl->done_lock, flags);
> > + req = list_first_entry_or_null(&wb_ctl->done_reqs,
> > + struct zram_wb_req, entry);
> > + if (req)
> > + list_del(&req->entry);
> > + spin_unlock_irqrestore(&wb_ctl->done_lock, flags);
> > +
> > + if (!req)
> > + break;
> > +
> > + err = zram_writeback_complete(zram, req);
> > + if (err)
> > + ret = err;
> > +
> > + atomic_dec(&wb_ctl->num_inflight);
> > + release_pp_slot(zram, req->pps);
> > + req->pps = NULL;
> > +
> > + list_add(&req->entry, &wb_ctl->idle_reqs);
>
> Shouldn't this be locked?
See below.
> > + }
> > +
> > + return ret;
> > +}
> > +
> > +static struct zram_wb_req *zram_select_idle_req(struct zram_wb_ctl *wb_ctl)
> > +{
> > + struct zram_wb_req *req;
> > +
> > + req = list_first_entry_or_null(&wb_ctl->idle_reqs,
> > + struct zram_wb_req, entry);
> > + if (req)
> > + list_del(&req->entry);
>
> See above. I think you need to lock this to avoid someone stepping in
> here an modify the element under you.
->idle_reqs list is mutated by one and one task only: the one that
does writeback. ->done_reqs list, on the other hand, is accessed
both from IRQ (bio completion) and from the writeback task.