xCalls: Safe I/O in Memory Transactions

19
xCalls: Safe I/O in Memory Transactions Haris Volos, Andres Jaan Tack, Neelam Goyal + , Michael Swift, Adam Welc § University of Wisconsin - University of Wisconsin - Madison Madison + §

description

xCalls: Safe I/O in Memory Transactions. Haris Volos , Andres Jaan Tack, Neelam Goyal + , Michael Swift, Adam Welc §. University of Wisconsin - Madison. §. +. Transactional Memory (TM). CMP leads to more concurrency within programs - PowerPoint PPT Presentation

Transcript of xCalls: Safe I/O in Memory Transactions

Page 1: xCalls: Safe I/O in Memory Transactions

xCalls: Safe I/O in Memory Transactions

Haris Volos,Andres Jaan Tack, Neelam Goyal+,

Michael Swift, Adam Welc§

University of Wisconsin - MadisonUniversity of Wisconsin - Madison+ §

Page 2: xCalls: Safe I/O in Memory Transactions

• CMP leads to more concurrency within programs• Synchronizing access to shared data via locks is hard

• atomic construct simplifies synchronizing access to shared data

atomic { x = x - c; y = y + c;}

LOCK(L) x = x - c; y = y + c;UNLOCK(L)

store(A)store(B)store(A)

Transactional Memory (TM)

Thread 1

atomic { A = A – 20; B = B + 20;}

atomic { B = B – 10; A = A + 10;}

Thread 2

Atomicity:PERFORM both updates to A and B or none

Isolation:OBSERVE both red transaction’s updates to A and B or none

ABORT conflicting transactions

Abort blue

Conflict

2

Page 3: xCalls: Safe I/O in Memory Transactions

A challenging world…• Real world programs frequently take actions

outside of their own memory– Firefox: ~1% critical sections do system call [Baugh TRANSACT ’07]

• Most TM systems apply only to user-level memory

Thread 1

atomic { item = procItem(queue); write (file, principal); write (file, item->header);}

atomic { item = procItem(queue); write (file, principal); write (file, item->header);}

memory file Thread 21a2b2b

1a

Abort

Interleaved writes

File writes not dropped

Memory updates dropped

3

1a

1b

2a

2b

Page 4: xCalls: Safe I/O in Memory Transactions

State of the art

• Defer• Undo• Global Lock

Ignore failures

Stop the world

4

atomic { item = procItem(queue); write (file, principal); write (file, item->header); send (socket, item->body);}

LAN

Internet

NAS

COMMITPerform send

Defer

Page 5: xCalls: Safe I/O in Memory Transactions

Contribution

5

• xCall programming interface– Exposes transactional semantics to programmer– Enables I/O within transactions w/o stopping the world– Exposes all failures to the program

Transactional Program

Transaction-unaware kernel

System call interface

xCall Library

Legacy calls

xCalls

Runs in user mode

Page 6: xCalls: Safe I/O in Memory Transactions

Outline

• Motivation• xCall Design & Implementation• Evaluation• Conclusion

6

Page 7: xCalls: Safe I/O in Memory Transactions

Design overview

• Principles1. As early as possible but not earlier2. Expose all failures

• Components– Atomic execution– Isolation– Error handling

7

Page 8: xCalls: Safe I/O in Memory Transactions

Atomic execution

• Provide abort semantics for kernel data and I/O

Expose to programmer when action is performed

8

atomic { item = procItem(queue); x_write (file, principal); x_write (file, item->header);}

file

Abort

buffers

Can reverse action? Need result? Execution Example

No Yes Global lock ioctl()

No No Defer x_write_pipe()

Yes -- In-place x_write()

Page 9: xCalls: Safe I/O in Memory Transactions

Isolation

• Prevent conflicting changes to kernel data made within a transaction

Sentinels– Revocable user-level locks– Lock logical kernel state visible through system calls

Thread 1

atomic { item = procItem(queue); x_write (file, principal); x_write (file, item->header);}

atomic { item = procItem(queue); x_write (file, principal); x_write (file, item->header);}

memory file Thread 2

Conflict

9

Page 10: xCalls: Safe I/O in Memory Transactions

atomic { item = procItem(queue); x_write (file, principal, &err1); x_write (file, item->header, &err2); x_send (socket, item->body, &err3);}if (err1 || err2 || err3) { /* CLEANUP */}

Error handling

• Some errors might not happen until transaction commits or aborts

Inform programmer when failures happen– Handle errors after transaction completes

LAN

InternetDefer

Deferred send: FAILEDerr3 = error

COMMITPerform send

Handle errorhere

10

Page 11: xCalls: Safe I/O in Memory Transactions

ssize_t x_write (int fd, void *buf, ssize_t nbytes ) { void *localbuf; ssize_t bytes; get_sentinel(fd); localbuf = alloc_local_buf(nbytes); read(fd, localbuf, nbytes); bytes = write(fd, buf, nbytes); if (bytes != -1) compensate(x_undo_write, fd, localbuf, bytes, result);}int x_undo_write (int fd, void *buf, ssize_t nbytes, int *result){ off_t ret1, ret2; lseek(fd, -nbytes, SEEK_CUR); if (ret1) pwrite(fd, buf, nbytes, ret1); if (ret1 == -1 || ret2 == -1) *result = errno; return (ret1 == -1 || ret2 == -1);

}

Example: file write

, int *result

Atomic execution

Atomic execution

Atomic execution

Isolation

Error handling

Error handling

ret2 =

11

ret1 =

Page 12: xCalls: Safe I/O in Memory Transactions

Summary

• xCall API exposes transactional semantics– Atomicity– Isolation– Error handling

• Prototype implementation– Executes as user-mode library– Relies on Intel STM for transactional memory– Provides 27 xCalls including file handling,

communication, threading12

Page 13: xCalls: Safe I/O in Memory Transactions

Outline

• Motivation• xCall Design & Implementation• Evaluation– Benefit of xCalls over global lock– Benefit of TM over locks

• Conclusion

13

Page 14: xCalls: Safe I/O in Memory Transactions

Evaluation platform

• Transactified three large multithreaded apps– Berkeley DB– BIND– XMMS

• Configurations– Native : locks + system calls – STM : transactions + system calls + global lock– xCalls : transactions + xCalls

• Run on 4 quad-core 2 GHz AMD Barcelona14

Page 15: xCalls: Safe I/O in Memory Transactions

Performance: Berkeley DB (1/2)

15

• xCalls scales better than STM with global lock• TM worse than locks due to STM overhead

• Workload: TPC-C

Page 16: xCalls: Safe I/O in Memory Transactions

Performance: Berkeley DB (2/2)

16

• xCalls improve concurrency over coarse grain lock• Global lock kills optimistic concurrency

• Workload: Lockscale

Page 17: xCalls: Safe I/O in Memory Transactions

Performance: BIND

17

• Transactions scale better than coarse grain locks• xCalls enable additional concurrency

• Workload: QueryPerf

Page 18: xCalls: Safe I/O in Memory Transactions

Performance summary

18

• xCalls benefit programs with I/O concurrency• TM benefits programs with contended but not

conflicting critical sections

Page 19: xCalls: Safe I/O in Memory Transactions

Conclusion

• xCall programming interface– Brings common OS services to TM programs– Requires no kernel modifications– Improves scalability over state of the art

19

Questions?