mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel.org>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Christoph Lameter <cl@linux.com>,
	Pekka Enberg <penberg@kernel.org>, Ingo Molnar <mingo@elte.hu>,
	Jens Axboe <axboe@kernel.dk>,
	Andrew Morton <akpm@linux-foundation.org>,
	werner <w.landgraf@ru.ru>, "H. Peter Anvin" <hpa@zytor.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [block IO crash] Re: 2.6.39-rc5-git2 boot crashs
Date: Thu, 5 May 2011 11:54:21 +0200	[thread overview]
Message-ID: <20110505095421.GD30950@htj.dyndns.org> (raw)
In-Reply-To: <alpine.LFD.2.02.1105042325500.3005@ionos>

Hey,

On Wed, May 04, 2011 at 11:40:33PM +0200, Thomas Gleixner wrote:
> Yeah, I tripped over that as well. And the new shiny extra
> CONFIG_CMPXCHG_DOUBLE misfeature Christoph nailed together is just
> ignoring it as well. It's just more useless #ifdef and CONFIG bloat.
> 
> That whole this_cpu_* stuff seems to be designed by committee. A quick
> grep shows that max. 10% of the implemented macro hell is actually
> used. Can we get rid of all unused ones and bring them back when they
> are actually required?

What happened there was more of lack of design rather than too much
design.  At first it were a few ops with only two variants -
preemption protected default one and __ prefixed unprotected one.
Then came the irqsafe ops and then the whole kinda exploded on itself
with all the different ops.

Cleaning up percpu accessors has been on my todo list for some time
now.  The this_cpu_*() thing is still in its infancy and there aren't
many users and the existing ones are mostly in the core, so cleaning
things up should be relatively easy.  Things which I've been
considering are...

1. Static and dynamic accessors.

We have two sets of percpu accessors.  Originally, one set was for
static percpu variables and the other for dynamic ones.  Since the
percpu allocator reimplementation, there's no distinction between
static and dynamic and the new this_cpu_*() functions don't
distinguish them.  We need to unify the duplicate ones.  There's
nothing much to decide about this.  It just needs to be done.

2. this_cpu_*()

This one is more tricky.  General cleanup aside...

this_cpu_*() ops currently come in three flavors and the naming
convention is rather confusing.  __this_cpu for no protection,
this_cpu for preemtion disabled and irqsafe_cpu for irq protected.
IIUC it was intended to loosely match the naming convention of
spinlocks but I'm not sure whether that's beneficial in this case.

The biggest problem, as shown by this bug, is that it's error-prone.
Percpu ops as they currently stand don't have lockdep protection for
accessing contexts.  There's nothing protecting percpu vars being
accessed from wrong contexts.  I think adding lockdep protection
should be doable and should be done, but it would be much better if
it's safer by default.

The problem is aggravated by the fact that, on x86 where most of
developement and testing happens, there's no difference between
__this_cpu_*(), this_cpu_*() and irqsafe_cpu_*().  They're one and the
same, so testing coverage suffers.  We can avoid this by adding a
debug option which forces the generic versions whether the arch ones
are there or not, but it does raise the question - do we really need
all these different confusing variants?

For x86, it doesn't matter.  There are some corner cases with
cmpxchg_[double] but I don't think we would be in any trouble just
using the generic ones for them.  The problem is with other archs
where local atomic ops haven't been or, for most load-store
architectures, can't be implemented.  We might say "eh... screw them"
and let them use the generic ones but the problem is that this_cpu_*()
tend to be used in extremely hot paths where extra irq on/off's can
show up as significant overhead.

The thing that I want gone the most is the irqsafe_ variant.  It would
be much nicer/safer if this_cpu_*() is atomic against everything.  If
the caller is gonna take care of exclusion from the enclosing area
(this is a valid use case when there's a series of operations to be
done including but not limited to multiple this_cpu ops), it can use
__this_cpu_*() ones.

The reason to disable preemtion instead of IRQ is two-fold - First,
preemption can be disabled for longer period than IRQ.  Second,
depending on CPU, toggling preemption is significantly cheaper than
toggling preemption.  For this_cpu ops, the first one doesn't apply.
It's always very short, so the only thing that needs to be considered
is the overhead of toggling protection.

So, to avoid suffering performance penalty from this_cpu_*()
conversion, architectures can choose one of the followings.

1. Implement arch specific this_cpu_*() ops.  This would be the better
   way but unfortunately many architectures simply can't.  :-(

2. Make irq toggling as cheap as preemption toggling.  This can be
   achieved by implementing IRQ masking in software.  I played with it
   a bit on x86 last year.  I didn't get to finish it and it would
   have taken me some time to iron out weird failures but it didn't
   seem too difficult and as irq on/off is quite expensive on a lot of
   CPUs, this might bring overall performance benefit.

For many archs, #2 would be the only choice and if we're gonna do that
I think it would be best to do it on x86 too.  It involves changes to
common code too and x86 has the highest test/development coverage.

I don't feel brave enough to remove preemption protected ones without
first somehow taking care of non-x86 archs.  The preemption disabled
ones are used for statistics in net, block, irq and fs and simply
switching to irq protected ones is likely to noticeably hurt many
non-x86 archs.  Maybe the ones which really matter can implement at
least _add() and we can get away without doing soft irq masking.

Anyways, that's what I've been thinking.  I'll get to it in the next
devel cycle or the one after that.  What do you guys think about soft
irq masking idea?

Thanks.

--
tejun

  reply	other threads:[~2011-05-05  9:54 UTC|newest]

