From: Minchan Kim <minchan@kernel.org>
To: Sergey Senozhatsky <senozhatsky@chromium.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Yuwen Chen <ywen.chen@foxmail.com>,
Richard Chang <richardycc@google.com>,
Brian Geffon <bgeffon@google.com>,
Fengyu Lian <licayy@outlook.com>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
linux-block@vger.kernel.org
Subject: Re: [PATCHv2 1/4] zram: introduce writeback bio batching support
Date: Fri, 14 Nov 2025 11:14:35 -0800 [thread overview]
Message-ID: <aRd_m00a6AcVtDh0@google.com> (raw)
In-Reply-To: <rjowf2hdk7pkmqpslj6jaqm6y4mhvr726dxpjyz7jtcjixv3hi@jyah654foky4>
On Fri, Nov 14, 2025 at 10:53:23AM +0900, Sergey Senozhatsky wrote:
> On (25/11/13 15:45), Minchan Kim wrote:
> [..]
> > > +struct zram_wb_req {
> > > + unsigned long blk_idx;
> > > + struct page *page;
> > > struct zram_pp_slot *pps;
> > > struct bio_vec bio_vec;
> > > struct bio bio;
> > > - int ret = 0, err;
> > > +
> > > + struct list_head entry;
> > > +};
> >
> > How about moving structure definition to the upper part of the C file?
> > Not only readability to put together data types but also better diff
> > for reviewer to know what we changed in this patch.
>
> This still needs to be under #ifdef CONFIG_ZRAM_WRITEBACK so readability
> is not significantly better. Do you still prefer moving it up?
Let's move them on top of ifdef CONFIG_ZRAM_WRITEBACK, then.
IOW, above of writeback_limit_enable_store.
>
> [..]
>
> > > +/* XXX: should be a per-device sysfs attr */
> > > +#define ZRAM_WB_REQ_CNT 1
> >
> > Understand you will create the knob for the tune but at least,
> > let's introduce default number for that here.
> >
> > How about 32 since it's general queue depth for modern storage?
>
> So this is tricky. I don't know what number is a good default for
> all, given the variety of devices out there, variety of specs and
> hardware, on both sides of price range. I don't know if 32 is safe
> wrt to performance/throughput (I may be wrong and 32 is safe for
> everyone). On the other hand, 1 was our baseline for ages, so I
> wanted to minimize the risks and just keep the baseline behavior.
>
> Do you still prefer 32 as default? (here and in the next patch)
Yes, we couldn't get the perfect number everyone would be happpy
since we don't know their configuration but the value is the
typical UFS 3.1(even, it's little old sice UFS has higher queue depth)'s
queue depth. More good thing with the 32 is aligned with SWAP_CLUSTER_MAX
which is the unit of batching in the traditional split LRU reclaim.
Assuming we don't encounter any significant regressions, I'd like to
move forward with a queue depth of 32 so that all users can benefit from
this speedup.
>
> [..]
> > > + for (i = 0; i < ZRAM_WB_REQ_CNT; i++) {
> > > + struct zram_wb_req *req;
> > > +
> > > + /*
> > > + * This is fatal condition only if we couldn't allocate
> > > + * any requests at all. Otherwise we just work with the
> > > + * requests that we have successfully allocated, so that
> > > + * writeback can still proceed, even if there is only one
> > > + * request on the idle list.
> > > + */
> > > + req = kzalloc(sizeof(*req), GFP_NOIO | __GFP_NOWARN);
> >
> > Why GFP_NOIO?
> >
> > > + if (!req)
> > > + break;
> > > +
> > > + req->page = alloc_page(GFP_NOIO | __GFP_NOWARN);
> >
> > Ditto
>
> So we do this for post-processing, which allocates a bunch of memory
> for post-processing (not only requests lists with physical pages, but
> also candidate slots buckets). The thing is that post-processing can
> be called under memory pressure and we don't really want to block and
> reclaim memory from the path that is called to relive memory pressure
> (by doing writeback or recompression).
Sorry, I didn't understand what's the post-processing means.
First, this writeback_store path is not critical path. Typical usecase
is trigger the writeback store on system idle time to save zram memory.
Second, If you used the flag to relieve memory pressure, that's not
the right flag. GFP_NOIO aimed to prevent deadlock with IO context
but the writeback_store is just process context so no reason to use
the GFP_NOIO. (If we really want to releieve memory presure, we
should use __GFP_NORETRY with ~__GFP_RECLAIM but I doubt)
>
> > > + if (!req->page) {
> > > + kfree(req);
> > > + break;
> > > + }
> > > +
> > > + INIT_LIST_HEAD(&req->entry);
> >
> > Do we need this reset?
>
> Let me take a look.
>
> > > +static void zram_account_writeback_rollback(struct zram *zram)
> > > +{
> > > + spin_lock(&zram->wb_limit_lock);
> > > + if (zram->wb_limit_enable)
> > > + zram->bd_wb_limit += 1UL << (PAGE_SHIFT - 12);
> > > + spin_unlock(&zram->wb_limit_lock);
> > > +}
> > > +
> > > +static void zram_account_writeback_submit(struct zram *zram)
> > > +{
> > > + spin_lock(&zram->wb_limit_lock);
> > > + if (zram->wb_limit_enable && zram->bd_wb_limit > 0)
> > > + zram->bd_wb_limit -= 1UL << (PAGE_SHIFT - 12);
> > > + spin_unlock(&zram->wb_limit_lock);
> > > +}
> >
> > I didn't think about much about this that we really need to be
> > accurate like this. Maybe, next time after coffee.
>
> Sorry, not sure I understand this comment.
I meant I didn't took close look the part, yet. :)
next prev parent reply other threads:[~2025-11-14 19:14 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-13 8:53 [PATCHv2 0/4] zram: introduce writeback bio batching Sergey Senozhatsky
2025-11-13 8:53 ` [PATCHv2 1/4] zram: introduce writeback bio batching support Sergey Senozhatsky
2025-11-13 23:45 ` Minchan Kim
2025-11-14 1:53 ` Sergey Senozhatsky
2025-11-14 3:08 ` Sergey Senozhatsky
2025-11-14 19:14 ` Minchan Kim [this message]
2025-11-15 2:25 ` Sergey Senozhatsky
2025-11-15 3:42 ` Sergey Senozhatsky
2025-11-13 8:54 ` [PATCHv2 2/4] zram: add writeback batch size device attr Sergey Senozhatsky
2025-11-13 8:54 ` [PATCHv2 3/4] zram: take write lock in wb limit store handlers Sergey Senozhatsky
2025-11-13 8:54 ` [PATCHv2 4/4] zram: drop wb_limit_lock Sergey Senozhatsky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aRd_m00a6AcVtDh0@google.com \
--to=minchan@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=bgeffon@google.com \
--cc=licayy@outlook.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=richardycc@google.com \
--cc=senozhatsky@chromium.org \
--cc=ywen.chen@foxmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox