Memory Management for Self-Adjusting Computation Matthew Hammer - - PowerPoint PPT Presentation

memory management for self adjusting computation
SMART_READER_LITE
LIVE PREVIEW

Memory Management for Self-Adjusting Computation Matthew Hammer - - PowerPoint PPT Presentation

Memory Management for Self-Adjusting Computation Matthew Hammer Umut Acar Toyota Technological Institute at Chicago International Symposium on Memory Management, 2008 Overview of Talk Previous frameworks written in SML We implement a


slide-1
SLIDE 1

Memory Management for Self-Adjusting Computation

Matthew Hammer Umut Acar

Toyota Technological Institute at Chicago

International Symposium on Memory Management, 2008

slide-2
SLIDE 2

Overview of Talk

  • Previous frameworks written in SML
  • We implement a framework for C

In this talk, we

  • Briefly review self-adjusting computation
  • Discuss memory management issues
  • Introduce and evaluate our approach
  • Compare to previous SML framework

Matthew Hammer Memory Management for Self-Adjusting Computation 2 / 42

slide-3
SLIDE 3

Self-Adjusting Computation

Motivation : Incremental change is pervasive. Many applications encounter data that changes slowly or incrementally over time.

  • Applications that interact with a physical environment.

E.g., Robots.

  • Applications that interact with a user.

E.g., Games, Editors, Compilers, etc.

  • Application that rely on modeling or simulation.

E.g., Scientific Computing, Computational Biology, Motion Simulation.

Matthew Hammer Memory Management for Self-Adjusting Computation 3 / 42

slide-4
SLIDE 4

Self-Adjusting Computation

Ordinary Program Runs

Program Input 1 Output 1 Program Input 2 Output 2 Program Input N Output N

  • Ordinary programs often

run repeatedly on changing input.

  • What if input and output

change by only small increments?

Matthew Hammer Memory Management for Self-Adjusting Computation 4 / 42

slide-5
SLIDE 5

Self-Adjusting Computation

Ordinary Program Runs

Program Input 1 Output 1 Program Input 2 Output 2 Program Input N Output N small change small change

  • Ordinary programs often

run repeatedly on changing input.

  • What if input and output

change by only small increments?

Matthew Hammer Memory Management for Self-Adjusting Computation 4 / 42

slide-6
SLIDE 6

Self-Adjusting Computation

Ordinary Program Runs

Program Input 1 Output 1 Program Input 2 Output 2 Program Input N Output N small change small change

Self-Adjusting Program Runs

Self-Adj. Program Input 1 Output 1 Self-Adj. Program Input 2 Output 2 Self-Adj. Program Input N Output N Trace 1 Trace 2 Trace N-1 small change small change Matthew Hammer Memory Management for Self-Adjusting Computation 4 / 42

slide-7
SLIDE 7

Self-Adjusting Computation

  • Record execution in a

program trace

  • When input changes, a

change propagation algorithm updates the

  • utput and trace as if the

program was run “from-scratch”.

  • Tries to reuse past

computation when possible Self-Adjusting Program Runs

Self-Adj. Program Input 1 Output 1 Self-Adj. Program Input 2 Output 2 Self-Adj. Program Input N Output N Trace 1 Trace 2 Trace N-1 small change small change Matthew Hammer Memory Management for Self-Adjusting Computation 4 / 42

slide-8
SLIDE 8

Self-Adjusting Computation

Previous work has shown effectiveness for many applications: List primitives (map, reverse, . . . ) O(1) Sorting: mergesort, quicksort O(log n) 2D Convex hulls O(log n) [ESA ’06] Tree contraction [Miller, Reif ’85] O(log n) [SODA ’04]. 3D Convex Hulls O(log n) [SCG ’07] Meshing in 2D and 3D O(log n) [FWCG ’07] Bayesian Inference on Trees O(log n) [NIPS ’07] Bayesian Inference on Graphs O(sd log n) [UAI ’08] All bounds are randomized (expected time) and are within an expected constant factor of optimal or best known-bounds.

Matthew Hammer Memory Management for Self-Adjusting Computation 5 / 42

slide-9
SLIDE 9

Writing Self-Adjusting Programs

Program Input Output Self-Adj. Program Input Output Trace In Trace Out

Program Transformation

