Processes without Partitions Matthew Flatt University of Utah Adam - - PowerPoint PPT Presentation

processes without partitions
SMART_READER_LITE
LIVE PREVIEW

Processes without Partitions Matthew Flatt University of Utah Adam - - PowerPoint PPT Presentation

Processes without Partitions Matthew Flatt University of Utah Adam Wick Robert Bruce Findler University of Utah University of Chicago 1 This talk has been modified from its original version. It has been edited for content and formatted to


slide-1
SLIDE 1

Processes without Partitions

Matthew Flatt

University of Utah Adam Wick

University of Utah

Robert Bruce Findler

University of Chicago

1

slide-2
SLIDE 2

This talk has been modified from its original

  • version. It has been edited for content and

formatted to fit your screen.

2

slide-3
SLIDE 3

Machines and Processes

3

slide-4
SLIDE 4

Machines and Processes

101010 010101

4

slide-5
SLIDE 5

Machines and Processes

101010 010101

5

slide-6
SLIDE 6

Machines and Processes

λ λ

101010 010101

6

slide-7
SLIDE 7

Machines and Processes

λ λ

OS

101010 010101

7

slide-8
SLIDE 8

Machines and Processes

λ λ

VM

101010 010101

8

slide-9
SLIDE 9

Process Examples

9

slide-10
SLIDE 10

Process Examples

10

slide-11
SLIDE 11

Process Examples

11

slide-12
SLIDE 12

Process Examples

12

slide-13
SLIDE 13

Process Examples

λ

DrScheme user's program

λ

Run DrScheme

13

slide-14
SLIDE 14

Languages with Termination

Pilot [Redell80] SPIN [Bershad95] JKernel [Hawblitzel98] Alta [Tullman99] KaffeOS [Back00] JSR-121 [Soper03] .NET application domains ...

λ λ

14-15

slide-15
SLIDE 15

Languages with Termination

PLT Scheme

λ λ

16

slide-16
SLIDE 16

Motivation and Approach Processes in PLT Scheme

  • Threads
  • Parameters
  • Eventspaces
  • Custodians

Memory Accounting

17

slide-17
SLIDE 17

Threads

Concurrent execution

(require "spin-display.scm")

eval

(define (spin) (rotate-a-little) (sleep 0.1) (spin)) (define spinner (thread spin))

eval

(kill-thread spinner)

eval

18

slide-18
SLIDE 18

Parameters (a.k.a. Fluid Variables)

Thread-local state

(printf "Hello\n") (fprintf (current-output-port) "Hola\n") (fprintf (current-error-port) "Goodbye\n") (error "Ciao")

eval

(parameterize ((current-error-port (current-output-port))) (error "Au Revoir"))

eval

(parameterize ((current-error-port (current-output-port))) (thread (lambda () (error "Zai Jian"))))

eval

19

slide-19
SLIDE 19

Eventspaces

Concurrent GUIs

(thread (lambda () (message-box "One" "Hi"))) (thread (lambda () (message-box "Two" "Bye")))

eval

(thread (lambda () (message-box "One" "Hi"))) (parameterize ((current-eventspace (make-eventspace))) (thread (lambda () (message-box "Two" "Bye"))))

eval

20

slide-20
SLIDE 20

Custodians

Termination and clean-up

(define c (make-custodian)) (parameterize ((current-custodian c)) ...)

eval

(custodian-shutdown-all c)

eval

21

slide-21
SLIDE 21

Etc.

  • Security Guards

Resource access control

  • Namespaces

Global bindings

  • Will Executors

Timing of finalizations

  • Inspectors

Debugging access

22

slide-22
SLIDE 22

Building a Programming Environment

SchemeEsq, a mini DrScheme [ICFP 99]

23

slide-23
SLIDE 23

GUI - Frame

