lttng-dev.lists.lttng.org archive mirror
 help / color / mirror / Atom feed
* Alternative to signals/sys_membarrier() in liburcu
@ 2015-02-11  0:03 Michael Sullivan
  0 siblings, 0 replies; 16+ messages in thread
From: Michael Sullivan @ 2015-02-11  0:03 UTC (permalink / raw)
  To: lttng-dev


[-- Attachment #1.1: Type: text/plain, Size: 1782 bytes --]

I've been looking at the RCU library (as part of gathering examples for my
research on weak memory models) and was thinking about ways to force other
threads to issue barriers. Since it seems like sys_membarrier() never made
it into the kernel, I was pondering whether there was some other way to
more or less get its effect; as it turns out, there is, but it is a hack:
mprotect(2).

When a thread revokes write permissions on a page, the kernel needs to do a
TLB shootdown to make sure that none of the other CPUs running code in that
address space have a writable mapping for that page cached. In Linux, this
is done by forcing code to invalidate the mappings to run on every CPU in
the address space, and waiting for completion. The code for the "run this
function on another CPU" mechanism forces the target CPU to issue an
smp_mb().

(In practice TLB shootdowns are done when permissions are added, not just
when they are removed, but they needn't be; faults caused by using a cached
entry with less permissions can be fixed up by the page fault handler.
They're also needed when unmapping memory, but mprotect() seems cheaper
than having to mmap() and munmap(). Also TLB shootdowns aren't needed if
the page is non-present because it's never been backed or has been swapped
out, so mlock(2) is used to keep it in place).

I hacked this up and in my limited testing, it does seem to have way better
write side performance than the signal version has. That said, it is also
super hacky and is certainly depending on behaviors of mprotect() that are
not actually specified. It would be unusual, I think, to implement
mprotect() in a way where this didn't work? It may well be to janky to
actually be useful, though.

I can send the code if you're interested.

-Michael Sullivan

[-- Attachment #1.2: Type: text/html, Size: 1931 bytes --]

[-- Attachment #2: Type: text/plain, Size: 155 bytes --]

_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2015-03-23  9:35 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <CANW5cDmTCM9ZmhN7-2eWUEYvD+Y=sGt2i7mecdPTTLHMcT8fPg@mail.gmail.com>
2015-02-12 13:57 ` Alternative to signals/sys_membarrier() in liburcu Duncan Sands
2015-03-12 14:57 ` Mathieu Desnoyers
     [not found] ` <54DCB15F.80505@free.fr>
2015-03-12 14:58   ` Mathieu Desnoyers
     [not found] ` <867044376.285926.1426172227750.JavaMail.zimbra@efficios.com>
2015-03-12 16:04   ` Michael Sullivan
     [not found]   ` <CANW5cDkiZoysNM3rqb4v6Tj996ocsaSh=OZoBLfp4h7ZGb4bxg@mail.gmail.com>
2015-03-12 20:53     ` Mathieu Desnoyers
     [not found]     ` <666590480.287502.1426193588471.JavaMail.zimbra@efficios.com>
2015-03-12 20:56       ` Mathieu Desnoyers
2015-03-12 21:12         ` Paul E. McKenney
2015-03-14 21:06           ` Benjamin Herrenschmidt
2015-03-12 23:59         ` One Thousand Gnomes
2015-03-13  0:43           ` Mathieu Desnoyers
2015-03-12 21:47       ` Linus Torvalds
2015-03-12 22:30         ` Mathieu Desnoyers
2015-03-13  8:07           ` Ingo Molnar
2015-03-13 14:18             ` Paul E. McKenney
2015-03-23  9:35               ` [lttng-dev] " Duncan Sands
2015-02-11  0:03 Michael Sullivan

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).