Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upReplace synchronization primitives with those from parking_lot #1632
Conversation
This comment has been minimized.
This comment has been minimized.
alilleybrinker
commented
May 27, 2016
|
Just as a first comment, I'm not sure how the parking_lot primitives can be adopted in favor of the current standard library primitives without violation of Rust's stability guarantees. |
This comment has been minimized.
This comment has been minimized.
|
If this can be done in a way that is compatible, I would absolutely love to do this. |
This comment has been minimized.
This comment has been minimized.
As mentioned in the RFC, the parking_lot primitives have the same API as the standard ones, so there is no compatibility issue if we replace one with the other. |
This comment has been minimized.
This comment has been minimized.
|
I expected to see benchmarks on all tier 1 and at least some tier 2 platforms included into the RFC text as the reason to/not to accept the RFC. |
This comment has been minimized.
This comment has been minimized.
|
@nagisa I added some benchmark results for Linux and Windows. Unfortunately I don't have any other platforms to test on. |
This comment has been minimized.
This comment has been minimized.
|
I seem to recall from the Webkit article that the parking-lot-style locks are not entirely fair. While I also recall good reasons why this isn't so bad, if this is also true of the Rust crate, I would expect it (as well as any other downsides that may exist — for example, does the crate leak memory as Webkit does?) to be discussed in the RFC. |
This comment has been minimized.
This comment has been minimized.
|
I personally haven’t came across a single case where entirely-fair locks were necessary or even desirable. Is there one? I don’t recall us ever guaranteeing this for any locking mechanism in the standard library so far. Either way, from the same webkit blog post it seems like making locks fair is also an option. |
This comment has been minimized.
This comment has been minimized.
|
I'm not particularly keen on fair locks either (then again, I'm not sure I'm qualified to judge anyway). I just want all the differences, including the ones that may be irrelevant or drawbacks, documented in the RFC to make it easier to form an opinion without scavenging N articles across the internet. In particular if there are so many minor design decisions where |
This comment has been minimized.
This comment has been minimized.
|
Neither pthread mutexes or Windows SRWLOCK, which is what the standard library primitives are based on, make any fairness guarantees, so there is no difference here. |
This comment has been minimized.
This comment has been minimized.
comex
commented
May 29, 2016
|
|
This comment has been minimized.
This comment has been minimized.
|
The rfc does not mention, that |
This comment has been minimized.
This comment has been minimized.
|
I have poisoning support for parking_lot in a branch, and this is the version that would be integrated into the standard library. I don't plan on adding poisoning support to the parking_lot crate itself because poisoning has a significant performance cost and I feel that it makes the API uglier. By the way, lack of poisoning doesn't make anything unsafe, it just means that user code needs to be aware that locked data may be left in an inconsistent (but safe) state after a panic. This is why |
This comment has been minimized.
This comment has been minimized.
|
As an example, on AArch64, adding support for poisoning makes |
This comment has been minimized.
This comment has been minimized.
|
Is it possible to turn off poisoning when we are linking to the |
This comment has been minimized.
This comment has been minimized.
|
Abort still runs various handlers before actually quitting process (to my knowledge, at least), therefore all data behind mutex that may be accessed there should also be poisoned. |
This comment has been minimized.
This comment has been minimized.
|
@nagisa It only runs the panic hook, nothing else. |
This comment has been minimized.
This comment has been minimized.
|
So, it should be possible (abort doesn't call destructors anyways). |
This comment has been minimized.
This comment has been minimized.
|
You may have mutexes in statics and the panic hook may run arbitrary code. |
This comment has been minimized.
This comment has been minimized.
|
@nagisa With panic = abort a mutex can never become poisoned because that is done in the destructor of |
This comment has been minimized.
This comment has been minimized.
|
@nagisa The point is that the inner value cannot become poisoned because the destructor won't be called. |
nrc
added
the
T-libs
label
May 30, 2016
This comment has been minimized.
This comment has been minimized.
eternaleye
commented
May 31, 2016
•
|
One thing I feel is worth noting - the [1] http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.103.8168&rep=rep1&type=pdf |
This comment has been minimized.
This comment has been minimized.
|
@eternaleye |
This comment has been minimized.
This comment has been minimized.
eternaleye
commented
May 31, 2016
|
@Amanieu: Ah, had missed the backoff. However, I do strongly suggest reading my second link - it shows catastrophic throughput loss for the ticket spinlocks in the Linux kernel of the time, and compares against their MCS lock implementations patched into Linux. |
This comment has been minimized.
This comment has been minimized.
|
One big assumption that this paper makes is that all "threads" are always running and never scheduled out. This is a perfectly fine assumption to make in the context of a kernel where a "thread" is a raw CPU. However this doesn't necessarily apply in the context a userspace process where the scheduler will arbitrarily suspend threads for a (relatively) long duration. And this leads to the big issue with queue-based locks: you have no way of knowing whether the next thread in the queue has been scheduled out. If it has then you have one whole timeslice during which nobody owns the lock. If you instead have threads spinning on the lock word waiting for it to get unlocked then you are pretty much guaranteed to pass the lock to a thread that is running. Now, with that said, the spin waiting strategy in parking_lot is a bit ad-hoc and could use some fine-tuning (read: I made up some numbers and it seemed to give good results). In particular I'm considering reducing the number of times I yield the thread in favor of just queuing up the thread and having it sleep until explicitly woken up. |
This comment has been minimized.
This comment has been minimized.
arthurprs
commented
May 31, 2016
|
In order to really discuss this we need benchmarks with the poisoned branch on most tier A platforms. |
This comment has been minimized.
This comment has been minimized.
|
The benchmarks linked in the RFC were done on the poison branch. |
This comment has been minimized.
This comment has been minimized.
eternaleye
commented
Jun 1, 2016
|
@briansmith: Aligning to page boundaries makes cache contention worse, due to collision: http://danluu.com/3c-conflict/ Putting mutexes on their own cachelines might make sense, but page-aligning them could do a world of harm. |
This comment has been minimized.
This comment has been minimized.
There are two reasons why this won't work on
|
This comment has been minimized.
This comment has been minimized.
gereeter
commented
Jun 1, 2016
|
A more conservative change would be to just move the OS-specific implementations of |
This comment has been minimized.
This comment has been minimized.
gereeter
commented
Jun 1, 2016
|
Additionally, I'd like to see benchmarks against the standard library implementation of |
This comment has been minimized.
This comment has been minimized.
|
I expect the performance of As for |
This comment has been minimized.
This comment has been minimized.
briansmith
commented
Jun 1, 2016
Sorry, I meant to write "full cache line" and "cache-line-aligned." AFAICT, it should be really easy to provide both aligned-and-padded and single-byte variants. |
This comment has been minimized.
This comment has been minimized.
|
@briansmith What you really want to do is align the mutex and the data it is protecting to a cacheline. This can easily be done by marking |
This comment has been minimized.
This comment has been minimized.
|
This would be a nice thing to optionally enable if we gave |
This comment has been minimized.
This comment has been minimized.
CodesInChaos
commented
Jun 2, 2016
|
What seems a bit risky with this change is that it not only replaces the implementation, but that it also makes additional promises. This restricts alternative implementations and prevents backing out of the change. |
This comment has been minimized.
This comment has been minimized.
arthurprs
commented
Jun 2, 2016
|
@CodesInChaos the guarantees can always be reduced and this would still give good improvements in the performance side. Anyway I fell like this is a great proposal, we just need to wait a few months (let parking lot prove itself) before really making a decision. |
This comment has been minimized.
This comment has been minimized.
|
The |
This comment has been minimized.
This comment has been minimized.
|
Regarding real-world usage of parking_lot, today has brought us http://plhk.ru/trash/netmap-20160710.pdf . |
alexcrichton
added
the
final-comment-period
label
Jul 19, 2016
This comment has been minimized.
This comment has been minimized.
|
The libs team felt that this RFC's discussion has reached a standstill now and as a result it's ready to move into FCP. Our feeling matches what I wrote earlier about how |
This comment has been minimized.
This comment has been minimized.
tmiasko
commented
Jul 25, 2016
|
Having an implementation of synchronization primitives directly in standard
... (and many others, not to mention differences between Windows API). It seems that at some point it would be a really nice thing to have. |
This comment has been minimized.
This comment has been minimized.
I agree, there are lots of potential benefits to offering these constructs. But it's a pretty big move to make, and for the time being gaining more experience with them externally seems prudent. (In general, it's not 100% clear to me what direction the concurrency story within |
This comment has been minimized.
This comment has been minimized.
|
The libs team got a chance to talk about this RFC this week at libs triage, and our conclusion remains the same as before in that while |
alexcrichton
closed this
Jul 26, 2016
petrochenkov
referenced this pull request
Aug 9, 2016
Closed
Rust on Windows Vista (crash with SetThreadErrorMode) #35471
This comment has been minimized.
This comment has been minimized.
techtonik
commented
Aug 10, 2016
|
Can this still be included as a fallback mechanism to allow Rust to run not only on shiny new Windows? |
Amanieu
referenced this pull request
Aug 26, 2016
Open
RwLock and Mutex on Window theoretically allows undefined behavior in safe code #35836
This comment has been minimized.
This comment has been minimized.
|
Another blog post mentioning parking_lot: https://blog.mozilla.org/nfroyd/2017/03/29/on-mutex-performance-part-1/ It's been about a year since the crate was first published, so at some point it would be worth thinking about a timeline or otherwise mulling over specific criteria for potentially moving forward on this. Rather than trying to go into the stdlib directly, maybe a more reasonable first step would be to get this into rust-lang-nursery and see where it goes from there. |
This comment has been minimized.
This comment has been minimized.
|
I can easy imagine adding some Cargo features to make this opt-in (c.f. allocator choice). |
Amanieu
referenced this pull request
Jun 9, 2017
Closed
Why are these types not in the standard library? #36
This comment has been minimized.
This comment has been minimized.
sanmai-NL
commented
Dec 19, 2017
This comment has been minimized.
This comment has been minimized.
TerjeBr
commented
Feb 15, 2018
|
It has been a long time now. Should this pull request be reopened? |
This comment has been minimized.
This comment has been minimized.
|
The work of the up-and-comming portability time this year will hopefully allow this for free. |
Amanieu commentedMay 27, 2016
Rendered