Ordinary programs may be transformed into self-adjusting ones

  • Special operations added to create/update program trace
  • Done either by hand, or via compiler support

Previous work focused on supporting SML programs

Matthew Hammer Memory Management for Self-Adjusting Computation 6 / 42

slide-10
SLIDE 10

Motivation for this Work

Want to write self-adjusting computations in C. Benefits

  • Performance (both time and space).
  • Large user base
  • Broad hardware support (e.g., robots)
  • Interoperability with other libraries/software

Challenges

  • Memory management
  • Ensuring Safety & Correct-usage

Matthew Hammer Memory Management for Self-Adjusting Computation 7 / 42

slide-11
SLIDE 11

Motivation for this Work

Want to write self-adjusting computations in C. Benefits

  • Performance (both time and space).
  • Large user base
  • Broad hardware support (e.g., robots)
  • Interoperability with other libraries/software

Challenges

  • Memory management
  • Ensuring Safety & Correct-usage

This talk will focus on memory management.

Matthew Hammer Memory Management for Self-Adjusting Computation 7 / 42

slide-12
SLIDE 12

Motivation for this Work

Want to write self-adjusting computations in C. Some Memory Management Options

  • Leave it to the programmer?

— breaks abstractions of framework

  • Use an existing collector?

— previous work suggests performance problems Our Approach Couples memory management with the existing change propagation algorithm.

  • Memory allocation recorded in program trace
  • Dead objects are identified during change propagation
  • Dead objects are reclaimed automatically

Matthew Hammer Memory Management for Self-Adjusting Computation 7 / 42

slide-13
SLIDE 13

Motivation for this Work

Want to write self-adjusting computations in C. Some Memory Management Options

  • Leave it to the programmer?

— breaks abstractions of framework

  • Use an existing collector?

— previous work suggests performance problems Our Approach Couples memory management with the existing change propagation algorithm.

  • Memory allocation recorded in program trace
  • Dead objects are identified during change propagation
  • Dead objects are reclaimed automatically

Matthew Hammer Memory Management for Self-Adjusting Computation 7 / 42

slide-14
SLIDE 14

Examples

Matthew Hammer Memory Management for Self-Adjusting Computation 8 / 42

slide-15
SLIDE 15

Self-Adjusting Primitives

3 f g 9

call read write modref (input) modref (output)

  • A modifiable reference (modref) is a

memory cell that stores changeable data.

  • The input, output and intermediate data
  • f the program is instrumented with

modrefs.

  • To access its contents, a modref is read

during a function invocation.

  • To set its contents, a modref is written
  • The program trace stores the program’s

callgraph and modref dependencies.

Matthew Hammer Memory Management for Self-Adjusting Computation 9 / 42

slide-16
SLIDE 16

Example: Mapping a List

? E

Input List Output Dest

Let’s map a list in a self-adjusting way.

  • The input is stored in

a modref

  • We have to read it to

see a list cell

  • We are given an

empty modref to write the output

Matthew Hammer Memory Management for Self-Adjusting Computation 10 / 42

slide-17
SLIDE 17

Example: Mapping a List

? E

Input List Output Dest map

read

Let’s map a list in a self-adjusting way.

  • The input is stored in

a modref

  • We have to read it to

see a list cell

  • We are given an

empty modref to write the output

Matthew Hammer Memory Management for Self-Adjusting Computation 10 / 42

slide-18
SLIDE 18

Example: Mapping a List

E

Input List Output Dest map

?

a

read read value

Cons Case

  • Read input cell
  • Map a → a’
  • Allocate output cell
  • Write output cell
  • Recurse on tails

Matthew Hammer Memory Management for Self-Adjusting Computation 10 / 42

slide-19
SLIDE 19

Example: Mapping a List

E

Input List Output Dest map

?

a

read read value

Cons Case

  • Read input cell
  • Map a → a’
  • Allocate output cell
  • Write output cell
  • Recurse on tails

Matthew Hammer Memory Management for Self-Adjusting Computation 10 / 42

slide-20
SLIDE 20

Example: Mapping a List

E

Input List Output Dest map

?

a

read read value

a'

E

allocate

Cons Case

  • Read input cell
  • Map a → a’
  • Allocate output cell
  • Write output cell
  • Recurse on tails

Matthew Hammer Memory Management for Self-Adjusting Computation 10 / 42

