From: Waiman Long <longman@redhat.com>
To: "tj@kernel.org" <tj@kernel.org>, "Boy Wu (吳勃誼)" <Boy.Wu@mediatek.com>
Cc: "boris@bur.io" <boris@bur.io>,
"linux-block@vger.kernel.org" <linux-block@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"cgroups@vger.kernel.org" <cgroups@vger.kernel.org>,
"linux-mediatek@lists.infradead.org"
<linux-mediatek@lists.infradead.org>,
"axboe@kernel.dk" <axboe@kernel.dk>,
"Iverlin Wang (王苳霖)" <Iverlin.Wang@mediatek.com>,
"josef@toxicpanda.com" <josef@toxicpanda.com>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>,
"matthias.bgg@gmail.com" <matthias.bgg@gmail.com>,
"angelogioacchino.delregno@collabora.com"
<angelogioacchino.delregno@collabora.com>
Subject: Re: [PATCH v3] blk-cgroup: Replace u64 sync with spinlock for iostat update
Date: Wed, 17 Jul 2024 13:37:56 -0400 [thread overview]
Message-ID: <f448f66b-7a91-4281-8f77-159541cbacff@redhat.com> (raw)
In-Reply-To: <Zpf3ks2drDZ7ULTa@slm.duckdns.org>
On 7/17/24 12:55, tj@kernel.org wrote:
> Hello,
>
> Does something like the following work for you?
>
> Thanks.
>
> diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
> index 37e6cc91d576..ec1d191f5c83 100644
> --- a/block/blk-cgroup.c
> +++ b/block/blk-cgroup.c
> @@ -329,7 +329,6 @@ static struct blkcg_gq *blkg_alloc(struct blkcg *blkcg, struct gendisk *disk,
> INIT_WORK(&blkg->async_bio_work, blkg_async_bio_workfn);
> #endif
>
> - u64_stats_init(&blkg->iostat.sync);
> for_each_possible_cpu(cpu) {
> u64_stats_init(&per_cpu_ptr(blkg->iostat_cpu, cpu)->sync);
> per_cpu_ptr(blkg->iostat_cpu, cpu)->blkg = blkg;
> @@ -632,24 +631,26 @@ static void blkg_iostat_set(struct blkg_iostat *dst, struct blkg_iostat *src)
> static void __blkg_clear_stat(struct blkg_iostat_set *bis)
> {
> struct blkg_iostat cur = {0};
> - unsigned long flags;
>
> - flags = u64_stats_update_begin_irqsave(&bis->sync);
> blkg_iostat_set(&bis->cur, &cur);
> blkg_iostat_set(&bis->last, &cur);
> - u64_stats_update_end_irqrestore(&bis->sync, flags);
> }
>
> static void blkg_clear_stat(struct blkcg_gq *blkg)
> {
> + unsigned long flags;
> int cpu;
>
> + raw_spin_lock_irqsave(&blkg_stat_lock, flags);
> +
> for_each_possible_cpu(cpu) {
> struct blkg_iostat_set *s = per_cpu_ptr(blkg->iostat_cpu, cpu);
>
> __blkg_clear_stat(s);
> }
> __blkg_clear_stat(&blkg->iostat);
> +
> + raw_spin_unlock_irqrestore(&blkg_stat_lock, flags);
> }
>
> static int blkcg_reset_stats(struct cgroup_subsys_state *css,
> @@ -998,12 +999,10 @@ static void blkcg_iostat_update(struct blkcg_gq *blkg, struct blkg_iostat *cur,
> unsigned long flags;
>
> /* propagate percpu delta to global */
> - flags = u64_stats_update_begin_irqsave(&blkg->iostat.sync);
> 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);
> }
>
> static void __blkcg_rstat_flush(struct blkcg *blkcg, int cpu)
> @@ -1134,9 +1133,9 @@ static void blkcg_fill_root_iostats(void)
> cpu_dkstats->sectors[STAT_DISCARD] << 9;
> }
>
> - flags = u64_stats_update_begin_irqsave(&blkg->iostat.sync);
> + raw_spin_lock_irqsave(&blkg_stat_lock, flags);
> blkg_iostat_set(&blkg->iostat.cur, &tmp);
> - u64_stats_update_end_irqrestore(&blkg->iostat.sync, flags);
> + raw_spin_unlock_irqrestore(&blkg_stat_lock, flags);
> }
> }
>
> @@ -1145,7 +1144,6 @@ static void blkcg_print_one_stat(struct blkcg_gq *blkg, struct seq_file *s)
> struct blkg_iostat_set *bis = &blkg->iostat;
> u64 rbytes, wbytes, rios, wios, dbytes, dios;
> const char *dname;
> - unsigned seq;
> int i;
>
> if (!blkg->online)
> @@ -1157,16 +1155,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);
> -
> - 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));
> + raw_spin_lock_irq(&blkg_stat_lock);
> + 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];
> + raw_spin_unlock_irq(&blkg_stat_lock, flags);
>
> if (rbytes || wbytes || rios || wios) {
> seq_printf(s, "rbytes=%llu wbytes=%llu rios=%llu wios=%llu dbytes=%llu dios=%llu",
>
bis->sync is still being used in blk_cgroup_bio_start(). Replacing it
with a global lock may kill performance. We may have to use a per-cpu
lock if we want to go this route of eliminating bis->sync.
Cheers,
Longman
next prev parent reply other threads:[~2024-07-17 17:38 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
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 [this message]
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=f448f66b-7a91-4281-8f77-159541cbacff@redhat.com \
--to=longman@redhat.com \
--cc=Boy.Wu@mediatek.com \
--cc=Iverlin.Wang@mediatek.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=axboe@kernel.dk \
--cc=boris@bur.io \
--cc=cgroups@vger.kernel.org \
--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 \
--cc=tj@kernel.org \
/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