* Avoiding the dentry d_lock on final dput(), part deux: transactional memory
@ 2013-09-30 19:29 Linus Torvalds
2013-09-30 20:01 ` Waiman Long
2013-09-30 22:52 ` Benjamin Herrenschmidt
0 siblings, 2 replies; 12+ messages in thread
From: Linus Torvalds @ 2013-09-30 19:29 UTC (permalink / raw)
To: Ingo Molnar, Peter Zijlstra, Waiman Long, Benjamin Herrenschmidt
Cc: Norton, Scott J, Linux Kernel Mailing List,
Chandramouleeswaran, Aswin, George Spelvin, linux-fsdevel,
ppc-dev
[-- Attachment #1: Type: text/plain, Size: 3956 bytes --]
So with all the lockref work, we now avoid the dentry d_lock for
almost all normal cases.
There is one single remaining common case, though: the final dput()
when the dentry count goes down to zero, and we need to check if we
are supposed to get rid of the dentry (or at least put it on the LRU
lists etc).
And that's something lockref itself cannot really help us with unless
we start adding status bits to it (eg some kind of "enable slow-case"
bit in the lock part of the lockref). Which sounds like a clever but
very fragile approach.
However, I did get myself a i7-4770S exactly because I was
forward-thinking, and wanted to try using transactional memory for
these kinds of things.
Quite frankly, from all I've seen so far, the kernel is not going to
have very good luck with things like lock elision, because we're
really fine-grained already, and at least the Intel lock-elision
(don't know about POWER8) basically requires software to do prediction
on whether the transaction will succeed or not, dynamically based on
aborts etc. And quite frankly, by the time you have to do things like
that, you've already lost. We're better off just using our normal
locks.
So as far as I'm concerned, transactional memory is going to be useful
- *if* it is useful - only for specialized code. Some of that might be
architecture-internal lock implementations, other things might be
exactly the dput() kind of situation.
And the thing is, *normally* dput() doesn't need to do anything at
all, except decrement the dentry reference count. However, for that
normal case to be true, we need to atomically check:
- that the dentry lock isn't held (same as lockref)
- that we are already on the LRU list and don't need to add ourselves to it
- that we already have the DCACHE_REFERENCED bit set and don't need to set it
- that the dentry isn't unhashed and needs to be killed.
Additionally, we need to check that it's not a dentry that has a
"d_delete()" operation, but that's a static attribute of a dentry, so
that's not something that we need to check atomically wrt the other
things.
ANYWAY. With all that out of the way, the basic point is that this is
really simple, and fits very well with even very limited transactional
memory. We literally need to do just a single write, and something
like three reads from memory. And we already have a trivial fallback,
namely the old code using the lockrefs. IOW, it's literally ten
straight-line instructions between the xbegin and the xend for me.
So here's a patch that works for me. It requires gcc to know "asm
goto", and it requires binutils that know about xbegin/xabort. And it
requires a CPU that supports the intel RTM extensions.
But I'm cc'ing the POWER people, because I don't know the POWER8
interfaces, and I don't want to necessarily call this "xbegin"/"xend"
when I actually wrap it in some helper functions.
Anyway, profiles with this look beautiful (I'm using "make -j" on a
fully built allmodconfig kernel tree as the source of profile data).
There's no spinlocks from dput at all, and the dput() profile itself
shows basically 1% in anything but the fastpath (probably the _very_
occasional first accesses where we need to add things to the LRU
lists).
And the patch is small, but is obviously totally lacking any test for
CPU support or anything like that. Or portability. But I thought I'd
get the ball rolling, because I doubt the intel TSX patches are going
to be useful (if they were, Intel would be crowing about performance
numbers now that the CPU's are out, and they aren't).
I don't know if the people doing HP performance testing have
TSX-enabled machines, but hey, maybe. So you guys are cc'd too.
I also didn't actually check if performance is affected. I doubt it is
measurable on this machine, especially on "make -j" that spends 90% of
its time in user space. But the profile comparison really does make it
look good..
Comments?
Linus
[-- Attachment #2: patch.diff --]
[-- Type: application/octet-stream, Size: 1614 bytes --]
fs/dcache.c | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/fs/dcache.c b/fs/dcache.c
index 41000305d716..c988806b941e 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -603,6 +603,9 @@ relock:
* Real recursion would eat up our stack space.
*/
+#define is_simple_dput(dentry) \
+ (((dentry)->d_flags & (DCACHE_REFERENCED |DCACHE_LRU_LIST)) == (DCACHE_REFERENCED |DCACHE_LRU_LIST))
+
/*
* dput - release a dentry
* @dentry: dentry to release
@@ -617,6 +620,35 @@ void dput(struct dentry *dentry)
if (unlikely(!dentry))
return;
+ /*
+ * Try RTM for the trivial - and common - case.
+ *
+ * We don't do this for DCACHE_OP_DELETE (which is a static flag,
+ * so check it outside the transaction), and we require that the
+ * dentry is already marked referenced and on the LRU list.
+ *
+ * If that is true, and the dentry is not locked, we can just
+ * decrement the usage count.
+ *
+ * This is kind of a special super-case of lockref_put(), but
+ * atomically testing the dentry flags to make sure that there
+ * is nothing else we need to look at.
+ */
+ if (unlikely(dentry->d_flags & DCACHE_OP_DELETE))
+ goto repeat;
+ asm goto("xbegin %l[repeat]": : :"memory","ax":repeat);
+ if (unlikely(d_unhashed(dentry)))
+ goto xabort;
+ if (unlikely(!is_simple_dput(dentry)))
+ goto xabort;
+ if (unlikely(!arch_spin_value_unlocked(dentry->d_lock.rlock.raw_lock)))
+ goto xabort;
+ dentry->d_lockref.count--;
+ asm volatile("xend");
+ return;
+
+xabort:
+ asm volatile("xabort $0");
repeat:
if (lockref_put_or_lock(&dentry->d_lockref))
return;
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: Avoiding the dentry d_lock on final dput(), part deux: transactional memory
2013-09-30 19:29 Avoiding the dentry d_lock on final dput(), part deux: transactional memory Linus Torvalds
@ 2013-09-30 20:01 ` Waiman Long
2013-09-30 20:04 ` Linus Torvalds
2013-09-30 22:52 ` Benjamin Herrenschmidt
1 sibling, 1 reply; 12+ messages in thread
From: Waiman Long @ 2013-09-30 20:01 UTC (permalink / raw)
To: Linus Torvalds
Cc: Peter Zijlstra, George Spelvin, Linux Kernel Mailing List,
Chandramouleeswaran, Aswin, Norton, Scott J, linux-fsdevel,
ppc-dev, Ingo Molnar
On 09/30/2013 03:29 PM, Linus Torvalds wrote:
> So with all the lockref work, we now avoid the dentry d_lock for
> almost all normal cases.
>
> There is one single remaining common case, though: the final dput()
> when the dentry count goes down to zero, and we need to check if we
> are supposed to get rid of the dentry (or at least put it on the LRU
> lists etc).
>
> And that's something lockref itself cannot really help us with unless
> we start adding status bits to it (eg some kind of "enable slow-case"
> bit in the lock part of the lockref). Which sounds like a clever but
> very fragile approach.
>
> However, I did get myself a i7-4770S exactly because I was
> forward-thinking, and wanted to try using transactional memory for
> these kinds of things.
>
> Quite frankly, from all I've seen so far, the kernel is not going to
> have very good luck with things like lock elision, because we're
> really fine-grained already, and at least the Intel lock-elision
> (don't know about POWER8) basically requires software to do prediction
> on whether the transaction will succeed or not, dynamically based on
> aborts etc. And quite frankly, by the time you have to do things like
> that, you've already lost. We're better off just using our normal
> locks.
>
> So as far as I'm concerned, transactional memory is going to be useful
> - *if* it is useful - only for specialized code. Some of that might be
> architecture-internal lock implementations, other things might be
> exactly the dput() kind of situation.
>
> And the thing is, *normally* dput() doesn't need to do anything at
> all, except decrement the dentry reference count. However, for that
> normal case to be true, we need to atomically check:
>
> - that the dentry lock isn't held (same as lockref)
> - that we are already on the LRU list and don't need to add ourselves to it
> - that we already have the DCACHE_REFERENCED bit set and don't need to set it
> - that the dentry isn't unhashed and needs to be killed.
>
> Additionally, we need to check that it's not a dentry that has a
> "d_delete()" operation, but that's a static attribute of a dentry, so
> that's not something that we need to check atomically wrt the other
> things.
>
> ANYWAY. With all that out of the way, the basic point is that this is
> really simple, and fits very well with even very limited transactional
> memory. We literally need to do just a single write, and something
> like three reads from memory. And we already have a trivial fallback,
> namely the old code using the lockrefs. IOW, it's literally ten
> straight-line instructions between the xbegin and the xend for me.
>
> So here's a patch that works for me. It requires gcc to know "asm
> goto", and it requires binutils that know about xbegin/xabort. And it
> requires a CPU that supports the intel RTM extensions.
>
> But I'm cc'ing the POWER people, because I don't know the POWER8
> interfaces, and I don't want to necessarily call this "xbegin"/"xend"
> when I actually wrap it in some helper functions.
>
> Anyway, profiles with this look beautiful (I'm using "make -j" on a
> fully built allmodconfig kernel tree as the source of profile data).
> There's no spinlocks from dput at all, and the dput() profile itself
> shows basically 1% in anything but the fastpath (probably the _very_
> occasional first accesses where we need to add things to the LRU
> lists).
>
> And the patch is small, but is obviously totally lacking any test for
> CPU support or anything like that. Or portability. But I thought I'd
> get the ball rolling, because I doubt the intel TSX patches are going
> to be useful (if they were, Intel would be crowing about performance
> numbers now that the CPU's are out, and they aren't).
>
> I don't know if the people doing HP performance testing have
> TSX-enabled machines, but hey, maybe. So you guys are cc'd too.
The Xeon class CPUs are typically about one year behind the consumer CPU
chips. We are testing large NUMA machine with IvyBridge-EX CPUs right
now. Haswell-EX has to be at least one year out. So we don't have the
hardware to do the testing at the moment.
> I also didn't actually check if performance is affected. I doubt it is
> measurable on this machine, especially on "make -j" that spends 90% of
> its time in user space. But the profile comparison really does make it
> look good..
>
> Comments?
>
> Linus
I think this patch is worth a trial if relevant hardware is more widely
available. The TSX code certainly need to be moved to an architecture
specific area and should be runtime enabled using a static key. We also
need more TSX support infrastructure in place first.
-Longman
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Avoiding the dentry d_lock on final dput(), part deux: transactional memory
2013-09-30 20:01 ` Waiman Long
@ 2013-09-30 20:04 ` Linus Torvalds
2013-10-02 14:56 ` Andi Kleen
0 siblings, 1 reply; 12+ messages in thread
From: Linus Torvalds @ 2013-09-30 20:04 UTC (permalink / raw)
To: Waiman Long
Cc: Peter Zijlstra, George Spelvin, Linux Kernel Mailing List,
Chandramouleeswaran, Aswin, Norton, Scott J, linux-fsdevel,
ppc-dev, Ingo Molnar
On Mon, Sep 30, 2013 at 1:01 PM, Waiman Long <waiman.long@hp.com> wrote:
>
> I think this patch is worth a trial if relevant hardware is more widely
> available. The TSX code certainly need to be moved to an architecture
> specific area and should be runtime enabled using a static key. We also need
> more TSX support infrastructure in place first.
I think we can pick that up from Andi's patches, he should have that.
Although that did have very x86-specific naming (ie "xbegin"). And I
don't think he used "asm goto" to quite the same advantage as this -
and I think we do want to make sure that the overhead is minimal.
Linus
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Avoiding the dentry d_lock on final dput(), part deux: transactional memory
2013-09-30 20:04 ` Linus Torvalds
@ 2013-10-02 14:56 ` Andi Kleen
0 siblings, 0 replies; 12+ messages in thread
From: Andi Kleen @ 2013-10-02 14:56 UTC (permalink / raw)
To: Linus Torvalds
Cc: Waiman Long, Peter Zijlstra, Norton, Scott J, George Spelvin,
Linux Kernel Mailing List, Chandramouleeswaran, Aswin,
linux-fsdevel, ppc-dev, Ingo Molnar
Linus Torvalds <torvalds@linux-foundation.org> writes:
> On Mon, Sep 30, 2013 at 1:01 PM, Waiman Long <waiman.long@hp.com> wrote:
>>
>> I think this patch is worth a trial if relevant hardware is more widely
>> available. The TSX code certainly need to be moved to an architecture
>> specific area and should be runtime enabled using a static key. We also need
>> more TSX support infrastructure in place first.
>
> I think we can pick that up from Andi's patches, he should have that.
> Although that did have very x86-specific naming (ie "xbegin"). And I
> don't think he used "asm goto" to quite the same advantage as this -
> and I think we do want to make sure that the overhead is minimal.
FWIW my version #0 used asm goto directly, but I later switched to not
using it to support more compilers and higher level abstractions (locks
etc.) and use the same intrinsics as the user level guys are using.
The two extra instructions from not using asm goto for xbegin
don't matter all that much in the end.
That's the old asm goto stuff I wrote originally
(user level version):
https://github.com/andikleen/tsx-tools/blob/master/include/rtm-goto.h
There was also a kernel version of it that patched, right
now this is done in the main TSX patchkit like this:
https://git.kernel.org/cgit/linux/kernel/git/ak/linux-misc.git/commit/?h=hle312/rtm-base&id=9190346d57a9bc89e746aee774d07e54cd1e6e75
Essentially without RTM it just becomes and unconditional jump
to the abort handler, xabort is a nop, and xtest always returns 0.
-Andi
--
ak@linux.intel.com -- Speaking for myself only
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Avoiding the dentry d_lock on final dput(), part deux: transactional memory
2013-09-30 19:29 Avoiding the dentry d_lock on final dput(), part deux: transactional memory Linus Torvalds
2013-09-30 20:01 ` Waiman Long
@ 2013-09-30 22:52 ` Benjamin Herrenschmidt
2013-10-01 0:36 ` Michael Neuling
1 sibling, 1 reply; 12+ messages in thread
From: Benjamin Herrenschmidt @ 2013-09-30 22:52 UTC (permalink / raw)
To: Linus Torvalds
Cc: Waiman Long, Peter Zijlstra, Norton, Scott J,
Linux Kernel Mailing List, Chandramouleeswaran, Aswin,
Michael Neuling, George Spelvin, linux-fsdevel, ppc-dev,
Ingo Molnar
On Mon, 2013-09-30 at 12:29 -0700, Linus Torvalds wrote:
>
> But I'm cc'ing the POWER people, because I don't know the POWER8
> interfaces, and I don't want to necessarily call this "xbegin"/"xend"
> when I actually wrap it in some helper functions.
The main problem with powerpc TM is that we need to handle interrupts
happening while in transactional state. We currently only handle that
for userspace.
Mikey, how hard would it be to detect the in-kernel TM case and just
simulate an abort in the exception entry ? (return to tbegin basically)
Transactions in kernel make me nervous because of the PC jumping around
on aborts and how easy we can get that stuff wrong :-) They also have
interesting ordering semantics vs. locks, we need to be a tad careful
(as long as we don't access a lock variable transactionally we should be
ok. If we do, then spin_unlock needs a stronger barrier).
The basic semantic for us is tbegin. [...] tend instructions. If the
transaction fails, control returns to tbegin. (can happen at any point)
which returns a CC code indicating success or failure.
Things get really complicated if you take an interrupt however, the
transaction gets into some special "suspended" state, it doesn't just
die so we need to handle things in our interrupt entry (even if it's
just to make the transaction abort cleanly) and right now we don't when
coming from kernel space.
Cheers,
Ben.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Avoiding the dentry d_lock on final dput(), part deux: transactional memory
2013-09-30 22:52 ` Benjamin Herrenschmidt
@ 2013-10-01 0:36 ` Michael Neuling
2013-10-01 0:56 ` Linus Torvalds
0 siblings, 1 reply; 12+ messages in thread
From: Michael Neuling @ 2013-10-01 0:36 UTC (permalink / raw)
To: Benjamin Herrenschmidt
Cc: Waiman Long, Peter Zijlstra, Norton, Scott J, ppc-dev,
Linux Kernel Mailing List, Chandramouleeswaran, Aswin,
George Spelvin, linux-fsdevel, Linus Torvalds, Ingo Molnar
Ben,
> On Mon, 2013-09-30 at 12:29 -0700, Linus Torvalds wrote:
> >
> > But I'm cc'ing the POWER people, because I don't know the POWER8
> > interfaces, and I don't want to necessarily call this "xbegin"/"xend"
> > when I actually wrap it in some helper functions.
>
> The main problem with powerpc TM is that we need to handle interrupts
> happening while in transactional state. We currently only handle that
> for userspace.
Yep.
> Mikey, how hard would it be to detect the in-kernel TM case and just
> simulate an abort in the exception entry ? (return to tbegin basically)
It's doable.
The scary part is that we to make all register volatile. You were not
that keen on doing this as there are a lot of places in exception
entry/exit where we only save/restore a subset of the registers. We'd
need to catch all these.
> Transactions in kernel make me nervous because of the PC jumping
> around on aborts and how easy we can get that stuff wrong :-)
The same applies for userspace. We are pretty careful not to screw that
up though.
It's also one of the reason we don't do software rollback of userspace
transactions even in transactional (non-suspended) mode. We always save
and restore all state and let the HW deal with the PC and state jumping
around.
> They also have interesting ordering semantics vs. locks, we need to be
> a tad careful (as long as we don't access a lock variable
> transactionally we should be ok. If we do, then spin_unlock needs a
> stronger barrier).
Yep.
> The basic semantic for us is tbegin. [...] tend instructions. If the
> transaction fails, control returns to tbegin. (can happen at any
> point) which returns a CC code indicating success or failure.
FWIW eg.
tbegin
beq abort /* passes first time through */
....
transactional stuff
....
tend
b pass
abort:
pass:
> Things get really complicated if you take an interrupt however, the
> transaction gets into some special "suspended" state, it doesn't just
> die so we need to handle things in our interrupt entry (even if it's
> just to make the transaction abort cleanly) and right now we don't
> when coming from kernel space.
Yep, but we could check easily enough.
Mikey
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Avoiding the dentry d_lock on final dput(), part deux: transactional memory
2013-10-01 0:36 ` Michael Neuling
@ 2013-10-01 0:56 ` Linus Torvalds
2013-10-01 2:05 ` Benjamin Herrenschmidt
0 siblings, 1 reply; 12+ messages in thread
From: Linus Torvalds @ 2013-10-01 0:56 UTC (permalink / raw)
To: Michael Neuling
Cc: Waiman Long, Peter Zijlstra, George Spelvin,
Linux Kernel Mailing List, Chandramouleeswaran, Aswin,
Norton, Scott J, linux-fsdevel, ppc-dev, Ingo Molnar
On Mon, Sep 30, 2013 at 5:36 PM, Michael Neuling <mikey@neuling.org> wrote:
>
> The scary part is that we to make all register volatile. You were not
> that keen on doing this as there are a lot of places in exception
> entry/exit where we only save/restore a subset of the registers. We'd
> need to catch all these.
Ugh. It's very possible it's not worth using for the kernel then. The
example I posted is normally fine *without* any transactional support,
since it's a very local per-dentry lock, and since we only take that
lock when the last reference drops (so it's not some common directory
dentry, it's a end-point file dentry). In fact, on ARM they just made
the cmpxchg much faster by making it entirely non-serializing (since
it only updates a reference count, there is no locking involved apart
from checking that the lock state is unlocked)
So there is basically never any contention, and the transaction needs
to basically be pretty much the same cost as a "cmpxchg". It's not
clear if the intel TSX is good enough for that, and if you have to
save a lot of registers in order to use transactions on POWER8, I
doubt it's worthwhile.
We have very few - if any - locks where contention or even cache
bouncing is common or normal. Sure, we have a few particular loads
that can trigger it, but even that is becoming rare. So from a
performance standpoint, the target always needs to be "comparable to
hot spinlock in local cache".
>> They also have interesting ordering semantics vs. locks, we need to be
>> a tad careful (as long as we don't access a lock variable
>> transactionally we should be ok. If we do, then spin_unlock needs a
>> stronger barrier).
>
> Yep.
Well, just about any kernel transaction will at least read the state
of a lock. Without that, it's generally totally useless. My dput()
example sequence very much verified that the lock was not held, for
example.
I'm not sure how that affects anything. The actual transaction had
better not be visible inside the locked region (ie as far as any lock
users go, transactions better all happen fully before or after the
lock, if they read the lock and see it being unlocked).
That said, I cannot see how POWER8 could possibly violate that rule.
The whole "transactions are atomic" is kind of the whole and only
point of a transaction. So I'm not sure what odd lock restrictions
POWER8 could have.
> FWIW eg.
>
> tbegin
> beq abort /* passes first time through */
> ....
> transactional stuff
> ....
> tend
> b pass
>
> abort:
>
> pass:
That's fine, and matches the x86 semantics fairly closely, except
"xbegin" kind of "contains" that "jump to abort address". But we could
definitely use the same models. Call it
"transaction_begin/abort/end()", and it should be architecture-neutral
naming-wise.
Of course, if tbegin then acts basically like some crazy
assembly-level setjmp (I'm guessing it does exactly, and presumably
precisely that kind of compiler support - ie a function with
"__attribute((returns_twice))" in gcc-speak), the overhead of doing it
may kill it.
Linus
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Avoiding the dentry d_lock on final dput(), part deux: transactional memory
2013-10-01 0:56 ` Linus Torvalds
@ 2013-10-01 2:05 ` Benjamin Herrenschmidt
2013-10-01 3:13 ` Paul E. McKenney
0 siblings, 1 reply; 12+ messages in thread
From: Benjamin Herrenschmidt @ 2013-10-01 2:05 UTC (permalink / raw)
To: Linus Torvalds
Cc: Waiman Long, Michael Neuling, Peter Zijlstra, Norton, Scott J,
Linux Kernel Mailing List, Chandramouleeswaran, Aswin,
George Spelvin, linux-fsdevel, Paul E. McKenney, ppc-dev,
Ingo Molnar
On Mon, 2013-09-30 at 17:56 -0700, Linus Torvalds wrote:
> On Mon, Sep 30, 2013 at 5:36 PM, Michael Neuling <mikey@neuling.org> wrote:
> >
> > The scary part is that we to make all register volatile. You were not
> > that keen on doing this as there are a lot of places in exception
> > entry/exit where we only save/restore a subset of the registers. We'd
> > need to catch all these.
>
> Ugh. It's very possible it's not worth using for the kernel then. The
> example I posted is normally fine *without* any transactional support,
> since it's a very local per-dentry lock, and since we only take that
> lock when the last reference drops (so it's not some common directory
> dentry, it's a end-point file dentry). In fact, on ARM they just made
> the cmpxchg much faster by making it entirely non-serializing (since
> it only updates a reference count, there is no locking involved apart
> from checking that the lock state is unlocked)
>
> So there is basically never any contention, and the transaction needs
> to basically be pretty much the same cost as a "cmpxchg". It's not
> clear if the intel TSX is good enough for that, and if you have to
> save a lot of registers in order to use transactions on POWER8, I
> doubt it's worthwhile.
Well we don't have to, I think Mikey wasn't totally clear about that
"making all registers volatile" business :-) This is just something we
need to handle in assembly if we are going to reclaim the suspended
transaction.
So basically, what we need is something along the lines of
enable_kernel_tm() which checks if there's a suspended user transaction
and if yes, kills/reclaims it.
Then we also need to handle in our interrupt handlers that we have an
active/suspended transaction from a kernel state, which we don't deal
with at this point, and do whatever has to be done to kill it... we
might get away with something simple if we can state that we only allow
kernel transactions at task level and not from interrupt/softirq
contexts, at least initially.
> We have very few - if any - locks where contention or even cache
> bouncing is common or normal. Sure, we have a few particular loads
> that can trigger it, but even that is becoming rare. So from a
> performance standpoint, the target always needs to be "comparable to
> hot spinlock in local cache".
I am not quite familiar with the performance profile of our
transactional hardware. I think we should definitely try to hack
something together for that dput() case and measure it.
> >> They also have interesting ordering semantics vs. locks, we need to be
> >> a tad careful (as long as we don't access a lock variable
> >> transactionally we should be ok. If we do, then spin_unlock needs a
> >> stronger barrier).
> >
> > Yep.
>
> Well, just about any kernel transaction will at least read the state
> of a lock. Without that, it's generally totally useless. My dput()
> example sequence very much verified that the lock was not held, for
> example.
>
> I'm not sure how that affects anything. The actual transaction had
> better not be visible inside the locked region (ie as far as any lock
> users go, transactions better all happen fully before or after the
> lock, if they read the lock and see it being unlocked).
>
> That said, I cannot see how POWER8 could possibly violate that rule.
> The whole "transactions are atomic" is kind of the whole and only
> point of a transaction. So I'm not sure what odd lock restrictions
> POWER8 could have.
Has to do with the memory model :-(
I dug the whole story from my mbox and the situation is indeed as dire
as feared. If the transaction reads the lock, then the corresponding
spin_lock must have a full sync barrier in it instead of the current
lighter one.
Now I believe we are already "on the fence" with our locks today since
technically speaking, our unlock + lock sequence is *not* exactly a full
barrier (it is only if it's the same lock I think)
CC'ing Paul McKenney here who's been chasing that issue. In the end, we
might end up having to turn our locks into sync anyway
Yay ! The isanity^Wjoy of an OO memory model !
> > FWIW eg.
> >
> > tbegin
> > beq abort /* passes first time through */
> > ....
> > transactional stuff
> > ....
> > tend
> > b pass
> >
> > abort:
> >
> > pass:
>
> That's fine, and matches the x86 semantics fairly closely, except
> "xbegin" kind of "contains" that "jump to abort address". But we could
> definitely use the same models. Call it
> "transaction_begin/abort/end()", and it should be architecture-neutral
> naming-wise.
Right.
> Of course, if tbegin then acts basically like some crazy
> assembly-level setjmp (I'm guessing it does exactly, and presumably
> precisely that kind of compiler support - ie a function with
> "__attribute((returns_twice))" in gcc-speak), the overhead of doing it
> may kill it.
Well, all the registers are checkpointed so we *should* be ok but gcc
always makes me nervous in those circumstances ...
Ben.
> Linus
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Avoiding the dentry d_lock on final dput(), part deux: transactional memory
2013-10-01 2:05 ` Benjamin Herrenschmidt
@ 2013-10-01 3:13 ` Paul E. McKenney
2013-10-01 4:52 ` Michael Neuling
0 siblings, 1 reply; 12+ messages in thread
From: Paul E. McKenney @ 2013-10-01 3:13 UTC (permalink / raw)
To: Benjamin Herrenschmidt
Cc: Waiman Long, Michael Neuling, Peter Zijlstra, Norton, Scott J,
ppc-dev, Linux Kernel Mailing List, Chandramouleeswaran, Aswin,
George Spelvin, linux-fsdevel, Linus Torvalds, Ingo Molnar
On Tue, Oct 01, 2013 at 12:05:03PM +1000, Benjamin Herrenschmidt wrote:
> On Mon, 2013-09-30 at 17:56 -0700, Linus Torvalds wrote:
> > On Mon, Sep 30, 2013 at 5:36 PM, Michael Neuling <mikey@neuling.org> wrote:
> > >
> > > The scary part is that we to make all register volatile. You were not
> > > that keen on doing this as there are a lot of places in exception
> > > entry/exit where we only save/restore a subset of the registers. We'd
> > > need to catch all these.
> >
> > Ugh. It's very possible it's not worth using for the kernel then. The
> > example I posted is normally fine *without* any transactional support,
> > since it's a very local per-dentry lock, and since we only take that
> > lock when the last reference drops (so it's not some common directory
> > dentry, it's a end-point file dentry). In fact, on ARM they just made
> > the cmpxchg much faster by making it entirely non-serializing (since
> > it only updates a reference count, there is no locking involved apart
> > from checking that the lock state is unlocked)
A memory-barrier-free cmpxchg() would be easy on Power as well.
> > So there is basically never any contention, and the transaction needs
> > to basically be pretty much the same cost as a "cmpxchg". It's not
> > clear if the intel TSX is good enough for that, and if you have to
> > save a lot of registers in order to use transactions on POWER8, I
> > doubt it's worthwhile.
>
> Well we don't have to, I think Mikey wasn't totally clear about that
> "making all registers volatile" business :-) This is just something we
> need to handle in assembly if we are going to reclaim the suspended
> transaction.
>
> So basically, what we need is something along the lines of
> enable_kernel_tm() which checks if there's a suspended user transaction
> and if yes, kills/reclaims it.
>
> Then we also need to handle in our interrupt handlers that we have an
> active/suspended transaction from a kernel state, which we don't deal
> with at this point, and do whatever has to be done to kill it... we
> might get away with something simple if we can state that we only allow
> kernel transactions at task level and not from interrupt/softirq
> contexts, at least initially.
Call me a coward, but this is starting to sound a bit scary. ;-)
> > We have very few - if any - locks where contention or even cache
> > bouncing is common or normal. Sure, we have a few particular loads
> > that can trigger it, but even that is becoming rare. So from a
> > performance standpoint, the target always needs to be "comparable to
> > hot spinlock in local cache".
>
> I am not quite familiar with the performance profile of our
> transactional hardware. I think we should definitely try to hack
> something together for that dput() case and measure it.
>
> > >> They also have interesting ordering semantics vs. locks, we need to be
> > >> a tad careful (as long as we don't access a lock variable
> > >> transactionally we should be ok. If we do, then spin_unlock needs a
> > >> stronger barrier).
> > >
> > > Yep.
> >
> > Well, just about any kernel transaction will at least read the state
> > of a lock. Without that, it's generally totally useless. My dput()
> > example sequence very much verified that the lock was not held, for
> > example.
> >
> > I'm not sure how that affects anything. The actual transaction had
> > better not be visible inside the locked region (ie as far as any lock
> > users go, transactions better all happen fully before or after the
> > lock, if they read the lock and see it being unlocked).
> >
> > That said, I cannot see how POWER8 could possibly violate that rule.
> > The whole "transactions are atomic" is kind of the whole and only
> > point of a transaction. So I'm not sure what odd lock restrictions
> > POWER8 could have.
>
> Has to do with the memory model :-(
>
> I dug the whole story from my mbox and the situation is indeed as dire
> as feared. If the transaction reads the lock, then the corresponding
> spin_lock must have a full sync barrier in it instead of the current
> lighter one.
>
> Now I believe we are already "on the fence" with our locks today since
> technically speaking, our unlock + lock sequence is *not* exactly a full
> barrier (it is only if it's the same lock I think)
>
> CC'ing Paul McKenney here who's been chasing that issue. In the end, we
> might end up having to turn our locks into sync anyway
Well, there have been a lot of fixed software bugs since the last
suspicious sighting, but on the other hand, I am just now getting my
RCU testing going again on Power. I would certainly feel better
about things if unlock-lock was really truly a full barrier, but
this clearly needs a clean sighting.
> Yay ! The isanity^Wjoy of an OO memory model !
;-) ;-) ;-)
Thanx, Paul
> > > FWIW eg.
> > >
> > > tbegin
> > > beq abort /* passes first time through */
> > > ....
> > > transactional stuff
> > > ....
> > > tend
> > > b pass
> > >
> > > abort:
> > >
> > > pass:
> >
> > That's fine, and matches the x86 semantics fairly closely, except
> > "xbegin" kind of "contains" that "jump to abort address". But we could
> > definitely use the same models. Call it
> > "transaction_begin/abort/end()", and it should be architecture-neutral
> > naming-wise.
>
> Right.
>
> > Of course, if tbegin then acts basically like some crazy
> > assembly-level setjmp (I'm guessing it does exactly, and presumably
> > precisely that kind of compiler support - ie a function with
> > "__attribute((returns_twice))" in gcc-speak), the overhead of doing it
> > may kill it.
>
> Well, all the registers are checkpointed so we *should* be ok but gcc
> always makes me nervous in those circumstances ...
>
> Ben.
>
>
> > Linus
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at http://vger.kernel.org/majordomo-info.html
> > Please read the FAQ at http://www.tux.org/lkml/
>
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Avoiding the dentry d_lock on final dput(), part deux: transactional memory
2013-10-01 3:13 ` Paul E. McKenney
@ 2013-10-01 4:52 ` Michael Neuling
2013-10-01 12:16 ` Paul E. McKenney
0 siblings, 1 reply; 12+ messages in thread
From: Michael Neuling @ 2013-10-01 4:52 UTC (permalink / raw)
To: paulmck
Cc: Waiman Long, ppc-dev, Peter Zijlstra, George Spelvin,
Linux Kernel Mailing List, Chandramouleeswaran, Aswin,
Norton, Scott J, linux-fsdevel, Linus Torvalds, Ingo Molnar
>> Well we don't have to, I think Mikey wasn't totally clear about that
>> "making all registers volatile" business :-) This is just something we
>> need to handle in assembly if we are going to reclaim the suspended
>> transaction.
Yeah, sorry. The slow path with all registers as volatile is only
needed if we get pre-empted during the transaction.
>>
>> So basically, what we need is something along the lines of
>> enable_kernel_tm() which checks if there's a suspended user transaction
>> and if yes, kills/reclaims it.
>>
>> Then we also need to handle in our interrupt handlers that we have an
>> active/suspended transaction from a kernel state, which we don't deal
>> with at this point, and do whatever has to be done to kill it... we
>> might get away with something simple if we can state that we only allow
>> kernel transactions at task level and not from interrupt/softirq
>> contexts, at least initially.
>
> Call me a coward, but this is starting to sound a bit scary. ;-)
We are just wanting to prototype it for now to see if we could make it
go faster. If it's worth it, then we'd consider the additional
complexity this would bring.
I don't think it'll be that bad, but I'd certainly want to make sure
it's worth it before trying :-)
Mikey
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Avoiding the dentry d_lock on final dput(), part deux: transactional memory
2013-10-01 4:52 ` Michael Neuling
@ 2013-10-01 12:16 ` Paul E. McKenney
2013-10-01 13:42 ` Paul E. McKenney
0 siblings, 1 reply; 12+ messages in thread
From: Paul E. McKenney @ 2013-10-01 12:16 UTC (permalink / raw)
To: Michael Neuling
Cc: Waiman Long, ppc-dev, Peter Zijlstra, George Spelvin,
Linux Kernel Mailing List, Chandramouleeswaran, Aswin,
Norton, Scott J, linux-fsdevel, Linus Torvalds, Ingo Molnar
On Tue, Oct 01, 2013 at 02:52:28PM +1000, Michael Neuling wrote:
> >> Well we don't have to, I think Mikey wasn't totally clear about that
> >> "making all registers volatile" business :-) This is just something we
> >> need to handle in assembly if we are going to reclaim the suspended
> >> transaction.
>
> Yeah, sorry. The slow path with all registers as volatile is only
> needed if we get pre-empted during the transaction.
>
> >>
> >> So basically, what we need is something along the lines of
> >> enable_kernel_tm() which checks if there's a suspended user transaction
> >> and if yes, kills/reclaims it.
> >>
> >> Then we also need to handle in our interrupt handlers that we have an
> >> active/suspended transaction from a kernel state, which we don't deal
> >> with at this point, and do whatever has to be done to kill it... we
> >> might get away with something simple if we can state that we only allow
> >> kernel transactions at task level and not from interrupt/softirq
> >> contexts, at least initially.
> >
> > Call me a coward, but this is starting to sound a bit scary. ;-)
>
> We are just wanting to prototype it for now to see if we could make it
> go faster. If it's worth it, then we'd consider the additional
> complexity this would bring.
>
> I don't think it'll be that bad, but I'd certainly want to make sure
> it's worth it before trying :-)
OK, fair point. ;-)
Thanx, Paul
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Avoiding the dentry d_lock on final dput(), part deux: transactional memory
2013-10-01 12:16 ` Paul E. McKenney
@ 2013-10-01 13:42 ` Paul E. McKenney
0 siblings, 0 replies; 12+ messages in thread
From: Paul E. McKenney @ 2013-10-01 13:42 UTC (permalink / raw)
To: Michael Neuling
Cc: Waiman Long, ppc-dev, Peter Zijlstra, George Spelvin,
Linux Kernel Mailing List, Chandramouleeswaran, Aswin,
Norton, Scott J, linux-fsdevel, Linus Torvalds, Ingo Molnar
On Tue, Oct 01, 2013 at 05:16:54AM -0700, Paul E. McKenney wrote:
> On Tue, Oct 01, 2013 at 02:52:28PM +1000, Michael Neuling wrote:
> > >> Well we don't have to, I think Mikey wasn't totally clear about that
> > >> "making all registers volatile" business :-) This is just something we
> > >> need to handle in assembly if we are going to reclaim the suspended
> > >> transaction.
> >
> > Yeah, sorry. The slow path with all registers as volatile is only
> > needed if we get pre-empted during the transaction.
> >
> > >>
> > >> So basically, what we need is something along the lines of
> > >> enable_kernel_tm() which checks if there's a suspended user transaction
> > >> and if yes, kills/reclaims it.
> > >>
> > >> Then we also need to handle in our interrupt handlers that we have an
> > >> active/suspended transaction from a kernel state, which we don't deal
> > >> with at this point, and do whatever has to be done to kill it... we
> > >> might get away with something simple if we can state that we only allow
> > >> kernel transactions at task level and not from interrupt/softirq
> > >> contexts, at least initially.
> > >
> > > Call me a coward, but this is starting to sound a bit scary. ;-)
> >
> > We are just wanting to prototype it for now to see if we could make it
> > go faster. If it's worth it, then we'd consider the additional
> > complexity this would bring.
> >
> > I don't think it'll be that bad, but I'd certainly want to make sure
> > it's worth it before trying :-)
>
> OK, fair point. ;-)
That is, a fair point -assuming- that we also try the memory-barrier-free
cmpxchg that Linus suggested...
Thanx, Paul
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2013-10-02 14:57 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-30 19:29 Avoiding the dentry d_lock on final dput(), part deux: transactional memory Linus Torvalds
2013-09-30 20:01 ` Waiman Long
2013-09-30 20:04 ` Linus Torvalds
2013-10-02 14:56 ` Andi Kleen
2013-09-30 22:52 ` Benjamin Herrenschmidt
2013-10-01 0:36 ` Michael Neuling
2013-10-01 0:56 ` Linus Torvalds
2013-10-01 2:05 ` Benjamin Herrenschmidt
2013-10-01 3:13 ` Paul E. McKenney
2013-10-01 4:52 ` Michael Neuling
2013-10-01 12:16 ` Paul E. McKenney
2013-10-01 13:42 ` Paul E. McKenney
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).