[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YxoVKVVfnrq3js9O@fedora>
Date: Thu, 8 Sep 2022 09:15:37 -0700
From: Dennis Zhou <dennis@...nel.org>
To: Andrew Morton <akpm@...ux-foundation.org>
Cc: "Sun, Jiebin" <jiebin.sun@...el.com>,
Tim Chen <tim.c.chen@...ux.intel.com>, vasily.averin@...ux.dev,
shakeelb@...gle.com, tj@...nel.org, cl@...ux.com,
ebiederm@...ssion.com, legion@...nel.org, manfred@...orfullife.com,
alexander.mikhalitsyn@...tuozzo.com, linux-mm@...ck.org,
linux-kernel@...r.kernel.org, tim.c.chen@...el.com,
feng.tang@...el.com, ying.huang@...el.com, tianyou.li@...el.com,
wangyang.guo@...el.com
Subject: Re: [PATCH v4] ipc/msg: mitigate the lock contention with percpu
counter
Hello,
On Thu, Sep 08, 2022 at 08:38:59AM -0700, Andrew Morton wrote:
> On Thu, 8 Sep 2022 16:25:47 +0800 "Sun, Jiebin" <jiebin.sun@...el.com> wrote:
>
> > In our case, if the local
> > percpu counter is near to INT_MAX and there comes a big msgsz, the
> > overflow issue could happen.
>
> percpu_counter_add_batch() handles this - your big message
> won't overflow an s64.
>
>
> Lookng at percpu_counter_add_batch(), is this tweak right?
>
> - don't need to update *fbc->counters inside the lock
> - that __this_cpu_sub() is an obscure way of zeroing the thing
>
> --- a/lib/percpu_counter.c~a
> +++ a/lib/percpu_counter.c
> @@ -89,8 +89,8 @@ void percpu_counter_add_batch(struct per
> unsigned long flags;
> raw_spin_lock_irqsave(&fbc->lock, flags);
> fbc->count += count;
> - __this_cpu_sub(*fbc->counters, count - amount);
> raw_spin_unlock_irqrestore(&fbc->lock, flags);
> + __this_cpu_write(*fbc->counters, 0);
I don't think this is irq safe. It'd be best to leave it inside the
spinlock as then we can use __this_cpu_write() to 0 in there.
> } else {
> this_cpu_add(*fbc->counters, amount);
> }
> _
>
Thanks,
Dennis
Powered by blists - more mailing lists