All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel.org>
To: Nikolay Borisov <nborisov@suse.com>
Cc: jbacik@fb.com, linux-kernel@vger.kernel.org, mgorman@techsingularity.net
Subject: Re: [PATCH v2 2/2] writeback: Rework wb_[dec|inc]_stat family of functions
Date: Tue, 20 Jun 2017 16:30:49 -0400	[thread overview]
Message-ID: <20170620203049.GH21326@htj.duckdns.org> (raw)
In-Reply-To: <274063e4-57d0-5a87-1f43-28f5232af52b@suse.com>

Hello,

On Tue, Jun 20, 2017 at 11:28:30PM +0300, Nikolay Borisov wrote:
> > Heh, looks like I was confused.  __percpu_counter_add() is not
> > irq-safe.  It disables preemption and uses __this_cpu_read(), so
> > there's no protection against irq.  If writeback statistics want
> > irq-safe operations and it does, it would need these separate
> > operations.  Am I missing something?
> 
> So looking at the history of the commit initially there was
> preempt_disable + this_cpu_ptr which was later changed in:
> 
> 819a72af8d66 ("percpucounter: Optimize __percpu_counter_add a bit
> through the use of this_cpu() options.")
> 
> I believe that having __this_cpu_read ensures that we get an atomic
> snapshot of the variable but when we are doing the actual write e.g. the
> else {} branch we actually use this_cpu_add which ought to be preempt +
> irq safe, meaning we won't get torn write. In essence we have atomic
> reads by merit of __this_cpu_read + atomic writes by merit of using
> raw_spin_lock_irqsave in the if() branch and this_cpu_add in the else {}
> branch.

Ah, you're right.  The initial read is speculative.  The slow path is
protected with irq spinlock.  The fast path is this_cpu_add() which is
irq-safe.  We really need to document these functions.

Can I bother you with adding documentation to them while you're at it?

Thanks.

-- 
tejun

  reply	other threads:[~2017-06-20 20:30 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-20 11:36 [PATCH 1/2] percpu_counter: Rename __percpu_counter_add to percpu_counter_add_batch Nikolay Borisov
2017-06-20 11:36 ` [PATCH 2/2] writeback: Rework wb_[dec|inc]_stat family of functions Nikolay Borisov
2017-06-20 17:33   ` Tejun Heo
2017-06-20 18:02     ` [PATCH v2 " Nikolay Borisov
2017-06-20 19:37       ` Tejun Heo
2017-06-20 20:28         ` Nikolay Borisov
2017-06-20 20:30           ` Tejun Heo [this message]
2017-06-20 20:32             ` Nikolay Borisov
2017-06-21  7:25             ` [PATCH v3] " Nikolay Borisov
2017-06-21 15:59               ` Tejun Heo
2017-06-22  8:38                 ` Jan Kara
2017-06-21  0:05   ` [PATCH 2/2] " kbuild test robot
2017-06-20 17:28 ` [PATCH 1/2] percpu_counter: Rename __percpu_counter_add to percpu_counter_add_batch Tejun Heo
2017-06-20 18:01   ` [PATCH v2 " Nikolay Borisov
2017-06-20 19:47     ` [PATCH] " Tejun Heo
2017-06-20 19:47       ` Tejun Heo
2017-06-20 19:55       ` David Miller
2017-06-20 19:55         ` David Miller
2017-06-21  1:14       ` Darrick J. Wong
2017-06-21  1:14         ` Darrick J. Wong
2017-06-21 12:08       ` David Sterba
2017-06-21 12:08         ` David Sterba

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=20170620203049.GH21326@htj.duckdns.org \
    --to=tj@kernel.org \
    --cc=jbacik@fb.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@techsingularity.net \
    --cc=nborisov@suse.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.