(define frame (new frame% [label "SchemeEsq"] [width 400] [height 175])) (send frame show #t)

eval

24

slide-24
SLIDE 24

GUI - Reset Button

(new button% [label "Reset"] [parent frame] [callback (lambda (b e) (reset-program))])

eval

25

slide-25
SLIDE 25

GUI - Interaction Area

(define repl-display-canvas (new editor-canvas% [parent frame]))

eval

26

slide-26
SLIDE 26

GUI - Interaction Buffer

(define esq-text% (class text% ... (evaluate str) ...)) (define repl-editor (new esq-text%)) (send repl-display-canvas set-editor repl-editor)

eval

27

slide-27
SLIDE 27

Evaluator

(define (evaluate expr-str) (thread (lambda () (print (eval (read (open-input-string expr-str)))) (newline) (send repl-editor new-prompt))))

eval

28

slide-28
SLIDE 28

Evaluator Output

(define user-output-port (make-output-port ... repl-editor ...)) (define (evaluate expr-str) (parameterize ((current-output-port user-output-port)) (thread (lambda () ...))))

eval

29

slide-29
SLIDE 29

Evaluating GUIs

(define user-eventspace (make-eventspace)) (define (evaluate expr-str) (parameterize ((current-output-port user-output-port) (current-eventspace user-eventspace)) (thread (lambda () ...)))

eval

30

slide-30
SLIDE 30

Custodian for Evaluation

(define user-custodian (make-custodian)) (define user-eventspace (parameterize ((current-custodian user-custodian)) (make-eventspace))) (define (evaluate expr-str) (parameterize ((current-output-port user-output-port) (current-eventspace user-eventspace) (current-custodian user-custodian)) (thread (lambda () ...))))

eval

31

slide-31
SLIDE 31

Reset Evaluation

(define (reset-program) (custodian-shutdown-all user-custodian) (set! user-custodian (make-custodian)) (parameterize ((current-custodian user-custodian)) (set! user-eventspace (make-eventspace))) (send repl-editor reset))

eval

32

slide-32
SLIDE 32

Motivation and Approach Processes in PLT Scheme Memory Accounting

  • Without partitions

[ISMM 04]

33

slide-33
SLIDE 33

Resource Consumption

λ

DrScheme user's program

λ

34

slide-34
SLIDE 34

Resource Consumption

λ

DrScheme user's program

λ

35

slide-35
SLIDE 35

Resource Consumption

λ

DrScheme user's program

λ

36

slide-36
SLIDE 36

Resource Consumption

λ

DrScheme user's program

λ

37

slide-37
SLIDE 37

Resource Consumption

λ

DrScheme user's program

λ

38

slide-38
SLIDE 38

Resource Consumption

λ

DrScheme user's program

λ

39

slide-39
SLIDE 39

Resource Accounting

  • Conventional OS: process memory use = size of partition

λ λ

Accounting is easy Trading data is difficult

40

slide-40
SLIDE 40

Resource Accounting

  • Language as OS: process memory use = size of owned data

λ λ

Trading data is easy Accounting appears difficult: sharing, real-time tracking

41

slide-41
SLIDE 41

Resource Accounting

Our strategy: compute accounting charges during GC

λ λ

See also [Price03]

42

slide-42
SLIDE 42

Basic Accounting

λ

= custodian A

λ

= custodian B

thread 1 thread 2 thread 3

x y z q r s

43

slide-43
SLIDE 43

Basic Accounting

λ

= custodian A

λ

= custodian B

thread 1 thread 2 thread 3

x A y A z B q A r A s B

44

slide-44
SLIDE 44

Basic Accounting

λ

= custodian A

λ

= custodian B

thread 1 thread 2 thread 3

x A y A z B, A q A r A s B, A

45

slide-45
SLIDE 45

Sharing

λ

= custodian A

λ

= custodian B

thread 1 thread 2

x y z

46

slide-46
SLIDE 46

Sharing

λ

= custodian A

λ

= custodian B

thread 1 thread 2

x A y B z A or B

47

slide-47
SLIDE 47

Sharing: Charge the Child

λ

= custodian A

λ

= custodian B

thread 1 thread 2

x A y B z B, A

48

slide-48
SLIDE 48

Threads, Custodians, and Weak References

λ

= custodian A

λ

= custodian B

thread 1 thread 2

x

49

slide-49
SLIDE 49

Threads, Custodians, and Weak References

λ

= custodian A

λ

= custodian B

thread 1 thread 2

x B

50

slide-50
SLIDE 50

Threads, Custodians, and Weak References

λ

= custodian A

λ

= custodian B

thread 1 thread 2

x B

51

slide-51
SLIDE 51

Threads, Custodians, and Weak References

λ

= custodian A

λ

= custodian B

thread 1 thread 2

x B

52

slide-52
SLIDE 52

Why Charge the Child?

λ

= custodian A

λ

= custodian B

thread 1 thread 2

x A y B z B, A

  • Parent is responsible for children
  • Parent may allocate for children

GUI objects File descriptors ...

53-55

slide-53
SLIDE 53

Initial Experience: DrScheme

Bad Loop Normal Normal

56

slide-54
SLIDE 54

Initial Experience: DrScheme

Bad Loop Normal Shut Down

57

slide-55
SLIDE 55

DrScheme Bug

λ

= DrScheme

λ

= User1

λ

= User2

thread 0 thread 1 thread 2

x y z

58

slide-56
SLIDE 56

DrScheme Repair

λ

= DrScheme

λ

= User1

λ

= User2

thread 0 thread 1 thread 2

x y z

59

slide-57
SLIDE 57

DrScheme Repair

λ

= DrScheme

λ

= User1

λ

= User2

thread 0 thread 1 thread 2

x y z Changed 5 references:

  • Weakened 2
  • Removed 2
  • Moved 1 into child

60

slide-58
SLIDE 58

Current Experience: DrScheme

Bad Loop Normal Normal

61

slide-59
SLIDE 59

Current Experience: DrScheme

Shut Down Normal Normal

62

slide-60
SLIDE 60

Accounting without Partitions

Useful accounting

  • Doesn't need partitions
  • Does need hierarchy

63

slide-61
SLIDE 61

Conclusion

λ λ

  • Programmers need OS-like constructs in languages

concurrency adjust run-time environment easy termination

  • Multiple language constructs for “process”

programmer can mix and match to balance isolation and cooperation

64