From: Tejun Heo <tj@kernel.org>
To: "boy.wu" <boy.wu@mediatek.com>
Cc: Josef Bacik <josef@toxicpanda.com>, Jens Axboe <axboe@kernel.dk>,
Matthias Brugger <matthias.bgg@gmail.com>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>,
Boris Burkov <boris@bur.io>,
cgroups@vger.kernel.org, linux-block@vger.kernel.org,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org, iverlin.wang@mediatek.com
Subject: Re: [PATCH v3] blk-cgroup: Replace u64 sync with spinlock for iostat update
Date: Tue, 16 Jul 2024 11:13:35 -1000 [thread overview]
Message-ID: <Zpbify32lel9J-5I@slm.duckdns.org> (raw)
In-Reply-To: <20240716075206.23121-1-boy.wu@mediatek.com>
Hello, Boy.
So, looking at the patch, I'm not sure per-blkg lock makes sense.
On Tue, Jul 16, 2024 at 03:52:06PM +0800, boy.wu wrote:
> @@ -995,15 +995,13 @@ static void blkcg_iostat_update(struct blkcg_gq *blkg, struct blkg_iostat *cur,
> struct blkg_iostat *last)
> {
> struct blkg_iostat delta;
> - unsigned long flags;
>
> /* propagate percpu delta to global */
> - flags = u64_stats_update_begin_irqsave(&blkg->iostat.sync);
> + guard(spinlock_irqsave)(&blkg->iostat.spinlock);
> blkg_iostat_set(&delta, cur);
> blkg_iostat_sub(&delta, last);
> blkg_iostat_add(&blkg->iostat.cur, &delta);
> blkg_iostat_add(last, &delta);
> - u64_stats_update_end_irqrestore(&blkg->iostat.sync, flags);
> }
This is already called with blkg_stat_lock held.
> @@ -1051,10 +1048,8 @@ static void __blkcg_rstat_flush(struct blkcg *blkcg, int cpu)
> goto propagate_up; /* propagate up to parent only */
>
> /* fetch the current per-cpu values */
> - do {
> - seq = u64_stats_fetch_begin(&bisc->sync);
> + scoped_guard(spinlock_irqsave, &bisc->spinlock)
> blkg_iostat_set(&cur, &bisc->cur);
> - } while (u64_stats_fetch_retry(&bisc->sync, seq));
This is per-cpu stat and we should keep using u64_sync for them.
> @@ -1134,9 +1128,8 @@ static void blkcg_fill_root_iostats(void)
> cpu_dkstats->sectors[STAT_DISCARD] << 9;
> }
>
> - flags = u64_stats_update_begin_irqsave(&blkg->iostat.sync);
> + guard(spinlock_irqsave)(&blkg->iostat.spinlock);
> blkg_iostat_set(&blkg->iostat.cur, &tmp);
> - u64_stats_update_end_irqrestore(&blkg->iostat.sync, flags);
> }
> }
...
> @@ -1157,16 +1149,14 @@ static void blkcg_print_one_stat(struct blkcg_gq *blkg, struct seq_file *s)
>
> seq_printf(s, "%s ", dname);
>
> - do {
> - seq = u64_stats_fetch_begin(&bis->sync);
> -
> + scoped_guard(spinlock_irqsave, &bis->spinlock) {
> rbytes = bis->cur.bytes[BLKG_IOSTAT_READ];
> wbytes = bis->cur.bytes[BLKG_IOSTAT_WRITE];
> dbytes = bis->cur.bytes[BLKG_IOSTAT_DISCARD];
> rios = bis->cur.ios[BLKG_IOSTAT_READ];
> wios = bis->cur.ios[BLKG_IOSTAT_WRITE];
> dios = bis->cur.ios[BLKG_IOSTAT_DISCARD];
> - } while (u64_stats_fetch_retry(&bis->sync, seq));
> + }
The above two are the only places which can potentially benefit from
per-blkg lock but these aren't hot paths. I'd just use blkg_stat_lock for
the above.
> @@ -2152,30 +2141,29 @@ void blk_cgroup_bio_start(struct bio *bio)
>
> cpu = get_cpu();
> bis = per_cpu_ptr(bio->bi_blkg->iostat_cpu, cpu);
> - flags = u64_stats_update_begin_irqsave(&bis->sync);
> -
> - /*
> - * If the bio is flagged with BIO_CGROUP_ACCT it means this is a split
> - * bio and we would have already accounted for the size of the bio.
> - */
> - if (!bio_flagged(bio, BIO_CGROUP_ACCT)) {
> - bio_set_flag(bio, BIO_CGROUP_ACCT);
> - bis->cur.bytes[rwd] += bio->bi_iter.bi_size;
> - }
> - bis->cur.ios[rwd]++;
> + scoped_guard(spinlock_irqsave, &bis->spinlock) {
> + /*
> + * If the bio is flagged with BIO_CGROUP_ACCT it means this is a split
> + * bio and we would have already accounted for the size of the bio.
> + */
> + if (!bio_flagged(bio, BIO_CGROUP_ACCT)) {
> + bio_set_flag(bio, BIO_CGROUP_ACCT);
> + bis->cur.bytes[rwd] += bio->bi_iter.bi_size;
> + }
> + bis->cur.ios[rwd]++;
>
> - /*
> - * If the iostat_cpu isn't in a lockless list, put it into the
> - * list to indicate that a stat update is pending.
> - */
> - if (!READ_ONCE(bis->lqueued)) {
> - struct llist_head *lhead = this_cpu_ptr(blkcg->lhead);
> + /*
> + * If the iostat_cpu isn't in a lockless list, put it into the
> + * list to indicate that a stat update is pending.
> + */
> + if (!READ_ONCE(bis->lqueued)) {
> + struct llist_head *lhead = this_cpu_ptr(blkcg->lhead);
>
> - llist_add(&bis->lnode, lhead);
> - WRITE_ONCE(bis->lqueued, true);
> + llist_add(&bis->lnode, lhead);
> + WRITE_ONCE(bis->lqueued, true);
> + }
These are per-cpu stat updates which should keep using u64_sync. We don't
want to incur locking overhead for stat updates in the hot issue path.
Thanks.
--
tejun
next prev parent reply other threads:[~2024-07-16 21:13 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-16 7:52 [PATCH v3] blk-cgroup: Replace u64 sync with spinlock for iostat update boy.wu
2024-07-16 21:13 ` Tejun Heo [this message]
2024-07-17 2:25 ` Boy Wu (吳勃誼)
2024-07-17 3:44 ` Boy Wu (吳勃誼)
2024-07-17 4:09 ` Boy Wu (吳勃誼)
2024-07-17 16:55 ` tj
2024-07-17 17:37 ` Waiman Long
2024-07-17 17:40 ` tj
2024-07-17 18:18 ` Waiman Long
2024-07-17 18:24 ` tj
2024-07-17 18:55 ` Waiman Long
2024-07-17 18:57 ` tj
2024-07-18 1:21 ` Boy Wu (吳勃誼)
2024-07-18 1:27 ` tj
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=Zpbify32lel9J-5I@slm.duckdns.org \
--to=tj@kernel.org \
--cc=angelogioacchino.delregno@collabora.com \
--cc=axboe@kernel.dk \
--cc=boris@bur.io \
--cc=boy.wu@mediatek.com \
--cc=cgroups@vger.kernel.org \
--cc=iverlin.wang@mediatek.com \
--cc=josef@toxicpanda.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=matthias.bgg@gmail.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