From: Huang Ying <ying.huang@intel.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Len Brown <lenb@kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Andi Kleen <andi@firstfloor.org>,
"linux-acpi@vger.kernel.org" <linux-acpi@vger.kernel.org>,
Linus Torvalds <torvalds@linux-foundation.org>,
Thomas Gleixner <tglx@linutronix.de>, Ingo Molnar <mingo@elte.hu>,
Mauro Carvalho Chehab <mchehab@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Steven Rostedt <rostedt@goodmis.org>
Subject: Re: [PATCH -v4 1/2] lib, Make gen_pool memory allocator lockless
Date: Wed, 17 Nov 2010 14:05:14 +0800 [thread overview]
Message-ID: <1289973914.8719.1261.camel@yhuang-dev> (raw)
In-Reply-To: <20101116195720.23287038.akpm@linux-foundation.org>
On Wed, 2010-11-17 at 11:57 +0800, Andrew Morton wrote:
> On Wed, 17 Nov 2010 11:03:25 +0800 Huang Ying <ying.huang@intel.com> wrote:
>
> > It seems that Steven thinks many architectures without NMI-safe cmpxchg
> > have no real NMI too.
>
> Could be.
>
> Really, we should nail this down and work out the matrix of
> what-works-with-what, and then arrange for the things which _won't_
> work to be either non-Kconfigurable or non-compilable.
Yes. I will try to work out a draft matrix for review firstly.
> The worst thing we could do would be to advertise some code as
> "nmi-safe!!", then to have someone go and use it on that basis, only
> for their users to later discover ghastly rare races.
Yes.
> > In the patch description and comments, it is said that on architectures
> > without NMI-safe cmpxchg, gen_pool can not be used in NMI handler
> > safely.
> >
> > Or do you think it is better to use a spin_trylock based fallback if
> > NMI-safe cmpxchg is not available? Or require cmpxchg implementation
> > uses spin_trylock instead of spin_lock?
>
> As a first step, a typical thing to do would be to create
> CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG, define that in the appropriate
> architectures, make ftrace and perf and genpool and anything else
> dependent upon that at Kconfig-time.
Yes. At least lockless list should depend on that. And we need select
between cmpxchg and spin_trylock_irqsave based on that.
Hi, Peter,
Do you think think irq_work should depend on that? Or we just
reimplement irq_work based on lockless list and make irq_work depends on
lockless list?
> A spin_trylock_irqsave() implementation would do what? Rarely fail the
> memory allocation attempt if the trylock failed? I guess that's
> acceptable in the context of gen_pool, because memory allocators are
> expected to fail, and everyone carefully tests the allocation-failed
> error paths (lol).
Yes. I will implement the fallback for gen_pool.
> But rare failures may not be useful within the context of future
> clients of the "lockless" list implementation so I'd say that a safer
> approach would be to make the list implementation require
> CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG and be done with it.
Yes.
> So that's all pretty simple so far. However...
>
> The list implementation is still useful to
> non-CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG clients, as long as they aren't
> using it from NMI context, yes?
>
> In which case I suppose we could add a library of lockless_list_foo()
> functions which are usable from non-NMI contexts and which are
> available to all configs. And on top of that implement a library of
> nmi_safe_lockless_list_foo() functions which are just wrappers around
> lockless_list_foo(), but which are only available if
> CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG=y.
>
> Which is getting to be a bit of a pain, so you might choose to
> disregard everything after "However..." ;)
At least as the first step, I prefer to just make lockless list depend
on CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG.
Best Regards,
Huang Ying
next prev parent reply other threads:[~2010-11-17 6:05 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-16 0:53 [PATCH -v4 0/2] Lockless memory allocator and list Huang Ying
2010-11-16 0:53 ` [PATCH -v4 1/2] lib, Make gen_pool memory allocator lockless Huang Ying
2010-11-16 21:50 ` Andrew Morton
2010-11-17 2:18 ` Huang Ying
2010-11-17 2:35 ` Andrew Morton
2010-11-17 3:03 ` Huang Ying
2010-11-17 3:57 ` Andrew Morton
2010-11-17 6:05 ` Huang Ying [this message]
2010-11-17 10:49 ` Peter Zijlstra
2010-11-17 11:16 ` huang ying
2010-11-17 11:38 ` Peter Zijlstra
2010-11-17 10:40 ` Peter Zijlstra
2010-11-17 11:47 ` huang ying
2010-11-17 11:53 ` Peter Zijlstra
2010-11-18 1:14 ` Huang Ying
2010-11-18 8:34 ` Peter Zijlstra
2010-11-18 8:43 ` Paul Mundt
2010-11-18 8:57 ` Peter Zijlstra
2010-11-18 9:03 ` Paul Mundt
2010-11-16 0:53 ` [PATCH -v4 2/2] lib, Add lock-less NULL terminated single list Huang Ying
2010-11-16 11:50 ` Peter Zijlstra
2010-11-16 16:33 ` Linus Torvalds
2010-11-16 11:49 ` [PATCH -v4 0/2] Lockless memory allocator and list Peter Zijlstra
2010-11-16 16:38 ` Linus Torvalds
2010-11-16 18:04 ` Peter Zijlstra
2010-11-17 1:45 ` Huang Ying
2010-11-17 1:03 ` Huang Ying
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=1289973914.8719.1261.camel@yhuang-dev \
--to=ying.huang@intel.com \
--cc=akpm@linux-foundation.org \
--cc=andi@firstfloor.org \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mchehab@redhat.com \
--cc=mingo@elte.hu \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
/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;
as well as URLs for NNTP newsgroup(s).