slide-21
SLIDE 21

Example: Mapping a List

Input List Output Dest map

?

a

read read value

a'

E

allocate write

Cons Case

  • Read input cell
  • Map a → a’
  • Allocate output cell
  • Write output cell
  • Recurse on tails

Matthew Hammer Memory Management for Self-Adjusting Computation 10 / 42

slide-22
SLIDE 22

Example: Mapping a List

Input List Output Dest map

?

a

read read value

a'

E

allocate write

map

call

Input List Output Dest

Cons Case

  • Read input cell
  • Map a → a’
  • Allocate output cell
  • Write output cell
  • Recurse on tails

Matthew Hammer Memory Management for Self-Adjusting Computation 10 / 42

slide-23
SLIDE 23

Example: Mapping a List

? E

Input List Output Dest

Nil Case

  • Read nil input
  • Write nil output

Matthew Hammer Memory Management for Self-Adjusting Computation 10 / 42

slide-24
SLIDE 24

Example: Mapping a List

? E

Input List Output Dest map

read

Nil Case

  • Read nil input
  • Write nil output

Matthew Hammer Memory Management for Self-Adjusting Computation 10 / 42

slide-25
SLIDE 25

Example: Mapping a List

nil nil E

Input List Output Dest map

read read value

Nil Case

  • Read nil input
  • Write nil output

Matthew Hammer Memory Management for Self-Adjusting Computation 10 / 42

slide-26
SLIDE 26

Example: Mapping a List

nil nil nil

Input List Output Dest map

read read value write

Nil Case

  • Read nil input
  • Write nil output

Matthew Hammer Memory Management for Self-Adjusting Computation 10 / 42

slide-27
SLIDE 27

Example: Mapping a List

map

a

read read value

a'

allocate write call

map

b

read read value

b'

allocate write call

map

c

read read value

c'

allocate write call

map

d

read read value

d'

allocate write call

nil nil nil

map

read read value write

Full trace of mapping [a,b,c,d] → [a’,b’,c’,d’]

Matthew Hammer Memory Management for Self-Adjusting Computation 11 / 42

slide-28
SLIDE 28

Example: Mapping a List

map

a

read read value

a'

allocate write call

map

b

read read value

b'

allocate write call

map

c

read read value

c'

allocate write call

map

d

read read value

d'

allocate write call

nil nil nil

map

read read value write

User removes b from input, issues propagate command

Matthew Hammer Memory Management for Self-Adjusting Computation 11 / 42

slide-29
SLIDE 29

Example: Mapping a List

map

a

read read value

a'

allocate write call

map

b

read read value

b'

allocate write call

map

c

read read value

c'

allocate write call

map

d

read read value

d'

allocate write call

nil nil nil

map

read read value write

2nd iteration of map is affected by change (old read value doesn’t match new contents)

Matthew Hammer Memory Management for Self-Adjusting Computation 11 / 42

slide-30
SLIDE 30

Example: Mapping a List

map

a

read read value

a'

allocate write call

map

read

b'

map

c

read read value

c'

allocate write call

map

d

read read value

d'

allocate write call

nil nil nil

map

read read value write

re-execute

System begins re-executing the invocation

Matthew Hammer Memory Management for Self-Adjusting Computation 11 / 42

slide-31
SLIDE 31

Example: Mapping a List

map

a

read read value

a'

allocate write call

map

read read value

b'

map

c

read read value

c'

allocate write call

map

d

read read value

d'

allocate write call

nil nil nil

map

read read value write

Invocation is re-executed using new read value

Matthew Hammer Memory Management for Self-Adjusting Computation 11 / 42

slide-32
SLIDE 32

Example: Mapping a List

map

a

read read value

a'

allocate write call

map

read read value

b'

map

c

read read value

c'

write call

map

d

read read value

d'

allocate write call

nil nil nil

map

read read value write allocate allocate

Maps c → c’ Reuses the cons cell holding c’

Matthew Hammer Memory Management for Self-Adjusting Computation 11 / 42

slide-33
SLIDE 33

Example: Mapping a List

map

a

read read value

a'

allocate write call

map

read read value

b' c c'

map

d

read read value

d'

allocate write call

nil nil nil

map

read read value write allocate

Previous owner is out-of-date, Ultimately it’s removed

