Short-term Memory for Self-collecting Mutators Martin Aigner, Andreas - - PowerPoint PPT Presentation

short term memory for self collecting mutators
SMART_READER_LITE
LIVE PREVIEW

Short-term Memory for Self-collecting Mutators Martin Aigner, Andreas - - PowerPoint PPT Presentation

Introduction Self-collecting Mutators Implementation Experiments Short-term Memory for Self-collecting Mutators Martin Aigner, Andreas Haas , Christoph M. Kirsch, Michael Lippautz, Ana Sokolova, Stephanie Stroka, Andreas Unterweger University


slide-1
SLIDE 1

Introduction Self-collecting Mutators Implementation Experiments

Short-term Memory for Self-collecting Mutators

Martin Aigner, Andreas Haas, Christoph M. Kirsch, Michael Lippautz, Ana Sokolova, Stephanie Stroka, Andreas Unterweger

University of Salzburg

October 12, 2010

slide-2
SLIDE 2

Introduction Self-collecting Mutators Implementation Experiments Heap Management

Heap Management

heap

slide-3
SLIDE 3

Introduction Self-collecting Mutators Implementation Experiments Heap Management

Heap Management

needed heap

slide-4
SLIDE 4

Introduction Self-collecting Mutators Implementation Experiments Heap Management

Heap Management

needed not needed heap

slide-5
SLIDE 5

Introduction Self-collecting Mutators Implementation Experiments Heap Management

Heap Management

needed reachable heap

slide-6
SLIDE 6

Introduction Self-collecting Mutators Implementation Experiments Heap Management

Heap Management

needed reachable unreachable heap

slide-7
SLIDE 7

Introduction Self-collecting Mutators Implementation Experiments Heap Management

Heap Management

needed reachable unreachable heap explicit memory management deallocates here

slide-8
SLIDE 8

Introduction Self-collecting Mutators Implementation Experiments Heap Management

Heap Management

needed reachable unreachable heap explicit memory management deallocates here

  • memory leaks
slide-9
SLIDE 9

Introduction Self-collecting Mutators Implementation Experiments Heap Management

Heap Management

needed reachable unreachable heap explicit memory management deallocates here

  • memory leaks
  • dangling pointers
slide-10
SLIDE 10

Introduction Self-collecting Mutators Implementation Experiments Heap Management

Heap Management

needed reachable unreachable heap explicit memory management deallocates here garbage collectors deallocate here

  • memory leaks
  • dangling pointers
slide-11
SLIDE 11

Introduction Self-collecting Mutators Implementation Experiments Heap Management

Heap Management

needed reachable unreachable heap explicit memory management deallocates here garbage collectors deallocate here

  • memory leaks
  • dangling pointers
  • tracing
slide-12
SLIDE 12

Introduction Self-collecting Mutators Implementation Experiments Heap Management

Heap Management

needed reachable unreachable heap explicit memory management deallocates here garbage collectors deallocate here

  • memory leaks
  • dangling pointers
  • tracing
  • reference counting
slide-13
SLIDE 13

Introduction Self-collecting Mutators Implementation Experiments Heap Management

Heap Management

needed reachable unreachable heap explicit memory management deallocates here garbage collectors deallocate here

  • memory leaks
  • dangling pointers
  • tracing
  • reference counting
  • reachable memory leaks
slide-14
SLIDE 14

Introduction Self-collecting Mutators Implementation Experiments Persistent Memory Model

Persistent Memory Model

Allocated memory objects are guaranteed to exist until deallocation Explicit deallocation is not safe (dangling pointers) and can be space-unbounded (memory leaks) Implicit deallocation (unreachable objects) is safe but may be slow or space-consuming (proportional to the size of live memory) and can still be space-unbounded (memory leaks)

slide-15
SLIDE 15

Introduction Self-collecting Mutators Implementation Experiments Short-term Memory

Short-term Memory

Memory objects are only guaranteed to exist for a finite amount of time Memory objects are allocated with a given expiration date Memory objects are neither explicitly nor implicitly deallocated but may be refreshed to extend their expiration date

slide-16
SLIDE 16

Introduction Self-collecting Mutators Implementation Experiments Short-term Memory

Short-term Memory With short-term memory programmers or algorithms specify which memory objects are still needed and not which memory objects are not needed anymore!

slide-17
SLIDE 17

Introduction Self-collecting Mutators Implementation Experiments Short-term Memory

Short-term Memory

needed reachable heap not expired unreachable

slide-18
SLIDE 18