Thread overview: 83+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-02 22:28 werner
2011-05-02 23:24 ` Linus Torvalds
     [not found]   ` <web-516990066@zbackend1.aha.ru>
2011-05-03 15:22     ` Linus Torvalds
2011-05-03 19:08       ` Ingo Molnar
2011-05-03 20:17         ` Linus Torvalds
2011-05-03 20:20           ` H. Peter Anvin
2011-05-03 20:50             ` Ingo Molnar
2011-05-03 21:45               ` Linus Torvalds
2011-05-03 22:01                 ` H. Peter Anvin
2011-05-04  7:19                 ` Borislav Petkov
2011-05-04  7:38                   ` Ingo Molnar
2011-05-04  7:55                     ` Borislav Petkov
2011-05-04  8:35           ` [block IO crash] " Ingo Molnar
2011-05-04  9:52             ` Thomas Gleixner
2011-05-04 10:19               ` Ingo Molnar
2011-05-04 10:25                 ` Ingo Molnar
2011-05-04 10:33                   ` Ingo Molnar
2011-05-04 12:37                     ` Ingo Molnar
2011-05-04 12:36                   ` Ingo Molnar
2011-05-04 11:11                 ` Thomas Gleixner
2011-05-04 11:16                   ` Pekka Enberg
2011-05-04 11:27                     ` Tejun Heo
2011-05-04 12:51                       ` Pekka Enberg
2011-05-04 12:57                         ` Ingo Molnar
2011-05-04 13:02                           ` Thomas Gleixner
2011-05-04 13:00                       ` Thomas Gleixner
2011-05-04 13:20                         ` Tejun Heo
2011-05-04 14:10                           ` Thomas Gleixner
2011-05-04 14:14                             ` Ingo Molnar
2011-05-04 14:36                               ` [PATCH] slub: Fix the lockless code on 32-bit platforms with no 64-bit cmpxchg Ingo Molnar
2011-05-04 14:42                                 ` Christoph Lameter
2011-05-04 16:30                                 ` Ingo Molnar
2011-05-04 21:52                                 ` Ben Greear
2011-05-04 22:00                                   ` Linus Torvalds
2011-05-04 22:22                                     ` Ben Greear
2011-05-04 14:19                             ` [block IO crash] Re: 2.6.39-rc5-git2 boot crashs Christoph Lameter
2011-05-04 14:25                             ` Tejun Heo
2011-05-04 14:35                               ` Christoph Lameter
2011-05-04 15:20                                 ` Ingo Molnar
2011-05-04 14:46                               ` Thomas Gleixner
2011-05-04 15:00                                 ` Christoph Lameter
2011-05-04 15:13                                   ` Linus Torvalds
2011-05-04 15:28                                     ` Christoph Lameter
2011-05-04 15:37                                       ` Pekka Enberg
2011-05-04 15:53                                         ` Linus Torvalds
2011-05-04 18:20                                           ` Linus Torvalds
2011-05-04 18:49                                             ` Christoph Lameter
2011-05-04 19:07                                               ` Linus Torvalds
2011-05-04 19:30                                                 ` Christoph Lameter
2011-05-04 19:38                                                   ` Linus Torvalds
2011-05-04 20:04                                                     ` Christoph Lameter
2011-05-04 20:21                                                       ` Valdis.Kletnieks
2011-05-04 20:32                                                         ` Christoph Lameter
2011-05-04 20:49                                                           ` Ingo Molnar
2011-05-04 21:06                                                       ` Linus Torvalds
2011-05-04 21:19                                                         ` Linus Torvalds
2011-05-04 21:40                                                           ` Thomas Gleixner
2011-05-05  9:54                                                             ` Tejun Heo [this message]
2011-05-05 10:18                                                               ` Ingo Molnar
2011-05-05 10:45                                                               ` Thomas Gleixner
2011-05-05 18:20                                                               ` Christoph Lameter
2011-05-05 19:13                                                                 ` Ingo Molnar
2011-05-05 19:53                                                               ` werner
2011-05-05 20:09                                                                 ` Christoph Lameter
2011-05-05 21:12                                                                   ` werner
2011-05-05 22:27                                                                     ` Thomas Gleixner
     [not found]                                             ` <web-518008166@zbackend1.aha.ru>
     [not found]                                               ` <web-518059420@zbackend1.aha.ru>
     [not found]                                                 ` <20110505060204.GA28015@elte.hu>
2011-05-05  6:46                                                   ` werner
2011-05-04 15:37                                       ` [block IO crash] " Linus Torvalds
2011-05-04 16:08                                         ` Christoph Lameter
2011-05-04 16:50                                     ` Ingo Molnar
2011-05-04 17:12                                       ` Thomas Gleixner
2011-05-04 15:41                                   ` Pekka Enberg
2011-05-04 13:22                         ` Ingo Molnar
2011-05-04 14:21                         ` Christoph Lameter
2011-05-04 14:04                     ` Christoph Lameter
2011-05-04 14:07                       ` Tejun Heo
2011-05-04 14:21                       ` Thomas Gleixner
2011-05-04 10:13             ` Ingo Molnar
2011-05-04 10:41               ` Ingo Molnar
2011-05-04 10:45                 ` Ingo Molnar
2011-05-04 11:06                   ` Ingo Molnar
2011-05-04 12:37                     ` Ingo Molnar
2011-05-04 12:47                       ` Ingo Molnar

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=20110505095421.GD30950@htj.dyndns.org \
    --to=tj@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=axboe@kernel.dk \
    --cc=cl@linux.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=penberg@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --cc=w.landgraf@ru.ru \
    /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

Powered by JetHome