Matthew Hammer Memory Management for Self-Adjusting Computation 11 / 42

slide-34
SLIDE 34

Example: Mapping a List

map

a

read read value

a'

allocate write call

map

read read value

b' c c'

map

d

read read value

d'

allocate write call

nil nil nil

map

read read value write allocate write

Writes the cons cell to the output destination (readers of this modref are now affected, if any)

Matthew Hammer Memory Management for Self-Adjusting Computation 11 / 42

slide-35
SLIDE 35

Example: Mapping a List

map

a

read read value

a'

allocate write call

map

read read value

b' c c'

map

d

read read value

d'

allocate write call

nil nil nil

map

read read value write allocate write

Call Args

call

Recursive call with arguments:

  • input_list ← read( tail( input_list ) )
  • output_dest ← tail( new_cons_cell )

Matthew Hammer Memory Management for Self-Adjusting Computation 11 / 42

slide-36
SLIDE 36

Example: Mapping a List

map

a

read read value

a'

allocate write call

map

read read value

b' c c'

map

d

read read value

d'

allocate write call

nil nil nil

map

read read value write allocate write

Call Args

call

Match

Recursive call matches a call in the trace

Matthew Hammer Memory Management for Self-Adjusting Computation 11 / 42

slide-37
SLIDE 37

Example: Mapping a List

map

a

read read value

a'

allocate write call

map

read read value

b' c c'

map

d

read read value

d'

allocate write call

nil nil nil

map

read read value write allocate write call (matches)

Matching call is reused

Matthew Hammer Memory Management for Self-Adjusting Computation 11 / 42

slide-38
SLIDE 38

Example: Mapping a List

map

a

read read value

a'

allocate write call

map

read read value

b' c c'

map

d

read read value

d'

allocate write call

nil nil nil

map

read read value write allocate write call (matches)

garbage

Allocation of b’ cell is garbage

Matthew Hammer Memory Management for Self-Adjusting Computation 11 / 42

slide-39
SLIDE 39

Example: Mapping a List

map

a

read read value

a'

allocate write call

map

read read value

c c'

map

d

read read value

d'

allocate write call

nil nil nil

map

read read value write allocate write call (matches)

Output & Trace are consistent with removal of b

Matthew Hammer Memory Management for Self-Adjusting Computation 11 / 42

slide-40
SLIDE 40

Program Traces

When a trace is updated via change propagation, old trace

  • bjects are modified and/or replaced with new trace objects.

Live trace object Trace object retained in the updated trace. Dead trace object Trace object removed from the updated trace.

Matthew Hammer Memory Management for Self-Adjusting Computation 12 / 42

slide-41
SLIDE 41

History Independence

History Independence Property A trace updated via change propagation is consistent with a from-scratch run.

Self-Adj. Program Input Output Trace Self-Adj. Program Input Output Old Trace Trace

Equivalent

Matthew Hammer Memory Management for Self-Adjusting Computation 13 / 42

slide-42
SLIDE 42

History Independence

New trace, via change propagation

map

a

read read value

a'

allocate write call

map

read read value

c c'

map

d

read read value

d'

allocate write call

nil nil nil

map

read read value write allocate write call (matches)

New Trace, “from-scratch”

map

a

read read value

a'

allocate write call

map

read

c c'

map

d

read read value

d'

allocate write call

nil nil nil

map

read read value write allocate write call read value

Matthew Hammer Memory Management for Self-Adjusting Computation 14 / 42

slide-43
SLIDE 43

The Rough Idea for Identifying Garbage

Dead allocations (aka garbage) can be attributed to:

1 Live invocations that are re-executed 2 Dead invocations that are removed

allocate

map

b'

E

map

c'

E

allocate

dead re-execute dead remove

Enrich program traces

  • Record allocations in the program trace
  • Manage allocations during change propagation

Matthew Hammer Memory Management for Self-Adjusting Computation 15 / 42

slide-44
SLIDE 44

Challenges: Dangling Pointers

Must avoid dangling pointers in program trace

  • Reclaiming dead objects too soon makes dangling pointers
  • History independence implies that an updated trace

cannot reach dead objects.

dead

map

a

read read value

a'

allocate write call

map

read

b'

map

c

read read value

c'

allocate write call

map

d

read read value

d'

