Re: [PATCH v4 2/2] blk-cgroup: Flush stats at blkgs destruction path

From: Tejun Heo
Date: Thu Feb 02 2023 - 17:35:19 EST


On Thu, Feb 02, 2023 at 12:15:52PM +0800, Ming Lei wrote:
> > @@ -1093,6 +1095,20 @@ static void blkcg_destroy_blkgs(struct blkcg *blkcg)
> >
> > might_sleep();
> >
> > + /*
> > + * Flush all the non-empty percpu lockless lists to release the
> > + * blkg references held by those lists which, in turn, will
> > + * allow those blkgs to be freed and release their references to
> > + * blkcg. Otherwise, they may not be freed at all becase of this
> > + * circular dependency resulting in memory leak.
> > + */
> > + for_each_possible_cpu(cpu) {
> > + struct llist_head *lhead = per_cpu_ptr(blkcg->lhead, cpu);
> > +
> > + if (!llist_empty(lhead))
> > + cgroup_rstat_css_cpu_flush(&blkcg->css, cpu);
> > + }
>
> I guess it is possible for new iostat_cpu to be added just after the
> llist_empty() check.

Ah, good point. Maybe:

* Move flush below the blkg kill loop.

* In blk_cgroup_bio_start(), use percpu_ref_tryget() to decide whether to
add to llist or not.

--
tejun