Introduction Self-collecting Mutators Implementation Experiments Short-term Memory

Short-term Memory

needed reachable heap not expired

conservative refresh

slide-19
SLIDE 19

Introduction Self-collecting Mutators Implementation Experiments Short-term Memory

Short-term Memory

needed reachable heap not expired

conservative refresh conservative expiration

slide-20
SLIDE 20

Introduction Self-collecting Mutators Implementation Experiments Short-term Memory

Short-term Memory - Sources of Errors

Memory leaks

When not-needed objects are continuously refreshed When time does not advance

Dangling Pointers

When needed objects are not refreshed

slide-21
SLIDE 21

Introduction Self-collecting Mutators Implementation Experiments

Self-collecting Mutators

slide-22
SLIDE 22

Introduction Self-collecting Mutators Implementation Experiments Programming Model

Programming Model

Explicit memory management

The programmer (or an algorithm) adds memory management calls to the program code

Hybrid approach for backward compatibility

Per default objects are allocated as persistent and managed by the existing memory management (malloc/free, garbage collection) A refresh-call makes an object short-term, e.g. the objects gets an expiration date

slide-23
SLIDE 23

Introduction Self-collecting Mutators Implementation Experiments Expiration Date

Programming Model - Expiration Date

An object gets an expiration date when it gets refreshed and is then managed by our system A programmer refreshes objects explicitly

Every refresh-call creates a new expiration date for an object

The object expires when all its expiration dates are expired

slide-24
SLIDE 24

Introduction Self-collecting Mutators Implementation Experiments Time

Programming Model - Time

A software clock is used for object expiration

An integer counter which is increased by tick-calls An expiration date has expired when its value is less than the time of the software clock

Every thread has its own thread-local clock

Expiration dates expire according to the clock of the thread which created the expiration date

slide-25
SLIDE 25

Introduction Self-collecting Mutators Implementation Experiments Examples

Example - Monte Carlo