allocate write call

nil nil nil

map

read read value write

re-execute

  • ut-of-date

Matthew Hammer Memory Management for Self-Adjusting Computation 16 / 42

slide-45
SLIDE 45

Challenges: Dangling Pointers

Must avoid dangling pointers in program trace

  • Reclaiming dead objects too soon makes dangling pointers
  • History independence implies that an updated trace

cannot reach dead objects.

map

a

read read value

a'

allocate write call

map

read read value

c c'

map

d

read read value

d'

allocate write call

nil nil nil

map

read read value write allocate write call (matches)

b'

Matthew Hammer Memory Management for Self-Adjusting Computation 16 / 42

slide-46
SLIDE 46

Challenges: Supporting Reuse

Reuse of calls is essential

  • The arguments must match
  • Made possible by reusing allocated objects

map

a

read read value

a'

allocate write call

map

read read value

b' c c'

map

d

read read value

d'

allocate write call

nil nil nil

map

read read value write allocate write call (matches)

Matthew Hammer Memory Management for Self-Adjusting Computation 17 / 42

slide-47
SLIDE 47

Challenges: Supporting Reuse

Reuse of calls is essential

  • The arguments must match
  • Made possible by reusing allocated objects

map

a

read read value

a'

allocate write call

map

read read value

b' c c'

map

d

read read value

d'

allocate write call

nil nil nil

map

read read value write allocate write

Call Args

call

Match

Matthew Hammer Memory Management for Self-Adjusting Computation 17 / 42

slide-48
SLIDE 48

Challenges: Supporting Reuse

Reuse of calls is essential

  • The arguments must match
  • Made possible by reusing allocated objects

map

a

read read value

a'

allocate write call

map

read read value

b'

map

c

read read value

c'

write call

map

d

read read value

d'

allocate write call

nil nil nil

map

read read value write allocate allocate

Matthew Hammer Memory Management for Self-Adjusting Computation 17 / 42

slide-49
SLIDE 49

Overview of Our Technique

Free Live Dead

  • Live Allocations

Recorded in program trace with owner.

  • Dead Allocations

Removed / Re-executed owner Maintained in a list during propagation.

  • Reuse

Each assigned a new (live) owner. Matching done via user-supplied keys.

  • Reclamation

Change propagation complete ⇒ All dead allocations are garbage (i.e., unreachable) Paper has more details

Matthew Hammer Memory Management for Self-Adjusting Computation 18 / 42

slide-50
SLIDE 50

Overview of Our Technique

Free Live Dead Allocate

  • Live Allocations

Recorded in program trace with owner.

  • Dead Allocations

Removed / Re-executed owner Maintained in a list during propagation.

  • Reuse

Each assigned a new (live) owner. Matching done via user-supplied keys.

  • Reclamation

Change propagation complete ⇒ All dead allocations are garbage (i.e., unreachable) Paper has more details

Matthew Hammer Memory Management for Self-Adjusting Computation 18 / 42

slide-51
SLIDE 51

Overview of Our Technique

Free Live Dead Allocate Remove / Re-exec

  • Live Allocations

Recorded in program trace with owner.

  • Dead Allocations

Removed / Re-executed owner Maintained in a list during propagation.

  • Reuse

Each assigned a new (live) owner. Matching done via user-supplied keys.

  • Reclamation

Change propagation complete ⇒ All dead allocations are garbage (i.e., unreachable) Paper has more details

Matthew Hammer Memory Management for Self-Adjusting Computation 18 / 42

slide-52
SLIDE 52

Overview of Our Technique

Free Live Dead Allocate Reuse Reuse Remove / Re-exec

  • Live Allocations

Recorded in program trace with owner.

  • Dead Allocations

Removed / Re-executed owner Maintained in a list during propagation.

  • Reuse

Each assigned a new (live) owner. Matching done via user-supplied keys.

  • Reclamation

Change propagation complete ⇒ All dead allocations are garbage (i.e., unreachable) Paper has more details

Matthew Hammer Memory Management for Self-Adjusting Computation 18 / 42

slide-53
SLIDE 53

Overview of Our Technique

Free Live Dead Allocate Reuse Reuse Remove / Re-exec Reclaim

  • Live Allocations

Recorded in program trace with owner.

  • Dead Allocations

