Section 19.2.11

Partial-order reduction and commuting actions

Definition

Partial-order reduction is a technique that lets a model checker §3.30, a tool that explores every reachable state §3.21 of a system, skip orderings of concurrent actions that cannot affect the property being checked. Two actions are commuting actions in a state when they can run in either order from that state and both orders end in the same state. For actions that are independent, meaning that they commute and neither enables nor disables the other wherever both can run, the checker explores one representative order instead of every order.

The idea

A model checker examines concurrent software by exploring interleavings: the orders in which the actions of separate threads, tasks or devices can run. Many interleavings differ only in the order of actions that do not interact. With nn tasks that each set their own flag, there are n!n! orders through 2n2^n states, all ending in the same final state; 3 tasks already give 3!=3×2×1=63! = 3 \times 2 \times 1 = 6 orders. This growth is part of state explosion §3.26, the main practical limit of model checking.

The intuition is two people writing on separate sheets of paper: who writes first changes neither sheet. A run is then better described by a partial order §19.2.6, which records only which actions must come before which, than by one sequence. All sequences consistent with one partial order are equivalent, and checking one of them is enough if the property cannot tell them apart. The picture breaks when someone looks halfway through: a property that compares the two sheets, an observer, or a crash between the two actions can tell which went first.

How it works

Partial-order reduction works in three steps.

  1. Decide which actions are independent. Two actions are independent when, in every state where both are enabled, meaning allowed to run, neither disables the other and they commute. Tools approximate this from read and write sets: two actions count as independent when neither writes a variable that the other reads or writes, including the variables of the other’s enabling condition. Any pair not shown independent is treated as dependent, which costs reduction but never hides a behavior.

  2. Mark the visible actions. An action is visible when it can change the truth of a basic statement (an atomic proposition) that the property mentions, such as “y=1y = 1”.

  3. At each state, explore a subset of the enabled actions, called an ample set; related methods call it a persistent set or a stubborn set. Four conditions, given under Stated precisely, make this safe. In short: the subset is empty only when nothing is enabled; no action outside it that depends on an action in it can run first; it holds only invisible actions unless it holds every enabled action; and no enabled action is postponed forever around a cycle.

Sleep sets add a further saving: they record actions whose continuation has already been explored in an equivalent order, so the same pair of independent actions is not explored in both orders. Dynamic partial-order reduction, introduced by Flanagan and Godefroid in 2005 [439], discovers dependence during exploration from the memory locations that actions actually touch, which helps where a static analysis §3.1 cannot tell whether two pointer or array §14.5 accesses meet.

Worked example

Two tasks run at the same time. Task 1 performs action XX, which writes record xx: x:=1x := 1. Task 2 performs action YY, which writes record yy: y:=1y := 1. A state is the pair (x,y)(x, y), starting at (0,0)(0, 0). Full exploration finds 4 states, 4 steps and two orders: XX then YY visits (0,0)(0, 0), (1,0)(1, 0), (1,1)(1, 1), and YY then XX visits (0,0)(0, 0), (0,1)(0, 1), (1,1)(1, 1). Both orders are possible and end in (1,1)(1, 1), and neither write disables the other, so XX and YY are independent.

Let the property be “if y=1y = 1 then x=1x = 1”: record yy is a selector that may announce record xx only after xx is written. The order YY then XX passes through (0,1)(0, 1) and violates it. A reduction based on independence alone would explore only XX at (0,0)(0, 0), visit (0,0)(0, 0), (1,0)(1, 0) and (1,1)(1, 1), and report no violation. The visibility condition, C2 under Stated precisely, prevents this: both writes change a record the property mentions, so both are visible, the ample set at (0,0)(0, 0) must hold both, and both orders are explored.

A crash between the writes is handled the same way. Model it as an action CC, enabled in every state, that stops both tasks and keeps the records as they are. CC disables XX and YY, so it depends on both. By condition C1, an ample set at (0,0)(0, 0) that holds XX must also hold CC, which depends on XX and could otherwise run first, and then also YY, which depends on CC. The reduction therefore keeps a crash at both (1,0)(1, 0) and (0,1)(0, 1), which a recovery routine may treat differently.