monteCarlo ( int r e p e t i t i o n s ) { Vector r e s u l t s = new Vector ( r e p e t i t i o n s ) ; for ( int i = 0; i < r e p e t i t i o n s ; i++) { RandomWalk walk = createRandomWalk ( ) ; r e s u l t s . add ( d o C a l c u l a t i o n ( walk ) ; } e v a l u a t e R e s u l t s ( r e s u l t s ) ; }

slide-26
SLIDE 26

Introduction Self-collecting Mutators Implementation Experiments Examples

Example - Monte Carlo

monteCarlo ( int r e p e t i t i o n s ) { Vector r e s u l t s = new Vector ( r e p e t i t i o n s ) ; for ( int i = 0; i < r e p e t i t i o n s ; i++) { RandomWalk walk = createRandomWalk ( ) ;

  • SCM. r e f r e s h ( walk ,

0 ) ; r e s u l t s . add ( d o C a l c u l a t i o n ( walk ) ;

  • SCM. t i c k ( ) ;

} e v a l u a t e R e s u l t s ( r e s u l t s ) ; }

slide-27
SLIDE 27

Introduction Self-collecting Mutators Implementation Experiments Examples

Example - x264 Video Encoder

pop_unused push_unused unused frame pool

processing unit reference buffers input frames

  • utput

refresh malloc 1 2 3 4 5 6 tick 7

  • r

concurrent

2

slide-28
SLIDE 28

Introduction Self-collecting Mutators Implementation Experiments Examples

Other Use Cases

benchmark LoC tick refresh free aux total mpg123 16043 1 (-)43 44 JLayer 8247 1 6 2 9 Monte Carlo 1450 1 3 2 6 LuIndex 74584 2 15 3 20

Table: Use cases of short-term memory: lines of code of the benchmark, number of tick-calls, number of refresh-calls, number of free-calls, number of auxiliary lines of code, and total number of modified lines of code.

slide-29
SLIDE 29

Introduction Self-collecting Mutators Implementation Experiments

Implementation

slide-30
SLIDE 30

Introduction Self-collecting Mutators Implementation Experiments

Implementation

Our implementation is called self-collecting mutators (SCM)

The threads (mutators) of a program collect their expired

  • bjects by themselves

At memory management calls a constant number of expired

  • bjects are collected

We have implementations in C, Java and Go The C implementation is based on ptmalloc2 The Java implementation is based on the Jikes RVM For the Go implementation we extended the 6g Go runtime Available at: tiptoe.cs.uni-salzburg.at/short-term-memory

slide-31
SLIDE 31

Introduction Self-collecting Mutators Implementation Experiments Descriptors

Implementation - Descriptors

An Object can have multiple expiration dates

An expiration date is represented by a descriptor, which stores the expiration date and a pointer to the object

For each expiration date of an object there exists one descriptor

Every object contains a descriptor counter (1 word) in its header which counts the number of descriptors pointing to it 4 Object Descriptor

Expiration Date Pointer to the object

1

slide-32
SLIDE 32

Introduction Self-collecting Mutators Implementation Experiments Descriptors

Implementation - Descriptors Buffer

expired descriptor 4 4 4 4 5 5 5 5 5 5 6 6 6 7 7 7 7 7 1 1 1 2 2 3 3 3 3 not-expired descriptor time=4

slide-33
SLIDE 33

Introduction Self-collecting Mutators Implementation Experiments Descriptors

Implementation - Descriptor Buffer

expired descriptor list 4 5 6 7 time=4

slide-34
SLIDE 34

Introduction Self-collecting Mutators Implementation Experiments Descriptors

Implementation - Descriptor Buffer

expired descriptor list 4 5 6 7 1 2 3 4 mod 4 = 5 mod 4 = 6 mod 4 = 7 mod 4 = time = 4 maximal expiration extension = 3

slide-35
SLIDE 35

Introduction Self-collecting Mutators Implementation Experiments Descriptors

Implementation - Descriptor Buffer

slide-36
SLIDE 36

Introduction Self-collecting Mutators Implementation Experiments malloc/new

Implementation - malloc/new

Definition malloc(size) new Object() The malloc/new call of SCM increases the requested amount

  • f memory by one word and uses the underlying memory

management then to allocate the memory

In C it is ptmalloc2 In Java and Go it is a mark-sweep garbage collector

The additional header word of an object is used for the descriptor counter The descriptor counter is initialized with zero

slide-37
SLIDE 37

Introduction Self-collecting Mutators Implementation Experiments refresh

Implementation - refresh

Definition refresh(object, extension) The refresh-call creates a new descriptor for the considered

  • bject

The refresh-call consists of four operations:

1

Increase the descriptor counter of the specified object

2

Create a new descriptor and store it in the descriptor buffer which corresponds to the given expiration extension.

3

(Self-collection) Remove one descriptor from the expired descriptors list

4

Decrease the descriptor counter of the object which corresponds to that descriptor

If the descriptor counter gets zero, the object is deallocated

slide-38
SLIDE 38

Introduction Self-collecting Mutators Implementation Experiments refresh

Before refresh

expired descriptor list 4 5 6 7 1 2 3 4 mod 4 = 5 mod 4 = 6 mod 4 = 7 mod 4 = time=4 refresh(object, 0);

slide-39
SLIDE 39

Introduction Self-collecting Mutators Implementation Experiments refresh

After refresh

expired descriptor list 4 5 6 7 1 2 3 4 mod 4 = 5 mod 4 = 6 mod 4 = 7 mod 4 = time=4 refresh(object, 0); add one descriptor remove one descriptor

slide-40
SLIDE 40

Introduction Self-collecting Mutators Implementation Experiments tick

Implementation - tick

Definition tick() The tick-call increases the thread-local time The descriptor list which expires by that time advance is appended to the expired descriptor list

slide-41
SLIDE 41

Introduction Self-collecting Mutators Implementation Experiments tick

Before tick

expired descriptor list 4 5 6 7 1 2 3 4 mod 4 = 5 mod 4 = 6 mod 4 = 7 mod 4 = time=4

slide-42
SLIDE 42

Introduction Self-collecting Mutators Implementation Experiments tick

After tick

expired descriptor list 8 5 6 7 1 2 3 8 mod 4 = 5 mod 4 = 6 mod 4 = 7 mod 4 = time=5

slide-43
SLIDE 43

Introduction Self-collecting Mutators Implementation Experiments free

Implementation - free

Definition free(object) In C it is still possible to use the free-call for explicit deallocation When the descriptor counter of the object is zero, the object is deallocated Otherwise nothing is done

The object will be deallocated when its last descriptor expires

slide-44
SLIDE 44

Introduction Self-collecting Mutators Implementation Experiments Garbage Collector

Implementation - Garbage Collector

All objects are considered to compute reachability Short-term objects are not deallocated

They will be deallocated when their last descriptor expires

slide-45
SLIDE 45

Introduction Self-collecting Mutators Implementation Experiments

Experiments

slide-46
SLIDE 46

Introduction Self-collecting Mutators Implementation Experiments

What we want to show

In C

Short-term memory is easier to use while not loosing temporal performance and with low memory overhead

In Java and Go

Short-term memory is more difficult to use but improves temporal performance (e.g. reduce the number of garbage collection runs)

slide-47
SLIDE 47

Introduction Self-collecting Mutators Implementation Experiments

Experiments - System Configuration

CPU 2x AMD Opteron DualCore, 2.0 GHz RAM 4GB OS Linux 2.6.32-21-generic Java VM Jikes RVM 3.1.0 C compiler gcc version 4.4.3 C allocator ptmalloc2-20011215 (glibc-2.10.1)

Table: System configuration.

slide-48
SLIDE 48

Introduction Self-collecting Mutators Implementation Experiments Monte Carlo

Monte Carlo - Total Runtime

98 100 102 104 106 108 110 112 114 116 MC leaky MC fixed 4xMC fixed total runtime in % of the runtime of SCM (lower is better) Monte Carlo Benchmarks SCM(50,20) GEN MS SCM(50,20) double memory GEN double memory MS double memory

Figure: Total execution time of the Monte Carlo benchmarks in percentage of the total execution time of the benchmark using self- collecting mutators.

slide-49
SLIDE 49

Introduction Self-collecting Mutators Implementation Experiments Monte Carlo

Monte Carlo - Latency and Free Memory

5 10 15 20 25 30 35 40 45 500 1000 1500 2000 2500 100 1000 10000 100000 free memory in MB (higher is better) loop execution time in microseconds (logarithmic) (lower is better) loop iteration GEN free memory MS free memory SCM free memory GEN loop execution time MS loop execution time SCM loop execution time

Figure: Free memory and loop execution time of the fixed Monte Carlo benchmark.

slide-50
SLIDE 50

Introduction Self-collecting Mutators Implementation Experiments Monte Carlo

Monte Carlo - Tick Frequency - Latency

500 1000 5000 1000 2000 3000 4000 5000 6000 7000 8000 9000 loop execution time in microseconds (logarithmic) (lower is better) loop iteration 1 tick/1 iteration 1 tick/50 iterations 1 tick/200 iterations

Figure: Loop execution time of the Monte Carlo benchmark with different tick frequencies. Self-collecting mutators is used.

slide-51
SLIDE 51

Introduction Self-collecting Mutators Implementation Experiments Monte Carlo

Monte Carlo - Tick Frequency - Free Memory

16 18 20 22 24 26 28 1 10 100 1000 free memory in MB (higher is better) loop iteration (logarithmic) 1 tick/1 iteration 1 tick/50 iterations 1 tick/200 iterations

Figure: Free memory of the Monte Carlo benchmark with different tick

  • frequencies. Self-collecting mutators is used.
slide-52
SLIDE 52

Introduction Self-collecting Mutators Implementation Experiments mpg123 MP3 converter

mpg123 - Total Runtime

ptmalloc2 895.25ms 100.00% ptmalloc2 through SCM 899.43ms 100.47% SCM(1, 256B) 890.18ms 99.43% SCM(10, 256B) 898.28ms 100.34% SCM(1, 4KB) 892.18ms 99.66% SCM(10, 4KB) 892.28ms 99.67%

Table: Total execution times of the mpg123 benchmark averaged over 100 repetitions. Here, SCM(n, m) stands for self-collecting mutators with a maximal expiration extension of n and descriptor page size m.

slide-53
SLIDE 53

Introduction Self-collecting Mutators Implementation Experiments mpg123 MP3 converter

mpg123 - Memory Consumption

50 100 150 200 250 300 350 400 450 20 40 60 80 100 120 140 160 180 number of allocations

(1) (2) (3) (4) (5) (6) (7) (8) (9) tick tick tick tick tick

memory consumption in KB (lower is better) ptmalloc2 (1) SCM(1, 256B)(2) space-overhead(1, 256B)(3) SCM(10, 256B)(4) space-overhead(10, 256B)(5) SCM(1, 4KB)(6) space-overhead(1, 4KB)(7) SCM(10, 4KB)(8) space-overhead(10, 4KB)(9)

Memory overhead and consumption of the mpg123 benchmark. Again, SCM(n, m) stands for self-collecting mutators with a maximal expiration extension of n and descriptor page size m. We write space-overhead(n, m) to denote the memory

  • verhead of the SCM(n, m) configurations for storing descriptors and descriptor

counters.

slide-54
SLIDE 54

Introduction Self-collecting Mutators Implementation Experiments mpg123 MP3 converter

Thank You

check out:

eurosys2011.cs.uni-salzburg.at