A proposal for a mixed-atomicity memory model#41
A proposal for a mixed-atomicity memory model#41gasche wants to merge 3 commits intoocaml:masterfrom
Conversation
4b9eb8c to
02568bb
Compare
|
We (@fabbing and I) are reading this, slowly. |
OlivierNicole
left a comment
There was a problem hiding this comment.
While reading we found a few typos/strange syntax.
rfcs/mixed-atomicity-memory-model.md
Outdated
|
|
||
| e ~<l:ϕ>→ e' S(l); F —<l:ϕ>→ C'; F' | ||
| ———————————————————————————————————————————————— Step | ||
| <S, P || (F, e)]> —→ <S[l ↦ C'], P || (F', e')> |
There was a problem hiding this comment.
Not sure to understand what the double pipe means here. Did you mean P[i ↦ (F, e)]?
There was a problem hiding this comment.
Yes, I strayed slightly from the paper here. In my mind P || Q is standard syntax for parallel composition of processes/threads, which avoids talking about the irrelevant thread index.
There was a problem hiding this comment.
We thought that the stray ] may be a left-over from the previous notation, isn't it?
I see the point for Atomic.set_relaxed breaks coherence of atomic readsAtomic reads in OCaml satisfy coherence: if another thread writes an atomic and you read it repeatedly, then you will observe only one old->new transition (once you see the new value, further reads will agreee). This is not true of the proposed semantics: if an atomic and nonatomic write race on the same location, then the nonatomic write can choose a higher timestamp then the atomic one without updating the frontier, and atomic readers will then nondeterministically choose between the two, flickering between then arbitrarily many times. (Underlying hardware is coherent so you might think this saves you from observing such flickering. It does not: see Example 2 in the linked PLDI paper, where this sort of flickering appears due to interactions between compiler and hardware optimisations). Atomic.set_relaxed breaks the implementationThis assumption from the RFC is false as written:
The OCaml memory model has a property that the proposed semantics preserves, which is that frontiers in threads and locations grow monotonically - information about writes is never forgotten. A consequence of this is that for two atomic writes to the same location, one of them happens before the other, a property that does not hold in most memory models. This property is not naturally true of hardware models, and OCaml does some work to ensure it. (Roughly, by compiling atomic stores more like atomic exchanges). The proposed implementation would break this property, as nonatomic writes naively implemented would rewind the frontier of a location, because of weakness of coherence ordering in hardware models. That is, a semantics that is somewhat closer to what the implementation would do is one where Write-NA updates the location's frontier to the minimum of the previous and the thread's frontiers. (This would break the monotonicity and total-ordering-of-atomic-writes properties) |
|
Thanks! It looks like a reasonable next step would be to propose I am planning to close the current PR and open a new one with a revised/simplified proposal, so that we can easily compare the two, disentangle the two discussions, and restart here if we decide to someday. |
57e4886 to
b0df81d
Compare
|
In #41 I proposed a restricted version that only allows relaxed reads (not relaxed writes) on memory locations. I am closing here as planned -- but feel free to still comment on the full mixed-atomicity model in the present thread if there is something more to be said. (Thanks @OlivierNicole and @fabbing for the proof-reading / typos!) |
Yes, I believe One use case where I have used the equivalent of |
Rendered.
This RFC is more formal than is usual, as it proposes an extension of the current Multicore OCaml memory model to support mixed-atomicity (doing both atomic and non-atomic accesses on the same notation).
The question came up whenever we mentioned
Atomic.get_relaxedoperations or similar: do we understand what it means? My intuition is that the answer is "meh, that is not much harder than the current model", and this document is an attempt to instantiate this intuition into something more precise.Being a non-expert on memory models I would warmly welcome expert feedback.
The introduction of the RFC:
(Note: apparently github supports some LaTeX, but I chose to use weird unicode in verbatim blocks instead, because I think that it will be easier for people to write and edit if they want to, discuss/quote over email, etc.)