Where the reduction applies, the saving is large. Take nn tasks that each write their own record and a property that mentions none of the records. The full state graph has 2n2^n states, one for each set of finished tasks, and n×2n−1n \times 2^{n-1} steps. An ample set of one write per state meets all four conditions and leaves n+1n + 1 states and nn steps. For n=10n = 10, 1024 states and 10×512=512010 \times 512 = 5120 steps shrink to 11 states and 10 steps, and 10!=3,628,80010! = 3{,}628{,}800 orders shrink to one.

Stated precisely

Let ss be a state and α\alpha an action. Write enabled(s)\mathrm{enabled}(s) for the set of actions that can run in ss, and α(s)\alpha(s) for the state that α\alpha produces from ss. An independence relation II is a symmetric set of pairs of distinct actions such that, for every pair (α,β)∈I(\alpha, \beta) \in I and every state ss in which both α\alpha and β\beta are in enabled(s)\mathrm{enabled}(s): enabledness:β∈enabled(α(s)) and α∈enabled(β(s)),commutativity:β(α(s))=α(β(s)).\begin{aligned} &\text{enabledness:} && \beta \in \mathrm{enabled}(\alpha(s)) \text{ and } \alpha \in \mathrm{enabled}(\beta(s)), \\ &\text{commutativity:} && \beta(\alpha(s)) = \alpha(\beta(s)). \end{aligned} Two actions that are not independent are dependent.

Two finite sequences of actions are equivalent when one can be turned into the other by repeatedly swapping two adjacent independent actions. The equivalence classes are called Mazurkiewicz traces, after Antoni Mazurkiewicz. Each class corresponds to one partial order of the action occurrences, which gives the technique its name.

Let ample(s)\mathrm{ample}(s), a subset of enabled(s)\mathrm{enabled}(s), be the set of actions that the reduced search explores from ss. In the formulation of the textbook Model Checking by Clarke, Grumberg and Peled [524], the conditions are:

C0

ample(s)\mathrm{ample}(s) is empty only if enabled(s)\mathrm{enabled}(s) is empty.

C1

On every path of the full state graph that starts at ss, no action that depends on an action in ample(s)\mathrm{ample}(s) runs before some action in ample(s)\mathrm{ample}(s) runs.

C2

If ample(s)≠enabled(s)\mathrm{ample}(s) \neq \mathrm{enabled}(s), every action in ample(s)\mathrm{ample}(s) is invisible: it never changes the truth of a basic statement that the property mentions.

C3

No cycle of the reduced state graph contains a state in which some action is enabled that is in the ample set of no state on the cycle.

The guarantee: let φ\varphi be a formula of linear temporal logic, a logic of properties of single runs such as “always pp” for a basic statement pp, that does not use the next operator, “in the very next state”. If C0 to C3 hold at every explored state, the reduced state graph satisfies φ\varphi if and only if the full state graph does. The next operator is excluded because the reduction changes how many invisible steps lie between visible ones. The guarantee assumes a correct independence relation and visibility marking, and a model that includes, as actions, every crash and observer that the property must cover.

Limits and common mistakes

Questions answered

Can two writes to different records always commute?

No. Two writes to different records commute, meaning that both orders are possible and end in the same state, only when they share no state in the model and neither write enables or disables the other. Different records can share a hidden log position, an erase block of flash memory, a free-space limit or a checksum, and a capacity limit can let one write prevent the other.

Even when both orders end in the same state, they pass through different intermediate states: new xx with old yy, or old xx with new yy. A property such as “selector yy announces only a complete record xx”, an observer that reads between the writes, or a crash between them can tell these apart. Partial-order reduction, which lets a model checker explore one order of independent actions instead of all, may skip the second order only if the writes are independent and invisible to the property, and only if crashes and observers are modeled as actions, so that the reduction’s conditions keep every order they can distinguish.

Related entries: State explosion (§3.26), Model checking (§3.30), Race condition (§9.2). Further reading: [439, 524].