Section 8.6

Linearization point

Definition

A linearization point is an instant, between the call of an operation on a shared object and its return, at which the operation can be treated as taking effect instantly. A shared object is data, such as a counter, that several threads (sequences of instructions sharing one memory) use at the same time. If every operation has such a point and every result matches running the operations one at a time in the order of their points, the object is linearizable, a condition Herlihy and Wing defined in 1990.

The idea

Thread A writes the value 1 into a shared variable while thread B reads the variable. The two operations overlap in time, so “which came first” has no obvious answer, and B may see the old value or the new one. Reasoning about every interleaving of the individual instructions quickly becomes impossible. Linearizability replaces that with a simple picture: draw each operation as an interval on a time line, from its call to its return, and put one dot inside each interval. If the results are exactly what the operations would give when performed one at a time in the order of the dots, the object behaves as if each operation were instantaneous. Each dot is a linearization point.

In code, the dot usually sits on one instruction: the atomic store that makes a new value visible, or the successful compare-and-swap §9.9 that changes a shared pointer. An update that must also survive a loss of power has a second, separate instant: the one after which a crash can no longer undo it. The two instants need not coincide, and a design must say how they relate.

How it works

To show that a shared object is linearizable:

  1. Write the sequential specification, which says what each operation does when operations run one at a time. For a shared variable, a write stores its value and a read returns the most recently written value.

  2. Record the history: for each operation, its thread, call time, return time and result.

  3. Choose a point inside each interval and order the operations by their points. Because each point lies inside its own interval, an operation that returned before another was called always comes first. Operations whose intervals overlap may come in either order.

  4. Check the results against the sequential specification in that order. If some choice of points makes every result correct, the history is linearizable.

For an implementation, the argument names an instruction in each operation as its point and shows that every possible execution passes step 4. The point need not be the same line of code in every execution. In some lock-free §9.13 algorithms §14.1, in which threads coordinate through atomic instructions instead of locks, the point of one thread’s operation is an instruction executed by a different thread that helps it finish. A linearization point is part of a proof, not necessarily a fixed place in the source code.

Persistence adds that second point. Let an update replace version 1 of a configuration with version 2. Its linearization point for other threads is the atomic store of the pointer that makes version 2 visible in RAM. Its durable commit point is the completion of the write of the commit record §8.21, the small stored record that tells recovery which version is current; after a crash, recovery treats the update as committed exactly when that write completed before the crash. If the RAM point comes first, a crash between the two points returns the system to version 1 after threads have seen version 2. The usual rule avoids this: make the commit record durable first, then publish in RAM.

Izraelevitz, Mendes and Scott (2016) [513] defined a stronger condition for objects kept in persistent memory, main memory that keeps its content without power: durable linearizability, under which the history, with the crashes removed, must be linearizable. In particular, every operation that returned before a crash is still in effect after it.

Worked example

A shared variable xx starts at 0, and times are in microseconds. Thread A calls write(1) at time 0 and returns at time 4. Thread B calls read at time 2 and returns at time 3. The intervals [0,4][0, 4] and [2,3][2, 3] overlap.

Either result is linearizable.

Thread C calls read at time 5 and returns 0 at time 6. A’s point lies in [0,4][0, 4] and C’s point in [5,6][5, 6]. The latest possible point for A, 4, is earlier than the earliest possible point for C, 5, so every choice of points orders A before C. In the order A then C, the read must return 1. The result 0 is not linearizable.

Now the persistence window, with times in milliseconds (ms). A writer publishes version 2 of a configuration in RAM at 5 ms, and the commit record for version 2 finishes in flash memory §6.6 at 8 ms. A reader at 6 ms uses version 2. Power fails at 7 ms. Recovery finds the commit record still naming version 1 and starts with version 1, although a reader has already acted on version 2. The window lasts 8−5=38 - 5 = 3 ms. With the steps in the other order, the commit record complete at 8 ms and the RAM publication at 8.1 ms, every reader that sees version 2 does so after 8 ms, when a crash no longer undoes the update.

Stated precisely

A history is the record of an execution: for every operation, its call event with its arguments and its return event with its result. An operation o1o_1 precedes an operation o2o_2 in real time, written o1≺o2o_1 \prec o_2, when o1o_1 returns before o2o_2 is called. Herlihy and Wing define a history as linearizable when the following two steps succeed.

  1. Each operation that was called but has not returned is either given a return event with a result, or removed.

  2. There is an order SS of the remaining operations, one at a time, such that SS obeys the object’s sequential specification, and o1≺o2o_1 \prec o_2 implies that o1o_1 comes before o2o_2 in SS.

A linearization point of an operation oo is an instant tot_o with call(o)≤to≤return(o)\mathrm{call}(o) \le t_o \le \mathrm{return}(o), where call(o)\mathrm{call}(o) and return(o)\mathrm{return}(o) are the times of its call and return events, such that ordering all operations by these instants gives an order SS as above. Points chosen inside the intervals respect real time automatically: o1≺o2o_1 \prec o_2 gives to1≤return(o1)<call(o2)≤to2t_{o_1} \le \mathrm{return}(o_1) < \mathrm{call}(o_2) \le t_{o_2}.

For an update that must survive a crash, let cc be the instant at which the write of the commit record completes, and let pp be the update’s linearization point for threads in RAM. After a crash at instant tt, recovery treats the update as committed exactly when t>ct > c, provided that every torn outcome of the commit record write fails the record’s check value (a short number computed from the record’s other bytes), that everything the commit record names was complete before that write began, and that recovery decides from the commit record alone. A crash at any tt with p<t<cp < t < c undoes an update that other threads may already have seen. Requiring c≤pc \le p rules this out.

Limits and common mistakes

A linearization point belongs to a proof. Pointing at an atomic instruction in the code does not show that an object is linearizable; the argument must show that every result agrees with the order of the points.

Linearizability is stronger than sequential consistency §9.12. Sequential consistency requires one order of all operations that respects each thread’s own program order, but it may place an operation after another that finished earlier in a different thread. Linearizability also respects real-time order across threads.

Linearizability is local: a system whose objects are each linearizable is linearizable as a whole, which Herlihy and Wing prove. Sequential consistency lacks this property. Locality does not make a sequence of operations atomic: a read followed by a write on a linearizable object is two operations, and another thread can act between them.

The linearization point for threads is not the durable commit point. Making an update visible to threads says nothing about whether it survives a loss of power, and a stored commit record says nothing about what threads currently see.

On a processor with several cores, visibility needs atomic operations §9.8 or a memory barrier §4.37, an instruction that stops the processor and compiler from moving memory accesses across it. A plain store chosen as the linearization point may become visible to other cores later, or in a different order, than the source code suggests.

Questions answered

Which write determines whether recovery treats the update as committed?

The write of the commit record, the small stored record that tells the recovery procedure which version is current, determines it: recovery treats the update as committed exactly when that write completed before the failure. A failure before or during that write leaves the old version current, provided an interrupted commit record write always fails its check value; a failure after it leaves the new version current. This holds only if every record that the commit record names was completely written before the commit record write began, and recovery decides from the commit record alone.

That write is the update’s durable commit point, the crash-recovery counterpart of a linearization point, which is the instant at which an operation takes effect for other threads. The two instants need not coincide. If the new version becomes visible to other threads in RAM before the commit record is safely stored, a crash in between returns the system to the old version after threads have already used the new one. Storing the commit record first and publishing in RAM afterwards makes every update that threads can see one that recovery keeps.

Related entries: Atomicity (§8.3), Write ordering (§8.20), Commit record and selector (§8.21), Sequential consistency (§9.12). Further reading: [85, 513].