Be My Guest MCS Lock Now Welcomes Guests Tianzheng Wang , - - PowerPoint PPT Presentation

be my guest
SMART_READER_LITE
LIVE PREVIEW

Be My Guest MCS Lock Now Welcomes Guests Tianzheng Wang , - - PowerPoint PPT Presentation

Be My Guest MCS Lock Now Welcomes Guests Tianzheng Wang , University of Toronto Milind Chabbi, Hewlett Packard Labs Hideaki Kimura, Hewlett Packard Labs Protecting shared data using locks foo() { Centralized spin locks lock.acquire();


slide-1
SLIDE 1

Be My Guest – MCS Lock Now Welcomes Guests

Tianzheng Wang, University of Toronto Milind Chabbi, Hewlett Packard Labs Hideaki Kimura, Hewlett Packard Labs

slide-2
SLIDE 2

Protecting shared data using locks

foo() { lock.acquire(); data = my_value; lock.release(); }

Contention on a centralized location Centralized spin locks – Test-and-set, ticket, etc.

– Easy implementation – Widely adopted – Waste Interconnect traffic – Cache ping-ponging lock

slide-3
SLIDE 3

MCS Locks

3

Non-standard interface

foo(qnode) { lock.acquire(qnode); data = my_value; lock.release(qnode); }

Queue nodes everywhere

granted next waiting next

R1 R2

lock

– Local spinning – FIFO order SWAP

slide-4
SLIDE 4

4

“…it was especially complicated when the critical section spans multiple

  • functions. That required having

functions also accepting an additional MCS node in its parameter.”

  • Jason Low, HPE’s Linux kernel developer

Not easy to adopt MCS lock with non-standard API

slide-5
SLIDE 5

5

“…out of the 300+ places that make use

  • f the dcache lock, 99% of the contention

came from only 2 functions. Changing those 2 functions to use the MCS lock was fairly trivial...”

  • Jason Low, HPE’s Linux kernel developer

Not all lock users are created equal

slide-6
SLIDE 6

infrequent_func…(qnod e)

– Transaction workers vs. DB snapshot composer – Worker threads vs. daemon threads

6

frequent_func(qnode) { lock.acquire(qnode); ... lock.release(qnode); } infrequent_func2(qnode ) infrequent_func1(qnode){ lock.acquire(qnode); ... lock.release(qnode); }

Regular users Guests

slide-7
SLIDE 7

Existing approaches

7

Multi-process applications Storage requirements Thread-local queue nodes Works Bloated memory usage K42-MCS Queue nodes on the stack Satisfies Cohort locks Works Extra memory per node Possible data layout change

slide-8
SLIDE 8

MCSg: best(MCS) + best(TAS)

8

Regular users

foo(qnode) { lock.acquire(qnode); ... lock.release(qnode); }

Keeps all the benefits of MCS

Guests

bar() { lock.acquire(); ... lock.release(); }

No queue node needed

slide-9
SLIDE 9

MCSg: use cases

9

– Drop-in replacement for MCS to support guests – Replace a centralized spinlock for performance

– Start from all guests, – Gradually identify regular users and adapt

– As a building block for composite locks

– Same interface as MCS – Same storage requirement

slide-10
SLIDE 10

Guests in MCSg

10

lock

: “guest has the lock”

acquire ()

CAS(NULL,)

release()

CAS(,NULL)

Guests: similar to using a centralized spin lock

Retry until success

Retry until success Standard interface

slide-11
SLIDE 11

Regular users – change in acquire()

11

 No guest: same as MCS waiting | NULL acquire(N1) r = SWAP(N1)

slide-12
SLIDE 12

Regular users – change in acquire()

12

N1 waiting | NULL acquire(N1) r = SWAP(N1)

slide-13
SLIDE 13

Regular users – change in acquire()

13

r == , return  for the guest to release the lock t = SWAP() t == N1/another ptr Retry with r = SWAP(t) r == NULL Got lock

+5 LoC in acquire(…), no change in release(…)

 waiting | NULL acquire(N1) r = SWAP(N1)

slide-14
SLIDE 14

14

MCSg++ extensions

– Guest starvation

– CAS: no guaranteed success in a bounded # of steps – Solution: attach the guest after a regular user

– FIFO order violations – Retrying XCHG might line up after a later regular user

– Solution: retry with ticket

slide-15
SLIDE 15

15

Reducing guest starvation

granted next waiting next

R1 R2 G

r = XCHG() r.next = Guest Waiting spin until r.next == Guest Granted r.next = Guest Acquired R2

slide-16
SLIDE 16

16

Reducing guest starvation

granted next waiting next

R1 R2

R2

G

r = XCHG() r.next = Guest Waiting spin until r.next == Guest Granted r.next = Guest Acquired

r = SWAP()

slide-17
SLIDE 17

17

Reducing guest starvation

granted next waiting GW

R1 R2

R2

G

r = XCHG() r.next = Guest Waiting spin until r.next == Guest Granted r.next = Guest Acquired

r = SWAP() spin

slide-18
SLIDE 18

18

Reducing guest starvation

granted next waiting GG

R1 R2

R2

G

r = XCHG() r.next = Guest Waiting spin until r.next == Guest Granted r.next = Guest Acquired

r = SWAP() spin

slide-19
SLIDE 19

19

Reducing guest starvation

granted next waiting GA

R1 R2

R2

G

r = XCHG() r.next = Guest Waiting spin until r.next == Guest Granted r.next = Guest Acquired

r = SWAP() ack

slide-20
SLIDE 20

– HP DragonHawk

– 15-core Xeon E7-4890 v2 @ 2.80GHz – 16 sockets  240 physical cores – L2 256KB/core, L3 38MB/socket, 12TB DRAM

– Microbenchmarks

– MCSg, MCSg++, CLH, K42-MCS, TATAS – Critical section: 2 cache line accesses, high contention

– TPC-C with MCSg in FOEDUS, an OSS database

20

Evaluation

slide-21
SLIDE 21

21

Maintaining MCS’s scalability

– TPC-C Payment

– 192 workers – Highly contented – one warehouse Lock MTPS STDEV TATAS 0.33 0.095 MCS 0.46 0.011 MCSg 0.45 0.004

slide-22
SLIDE 22

One guest + 223 regular users

22

224 regular users

slide-23
SLIDE 23

One guest + 223 regular users

23

Starved

slide-24
SLIDE 24

Varying number of guests

24

Total throughput

No ticketing

slide-25
SLIDE 25

Varying number of guests

25

Guest throughput

No ticketing

slide-26
SLIDE 26

– Not all lock users are created equal

– Pervasive guests prevent easy adoption of MCS lock

– MCSg: dual-interface

– Regular users: acquire/release(lock, qnode) – Infrequent guests: acquire/release(lock) – Easy-to-implement: ~20 additional LoC – As scalable as MCS (guests being minority at runtime)

26

Conclusions Find out more in our paper!