Removed / Re-executed owner Maintained in a list during propagation.

  • Reuse

Each assigned a new (live) owner. Matching done via user-supplied keys.

  • Reclamation

Change propagation complete ⇒ All dead allocations are garbage (i.e., unreachable) Paper has more details

Matthew Hammer Memory Management for Self-Adjusting Computation 18 / 42

slide-54
SLIDE 54

Overview of Our Technique

Free Live Dead Allocate Reuse Reuse Remove / Re-exec Reclaim

  • Live Allocations

Recorded in program trace with owner.

  • Dead Allocations

Removed / Re-executed owner Maintained in a list during propagation.

  • Reuse

Each assigned a new (live) owner. Matching done via user-supplied keys.

  • Reclamation

Change propagation complete ⇒ All dead allocations are garbage (i.e., unreachable) Paper has more details

Matthew Hammer Memory Management for Self-Adjusting Computation 18 / 42

slide-55
SLIDE 55

Implementation: Overview

  • Implemented as a library for C
  • Primitives are “low-level”,

(e.g., we don’t enforce correct usage)

  • Dead objects reclaimed automatically

Matthew Hammer Memory Management for Self-Adjusting Computation 19 / 42

slide-56
SLIDE 56

Programming Interface

Modref Primitives Creation modref(key1, . . . , keyn) Writing write(l, v) Reading read(l) Modrefs . . .

  • May be indexed by keys.
  • Hold changeable values.
  • Track read-dependencies.

Other Primitives Allocation new(size, fi, key1, . . . , keyn) Invocation call(f, arg1, . . . , argn)

Matthew Hammer Memory Management for Self-Adjusting Computation 20 / 42

slide-57
SLIDE 57

Interface: Normal Form Programs

Reads must be in Normal Form, i.e., within a use of call Not Normal

int x = read(m1); int y = x + 1; write(m2, y);

Normal

call(incr, read(m1), m2); void incr(int x, modref_t* m) { write(m, x + 1); }

Matthew Hammer Memory Management for Self-Adjusting Computation 21 / 42

slide-58
SLIDE 58

Interface: Normal Form Programs

Reads must be in Normal Form, i.e., within a use of call Not Normal

int x = read(m1); int y = x + 1; write(m2, y);

Normal

call(incr, read(m1), m2); void incr(int x, modref_t* m) { write(m, x + 1); }

Matthew Hammer Memory Management for Self-Adjusting Computation 21 / 42

slide-59
SLIDE 59

Interface: Allocation

List Cell Structure

typedef struct { void* head; modref_t* tail; } cell_t;

List Cell Allocation

cell_t* c = new(sizeof(cell_t), cell_init, head);

List Cell Initialization

void cell_init(cell_t* c, void** keys) { c->head = keys[0]; c->tail = modref(); }

Allocated blocks are immutable (after being initialized).

Matthew Hammer Memory Management for Self-Adjusting Computation 22 / 42

slide-60
SLIDE 60

Interface Example: Mapping a List

Apply a function f to each element of a given list.

void map(cell_t* c1, void* (*f)(void* x), modref_t* result) { if (c1 == NULL) write(result, NULL); else { void* y = f(c1->head); cell_t* c2 = new(sizeof(cell_t), cell_init, y); write(result, c2); call(map, read(c1->tail), f, c2->tail); } }

To map a list input to output using f:

modref_t* output = modref(); call(map, read(input), f, output);

Matthew Hammer Memory Management for Self-Adjusting Computation 23 / 42

slide-61
SLIDE 61

Evaluation Part I

Matthew Hammer Memory Management for Self-Adjusting Computation 24 / 42

slide-62
SLIDE 62

Benchmarks

List Primitives filter, map, minimum, and sum Sorting quicksort and mergesort Computational Geometry

  • quickhull finds convex hull
  • diameter finds diameter of a set of points
  • distance finds distance between two sets of points

Tree Algorithms

  • bstverif verifies invariants of a binary search tree
  • exprtree evaluates an expression tree

Matthew Hammer Memory Management for Self-Adjusting Computation 25 / 42

slide-63
SLIDE 63

Overhead

Program Input 1 Output 1 Program Input 2 Output 2 Program Input N Output N Self-Adj. Program Input 1 Output 1 Self-Adj. Program Input 2 Output 2 Self-Adj. Program Input N Output N Trace 1 Trace 2 Trace N-1 small change small change small change small change

