Re: [PATCH v4] zram: Implement multi-page write-back

From: Sergey Senozhatsky

Date: Wed Nov 12 2025 - 21:20:21 EST


On (25/11/06 09:49), Yuwen Chen wrote:
> +static struct zram_wb_request *zram_writeback_next_request(struct zram_wb_request *pool,
> + int pool_cnt, int *cnt_off)
> +{
> + struct zram_wb_request *req = NULL;
> + int i = 0;
> +
> + for (i = *cnt_off; i < pool_cnt + *cnt_off; i++) {
> + req = &pool[i % pool_cnt];
> + if (!req->page) {
> + /* This memory should be freed by the caller. */
> + req->page = alloc_page(GFP_KERNEL);
> + if (!req->page)
> + continue;
> + }
> +
> + if (!test_and_set_bit(ZRAM_WB_REQUEST_ALLOCATED, &req->flags)) {
> + *cnt_off = (i + 1) % pool_cnt;
> + return req;
> + }
> + }
> + return NULL;
> +}

So I wonder if things will look simpler (is this the word I'm looking
for?) if you just have two lists for requests: one list for completed/idle
requests and one list for in-flight requests (and you move requests
around accordingly). Then you don't need to iterate the pool and check
flags, you just can check list_empty(&idle_requests) and take the first
(front) element.