Re: [PATCH 2/3] cgroup: make css_rstat_updated nmi safe

From: Tejun Heo
Date: Tue Jun 10 2025 - 17:26:52 EST


Hello,

On Mon, Jun 09, 2025 at 03:56:10PM -0700, Shakeel Butt wrote:
...
> + self = &rstatc->lnode;
> + if (!try_cmpxchg(&(rstatc->lnode.next), &self, NULL))
> return;
>
> + llist_add(&rstatc->lnode, lhead);

I may be missing something but when you say multiple inserters, you mean the
function being re-entered from stacked contexts - ie. process context, BH,
irq, nmi? If so, would it make sense to make the nmi and non-nmi paths use
separate lnode? In non-nmi path, we can just disable irq and test whether
lnode is empty and add it. nmi path can just test whether its lnode is empty
and add it. I suppose nmi's don't nest, right? If they do, we can do
try_cmpxchg() there I suppose.

While the actual addition to the list would be relatively low frequency,
css_rstat_updated() itself can be called pretty frequently. Before, the hot
path was early exit after data_race(css_rstat_cpu(css, cpu)->updated_next).
After, the hot path is now !try_cmpxchg() which doesn't seem great.

Thanks.

--
tejun