Overhead How much slower is the self-adjusting program when running “from-scratch”?

Matthew Hammer Memory Management for Self-Adjusting Computation 26 / 42

slide-64
SLIDE 64

Speedup

Program Input 1 Output 1 Program Input 2 Output 2 Program Input N Output N Self-Adj. Program Input 1 Output 1 Self-Adj. Program Input 2 Output 2 Self-Adj. Program Input N Output N Trace 1 Trace 2 Trace N-1 small change small change small change small change

Speedup How much faster can the self-adjusting program update the

  • utput for a small change?

Matthew Hammer Memory Management for Self-Adjusting Computation 27 / 42

slide-65
SLIDE 65

Overhead & Speedup

Application Input Size Overhead Speedup filter 106 4.2 1.7 × 105 map 106 2.4 3.0 × 105 minimum 106 2.6 1.3 × 105 sum 106 2.4 1.5 × 104 quicksort 105 2.1 5.6 × 103 mergesort 105 1.8 1.3 × 104 quickhull 105 2.1 1.9 × 103 diameter 105 2.3 1.9 × 103 distance 105 2.0 3.5 × 103 exprtree 106 2.3 1.0 × 104 bstverif 106 3.9 1.2 × 105

  • On a dual 2Ghz PowerPC G5, 6 GB of memory
  • GCC 4.0.2 with “-O3 -combine”

Matthew Hammer Memory Management for Self-Adjusting Computation 28 / 42

slide-66
SLIDE 66

Overhead & Speedup

Application Input Size Overhead Speedup filter 106 4.2 1.7 × 105 map 106 2.4 3.0 × 105 minimum 106 2.6 1.3 × 105 sum 106 2.4 1.5 × 104 quicksort 105 2.1 5.6 × 103 mergesort 105 1.8 1.3 × 104 quickhull 105 2.1 1.9 × 103 diameter 105 2.3 1.9 × 103 distance 105 2.0 3.5 × 103 exprtree 106 2.3 1.0 × 104 bstverif 106 3.9 1.2 × 105

  • Average overhead is 2 to 3x;
  • Overhead is scalable, i.e., O(1)
  • Speedups range from three to five orders of magnitude

Matthew Hammer Memory Management for Self-Adjusting Computation 28 / 42

slide-67
SLIDE 67

Evaluation Part II: Comparison to SML

Matthew Hammer Memory Management for Self-Adjusting Computation 29 / 42

slide-68
SLIDE 68

Evaluation: Setup & Measurements

Measurements SML+GC SML code including GC time SML-GC SML code excluding GC time Benchmarks List Primitives and Sorting: filter, map, minimum, sum Computational Geometry: quickhull, diameter Setup SML: MLton with “-runtime "ram-slop 1.0"”

Matthew Hammer Memory Management for Self-Adjusting Computation 30 / 42

slide-69
SLIDE 69

Quicksort: Timing comparison

50 100 150 50 100 150 200 250 300 Time (s) Input Size (n × 103) Quicksort From-Scratch SML+GC SML-GC C 5 10 15 50 100 150 200 250 300 Time (ms) Input Size (n × 103) Quicksort Ave. Update SML+GC SML-GC C

First Observations

  • SML timings excluding GC comparable to C timings.
  • SML timings including GC become 10x slower.

Matthew Hammer Memory Management for Self-Adjusting Computation 31 / 42

slide-70
SLIDE 70

Quicksort: Timing comparison

50 100 150 50 100 150 200 250 300 Time (s) Input Size (n × 103) Quicksort From-Scratch SML+GC SML-GC C 5 10 15 50 100 150 200 250 300 Time (ms) Input Size (n × 103) Quicksort Ave. Update SML+GC SML-GC C

First Observations

  • SML timings excluding GC comparable to C timings.
  • SML timings including GC become 10x slower.

Matthew Hammer Memory Management for Self-Adjusting Computation 31 / 42

slide-71
SLIDE 71

Tracing GC Cost

MLton uses a set of conventional tracing collectors (copying and mark-sweep). Analysis For tracing collectors, each reclaimed location costs O

  • 1

1 − r

  • where 0 ≤ r < 1 is the fraction of live memory.

