o(log n / log log n) rmrs randomized mutual exclusion danny hendler philipp woelfel podc 2009...

33
O(log n / log log n) RMRs Randomized Mutual Exclusion Danny Hendler Philipp Woelfel PODC 2009 Ben-Gurion University University of Calgary

Upload: elinor-blake

Post on 29-Jan-2016

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: O(log n / log log n) RMRs Randomized Mutual Exclusion Danny Hendler Philipp Woelfel PODC 2009 Ben-Gurion University University of Calgary

O(log n / log log n) RMRs Randomized Mutual Exclusion

Danny HendlerPhilipp Woelfel

PODC 2009

Ben-Gurion UniversityUniversity of Calgary

Page 2: O(log n / log log n) RMRs Randomized Mutual Exclusion Danny Hendler Philipp Woelfel PODC 2009 Ben-Gurion University University of Calgary

Talk outline

Prior art and our results Basic Algorithm (CC) Enhanced Algorithm (CC) Pseudo-code Open questions

Page 3: O(log n / log log n) RMRs Randomized Mutual Exclusion Danny Hendler Philipp Woelfel PODC 2009 Ben-Gurion University University of Calgary

Most Relevant Prior Art

Best upper bound for mutual exclusion: O(log n) RMRs (Yang and Anderson, Distributed Computing '96).

A tight Θ(n log n) RMRs lower bound for deterministic mutex

(Attiya, Hendler and Woelfel, STOC '08)

Compare-and-swap (CAS) is equivalent to read/write for RMR complexity(Golab, Hadzilacos, Hendler and Woelfel, PODC '07)

Page 4: O(log n / log log n) RMRs Randomized Mutual Exclusion Danny Hendler Philipp Woelfel PODC 2009 Ben-Gurion University University of Calgary

Our Results

Randomized mutual exclusion algorithms (for both CC/DSM)

that have:

O(log N / log log N) expected RMR complexity

against a strong adversary, and

O(log N) deterministic worst-case RMR complexity

Separation in terms of RMR complexity between

deterministic/randomized mutual exclusion algorithms

Page 5: O(log n / log log n) RMRs Randomized Mutual Exclusion Danny Hendler Philipp Woelfel PODC 2009 Ben-Gurion University University of Calgary

Shared-memory scheduling adversary types

Oblivious adversary: Makes all scheduling decisions in

advance

Weak adversary: Sees a process' coin-flip only after the

process takes the following step, can change future

scheduling based on history

Strong adversary: Can change future scheduling after

each coin-flip / step based on history

Page 6: O(log n / log log n) RMRs Randomized Mutual Exclusion Danny Hendler Philipp Woelfel PODC 2009 Ben-Gurion University University of Calgary

Talk outline

Prior art and our results Basic algorithm (CC model) Enhanced Algorithm (CC model) Pseudo-code Open questions

Page 7: O(log n / log log n) RMRs Randomized Mutual Exclusion Danny Hendler Philipp Woelfel PODC 2009 Ben-Gurion University University of Calgary

Basic Algorithm – Data Structures

1 2 Δ

Δ-1

Δ

0

1

1 2 n

Δ=Θ(log n / log log n)

Key idea:

Processes apply

randomized promotion

Key idea:

Processes apply

randomized promotion

Page 8: O(log n / log log n) RMRs Randomized Mutual Exclusion Danny Hendler Philipp Woelfel PODC 2009 Ben-Gurion University University of Calgary

Basic Algorithm – Data Structures (cont'd)

Δ-1Δ

0

1

1 2 Δ

1 2 n

lock{P,}

apply: <v1,v2, …,vΔ>

pi1 pi2 pik

Promotion Queue

notified[1…n]

Per-node structure

Page 9: O(log n / log log n) RMRs Randomized Mutual Exclusion Danny Hendler Philipp Woelfel PODC 2009 Ben-Gurion University University of Calgary

Basic Algorithm – Entry Section

Δ-1

Δ

0

1

i

Lock=

apply: <v1, , …,vΔ>iCAS(, i)

i

Page 10: O(log n / log log n) RMRs Randomized Mutual Exclusion Danny Hendler Philipp Woelfel PODC 2009 Ben-Gurion University University of Calgary

Basic Algorithm – Entry Section: scenario #2

Δ-1

Δ

0

1

i

Lock=q

apply: <v1, , …,vΔ>iCAS(,i)

Failure

Page 11: O(log n / log log n) RMRs Randomized Mutual Exclusion Danny Hendler Philipp Woelfel PODC 2009 Ben-Gurion University University of Calgary

Basic Algorithm – Entry Section: scenario #2

Δ-1

Δ

0

1

i

Lock=q

apply: <v1, , …,vΔ>i

await (n.lock=) || apply[ch]=)

Page 12: O(log n / log log n) RMRs Randomized Mutual Exclusion Danny Hendler Philipp Woelfel PODC 2009 Ben-Gurion University University of Calgary

Basic Algorithm – Entry Section: scenario #2

Δ-1

Δ

0

1

i

Lock=q

apply: <v1, , …,vΔ>i

await (n.lock=) || apply[ch]=)

Page 13: O(log n / log log n) RMRs Randomized Mutual Exclusion Danny Hendler Philipp Woelfel PODC 2009 Ben-Gurion University University of Calgary

Basic Algorithm – Entry Section: scenario #2

Δ-1

Δ

0

1

i

await (notified[i) =true)

CS

Page 14: O(log n / log log n) RMRs Randomized Mutual Exclusion Danny Hendler Philipp Woelfel PODC 2009 Ben-Gurion University University of Calgary

Climb up from leaf until last node capturedin entry section

Lock=p

apply: <v1, q, …,vΔ>

Basic Algorithm – Exit Section

Δ-1

Δ

0

1

p

Lottery

Page 15: O(log n / log log n) RMRs Randomized Mutual Exclusion Danny Hendler Philipp Woelfel PODC 2009 Ben-Gurion University University of Calgary

Perform a lottery on the root

Perform a lottery on the rootLock=p

apply: <v1, , …,vΔ>

Basic Algorithm – Exit Section

Δ-1

Δ

0

1

p

s

Promotion Queue

t

q

Page 16: O(log n / log log n) RMRs Randomized Mutual Exclusion Danny Hendler Philipp Woelfel PODC 2009 Ben-Gurion University University of Calgary

Basic Algorithm – Exit Section

Δ-1

Δ

0

1

i

await (notified[i) =true)

t

s

Promotion Queue

q

t

CSCS

Page 17: O(log n / log log n) RMRs Randomized Mutual Exclusion Danny Hendler Philipp Woelfel PODC 2009 Ben-Gurion University University of Calgary

Basic Algorithm – Exit Section (scenario #2)

Δ-1

Δ

0

1

i

Promotion Queue

EMPTY

Free Root LockFree Root Lock

Page 18: O(log n / log log n) RMRs Randomized Mutual Exclusion Danny Hendler Philipp Woelfel PODC 2009 Ben-Gurion University University of Calgary

Basic Algorithm – Properties

Lemma: mutual exclusion is satisfied

Proof intuition: when a process exits, it either

signals a single process without releasing the root's lock, or

if the promoted-processes queue is empty, releases the lock.

o When lock is free, it is captured atomically by CAS

Page 19: O(log n / log log n) RMRs Randomized Mutual Exclusion Danny Hendler Philipp Woelfel PODC 2009 Ben-Gurion University University of Calgary

Basic Algorithm – Properties (cont'd)

Lemma: Expected RMR complexity is Θ(log N / log log N)

await (n.lock=) || apply[ch]=)

A waiting process participates in a lottery every constant number of RMRs incurred here

Probability of winning a lottery is 1/Δ

Expected #RMRs incurred before promotion is Θ(log N / log log N)

Page 20: O(log n / log log n) RMRs Randomized Mutual Exclusion Danny Hendler Philipp Woelfel PODC 2009 Ben-Gurion University University of Calgary

Basic Algorithm – Properties (cont'd)

Mutual Exclusion

Expected RMR complexity:Θ(log N / log log N)

Non-optimal worst-case complexity and (even worse) starvation possible.

Page 21: O(log n / log log n) RMRs Randomized Mutual Exclusion Danny Hendler Philipp Woelfel PODC 2009 Ben-Gurion University University of Calgary

Talk outline

Prior art and our results Basic algorithm (CC) Enhanced Algorithm (CC) Pseudo-code Open questions

Page 22: O(log n / log log n) RMRs Randomized Mutual Exclusion Danny Hendler Philipp Woelfel PODC 2009 Ben-Gurion University University of Calgary

The enhanced algorithm.

Key ideaQuit randomized algorithm after incurring ‘'too many’’ RMRS and then execute a deterministic algorithm.

Problems How do we count the number of RMRs incurred? How do we “quit” the randomized algorithm?

Page 23: O(log n / log log n) RMRs Randomized Mutual Exclusion Danny Hendler Philipp Woelfel PODC 2009 Ben-Gurion University University of Calgary

Enhanced algorithm: counting RMRs problem

await (n.lock=) || apply[ch]=)

The problem: A process may incur here an unbounded number of RMRs without being aware of it.

Page 24: O(log n / log log n) RMRs Randomized Mutual Exclusion Danny Hendler Philipp Woelfel PODC 2009 Ben-Gurion University University of Calgary

Counting RMRs: solution

Key ideaPerform both randomized and deterministic promotion

Lock=p

apply: <v1, q, …,vΔ>

Increment promotion token whenever releasing a node

Perform deterministic promotion according to promotion index in addition to randomized promotion

token:

Page 25: O(log n / log log n) RMRs Randomized Mutual Exclusion Danny Hendler Philipp Woelfel PODC 2009 Ben-Gurion University University of Calgary

The enhanced algorithm: quitting problem

1 2 Δ

12 N

Upon exceeding allowed number of RMRs, why can't a

process simply release captured locks

and revert to a deterministic algorithm?

?

Upon exceeding allowed number of RMRs, why can't a

process simply release captured locks

and revert to a deterministic algorithm?

?

Waiting processes may incur RMRs without participating in lotteries!

Page 26: O(log n / log log n) RMRs Randomized Mutual Exclusion Danny Hendler Philipp Woelfel PODC 2009 Ben-Gurion University University of Calgary

Quitting problem: solution

Add a deterministic Δ-process mutex object to each node

Δ-1Δ

0

1

1 2 Δ

1 2 n

lock{P,}

apply: <v1,v2, …,vΔ>

Per-node structure

MX: Δ-process mutex token:

Page 27: O(log n / log log n) RMRs Randomized Mutual Exclusion Danny Hendler Philipp Woelfel PODC 2009 Ben-Gurion University University of Calgary

Quitting problem: solution (cont'd)

• After incurring O(log Δ) RMRs on a node, compete for the MX lock. Then spin trying to capture node lock.

• In addition to randomized and deterministic promotion, an exiting process promotes also the process that holds the MX lock, if any.

lock{P,}

apply: <v1,v2, …,vΔ>

Per-node structure

MX: Δ-process mutex

token:

Page 28: O(log n / log log n) RMRs Randomized Mutual Exclusion Danny Hendler Philipp Woelfel PODC 2009 Ben-Gurion University University of Calgary

Quitting problem: solution (cont'd)

• After incurring O(log Δ) RMRs on a node, compete for the MX lock. Then spin trying to capture node lock.

Worst-case number of RMRs = O(Δ log Δ)=O(log n)

Page 29: O(log n / log log n) RMRs Randomized Mutual Exclusion Danny Hendler Philipp Woelfel PODC 2009 Ben-Gurion University University of Calgary

Talk outline

Prior art and our results Basic algorithm (CC) Enhanced Algorithm (CC) Pseudo-code Open questions

Page 30: O(log n / log log n) RMRs Randomized Mutual Exclusion Danny Hendler Philipp Woelfel PODC 2009 Ben-Gurion University University of Calgary

Data-structures

i'th the i'th leaf

Page 31: O(log n / log log n) RMRs Randomized Mutual Exclusion Danny Hendler Philipp Woelfel PODC 2009 Ben-Gurion University University of Calgary

The entry section

i'th

Page 32: O(log n / log log n) RMRs Randomized Mutual Exclusion Danny Hendler Philipp Woelfel PODC 2009 Ben-Gurion University University of Calgary

The exit section

i'th

Page 33: O(log n / log log n) RMRs Randomized Mutual Exclusion Danny Hendler Philipp Woelfel PODC 2009 Ben-Gurion University University of Calgary

Open Problems

Is this best possible?• For strong adversary?

• For weak adversary?

• For oblivious adversary?

Is there an abortable randomized algorithm?

Is there an adaptive one?