Observation Execution traces often consume large fractions of available memory, i.e., r can approach 1 during normal usage.

Matthew Hammer Memory Management for Self-Adjusting Computation 32 / 42

slide-72
SLIDE 72

Quicksort: Tracing GC Cost

Tracing GC Cost (bytes traversed by GC) / (bytes allocated)

2 4 6 50 100 150 200 250 300 Traversed / Allocated Input Size (n × 103) Quicksort Change Propagation GC Cost

Plot of

1 1−r − 1

2 4 6 0.2 0.4 0.6 0.8 1 r 1/(1 - r) - 1

Cost increases for larger input-sizes (with larger traces).

Matthew Hammer Memory Management for Self-Adjusting Computation 33 / 42

slide-73
SLIDE 73

Generational Approaches

What about generations?

  • By partitioning objects into two or more generations GC

avoids tracing the entire heap for each collection.

  • Generational approach makes several assumptions.
  • Program traces violate each of these.

Generational Assumption Objects die young Old objects are unlikely to die Old-to-new pointers are rare Violation by Program Trace New objects are long-lived Removed objects are often old Old-to-new pointers are common

Matthew Hammer Memory Management for Self-Adjusting Computation 34 / 42

slide-74
SLIDE 74

Evaluation: From-Scratch Time (sec)

5 10 15 20 25 f i l t e r m a p m i n i m u m s u m q u i c k s

  • r

t m e r g e s

  • r

t q u i c k h u l l d i a m e t e r 74.2 SML+GC SML-GC C

Matthew Hammer Memory Management for Self-Adjusting Computation 35 / 42

slide-75
SLIDE 75

Evaluation: Average Update Time (sec)

0.0E+00 2.0E-05 4.0E-05 6.0E-05 8.0E-05 1.0E-04 1.2E-04 filter map minimum sum SML+GC SML-GC C 0.0E+00 1.0E-03 2.0E-03 3.0E-03 4.0E-03 5.0E-03 6.0E-03 quicksort mergesort quickhull diameter

Matthew Hammer Memory Management for Self-Adjusting Computation 36 / 42

slide-76
SLIDE 76

Evaluation: Space

200 400 600 800 1000 1200 filter map minimum sum quicksort mergesort quickhull diameter Max Live (MB) SML C

Matthew Hammer Memory Management for Self-Adjusting Computation 37 / 42

slide-77
SLIDE 77

Comparison Summary

Self-Adj. C vs Self-Adj. SML

  • 40-75% reduction of space usage.
  • Excluding SML GC time, they are comparable.
  • Including SML GC time, C versions up to 10x faster.

Matthew Hammer Memory Management for Self-Adjusting Computation 38 / 42

slide-78
SLIDE 78

Related Work

Reference Counting

  • Also has O(1) bound
  • Well-known challenges with overhead of counters,

and with cyclic structures. Region-based Approaches

  • Also organize objects according to “scope”
  • Usually don’t support objects moving between regions

Matthew Hammer Memory Management for Self-Adjusting Computation 39 / 42

slide-79
SLIDE 79

Future Work

On-going Front-end for C and improved runtime:

  • Simpler interface

(e.g., reads used more naturally)

  • Imperative modrefs

(i.e., multiple writes)

  • More optimizations and safety-checks

Future

  • Integration with existing, tracing collectors
  • Integration with existing, region-based approaches

Matthew Hammer Memory Management for Self-Adjusting Computation 40 / 42

slide-80
SLIDE 80

Summary

  • Memory management of self-adjusting propagation . . .
  • Couples nicely with tracing and change propagation.
  • But requires some care for correctness and reuse.
  • The result realizes the asymptotic bounds we wanted.
  • The C implementation outperforms previous

implementations in both time and space.

map

a

read read value

a'

allocate write call map read read value

b' c c'

map

d

read read value

d'

allocate write call

nil nil nil

map read read value write allocate write call (matches)

garbage

map

a

read read value

a'

allocate write call map read

c c'

map

d

read read value

d'

allocate write call

nil nil nil

map read read value write allocate write call read value

Matthew Hammer Memory Management for Self-Adjusting Computation 41 / 42

slide-81
SLIDE 81

Thanks, Questions

Thank You!

Questions?

Matthew Hammer Memory Management for Self-Adjusting Computation 42 / 42