increasing memory usage in real-time gc tobias ritzau and peter fritzson department of computer and...

19
Increasing Memory Increasing Memory Usage in Usage in Real-Time GC Real-Time GC Tobias Ritzau and Peter Fritzson Tobias Ritzau and Peter Fritzson Department of Computer and Information Department of Computer and Information Science Science Linköpings universitet Linköpings universitet [email protected] [email protected] http://www.ida.liu.se/~tobri http://www.ida.liu.se/~tobri

Upload: harold-nichols

Post on 18-Dec-2015

214 views

Category:

Documents


0 download

TRANSCRIPT

Increasing Memory Usage inIncreasing Memory Usage inReal-Time GCReal-Time GCTobias Ritzau and Peter FritzsonTobias Ritzau and Peter Fritzson

Department of Computer and Information ScienceDepartment of Computer and Information ScienceLinköpings universitetLinköpings universitet

[email protected]@ida.liu.sehttp://www.ida.liu.se/~tobrihttp://www.ida.liu.se/~tobri

227-9 October, 20027-9 October, 2002 Increasing Memory Usage in Real-Time GCIncreasing Memory Usage in Real-Time GC

The ProblemThe Problem

Published “real” real-time garbage Published “real” real-time garbage collectors consume too much memorycollectors consume too much memory

A large portion of the overhead is caused A large portion of the overhead is caused by type information, internal fragmentation, by type information, internal fragmentation, and GC house keepingand GC house keeping

However, most GC techniques also However, most GC techniques also require a buffer to hold dead objectsrequire a buffer to hold dead objects

337-9 October, 20027-9 October, 2002 Increasing Memory Usage in Real-Time GCIncreasing Memory Usage in Real-Time GC

Mark-SweepMark-SweepRoot

667-9 October, 20027-9 October, 2002 Increasing Memory Usage in Real-Time GCIncreasing Memory Usage in Real-Time GC

RT-CopyingRT-Copying

777-9 October, 20027-9 October, 2002 Increasing Memory Usage in Real-Time GCIncreasing Memory Usage in Real-Time GC

RT-Mark-Sweep (JamaicaVM)RT-Mark-Sweep (JamaicaVM)

887-9 October, 20027-9 October, 2002 Increasing Memory Usage in Real-Time GCIncreasing Memory Usage in Real-Time GC

Available MemoryAvailable Memory

The amount of available memory using The amount of available memory using real-time garbage collection and a heap of real-time garbage collection and a heap of 12 – 36 byte objects (equally distributed) is12 – 36 byte objects (equally distributed) is Copying GC: Copying GC: 25%25% Mark-Sweep (JamaicaVM):Mark-Sweep (JamaicaVM): 31%31% Reference Counting:Reference Counting: 47%47%

997-9 October, 20027-9 October, 2002 Increasing Memory Usage in Real-Time GCIncreasing Memory Usage in Real-Time GC

Reference CountingReference Counting

1

1

1

2

1

21

10

0

Root

1

2

0

01

10107-9 October, 20027-9 October, 2002 Increasing Memory Usage in Real-Time GCIncreasing Memory Usage in Real-Time GC

Reference CountingReference Counting

Disadvantages to overcomeDisadvantages to overcome Recursive freeingRecursive freeing External fragmentationExternal fragmentation Reclaiming dead cyclic data structuresReclaiming dead cyclic data structures Execution speedExecution speed

11117-9 October, 20027-9 October, 2002 Increasing Memory Usage in Real-Time GCIncreasing Memory Usage in Real-Time GC

Recursive FreeingRecursive Freeing

The problem was solved for equally sized The problem was solved for equally sized objects by Weizenbaum (1963)objects by Weizenbaum (1963)

Decrementing child references is Decrementing child references is postponed until the memory is reusedpostponed until the memory is reused

Still, all memory is available when it Still, all memory is available when it becomes unreachablebecomes unreachable

However, objects are not always of the However, objects are not always of the same size…same size…

12127-9 October, 20027-9 October, 2002 Increasing Memory Usage in Real-Time GCIncreasing Memory Usage in Real-Time GC

External FragmentationExternal Fragmentation

As in most file systems, the heap can be As in most file systems, the heap can be divided into equally sized blocksdivided into equally sized blocksSmall objects are linked using a list, while Small objects are linked using a list, while larger objects use a tree structurelarger objects use a tree structureMinor performance penalty for small Minor performance penalty for small objectsobjectsWeizenbaum’s technique to eliminate Weizenbaum’s technique to eliminate recursive freeing can be used on the recursive freeing can be used on the blocksblocks

13137-9 October, 20027-9 October, 2002 Increasing Memory Usage in Real-Time GCIncreasing Memory Usage in Real-Time GC

Dead Cyclic Data StructuresDead Cyclic Data Structures

Manual techniques cover most casesManual techniques cover most cases Breaking cyclesBreaking cycles Weak referencesWeak references Balloon typesBalloon types

Automatic techniques are not real-timeAutomatic techniques are not real-time

A backup real-time mark-sweep GC can A backup real-time mark-sweep GC can be used but that increases memory be used but that increases memory overheadoverhead

14147-9 October, 20027-9 October, 2002 Increasing Memory Usage in Real-Time GCIncreasing Memory Usage in Real-Time GC

Execution TimeExecution Time

Peep hole optimizationPeep hole optimization

Stack allocationStack allocation

Object owning (Data flow analysis)Object owning (Data flow analysis)

15157-9 October, 20027-9 October, 2002 Increasing Memory Usage in Real-Time GCIncreasing Memory Usage in Real-Time GC

RT-Reference CountingRT-Reference Counting

All operations are predictable in memory All operations are predictable in memory usage and execution timeusage and execution time

Memory usage is increased by more than Memory usage is increased by more than 50% for objects larger than 17 bytes50% for objects larger than 17 bytes

Dead cyclic data structures can be Dead cyclic data structures can be reclaimed (to the cost of memory reclaimed (to the cost of memory overhead)overhead)

16167-9 October, 20027-9 October, 2002 Increasing Memory Usage in Real-Time GCIncreasing Memory Usage in Real-Time GC

Impact of Block SizeImpact of Block Size

0%

20%

40%

60%

80%

100%

0 16 32 48 64 80 96 112 128

Average object size (bytes)

Mem

ory

ove

rhea

d

16 byte blocks

32 byte blocks

64 byte blocks

19197-9 October, 20027-9 October, 2002 Increasing Memory Usage in Real-Time GCIncreasing Memory Usage in Real-Time GC

ImplementationsImplementations

Real-Time Reference Counting has been Real-Time Reference Counting has been implemented:implemented: As CPP macrosAs CPP macros In the JOSES Java compilerIn the JOSES Java compiler In the Jamaica VMIn the Jamaica VM

However more optimizations are requiredHowever more optimizations are required

No backup GC has been implementedNo backup GC has been implemented

20207-9 October, 20027-9 October, 2002 Increasing Memory Usage in Real-Time GCIncreasing Memory Usage in Real-Time GC

BenchmarksBenchmarks

-5051015202530354045

b bs r rb rbs t tb tbs tr trb trbs

%

b = dividing objects into blocksbs = spreading the blocksr = using reference countingt = running thousand simulations (= more blocks in use)

21217-9 October, 20027-9 October, 2002 Increasing Memory Usage in Real-Time GCIncreasing Memory Usage in Real-Time GC

Future WorkFuture Work

Full implementationFull implementation

RT-Mark compactRT-Mark compact

Memory Usage AnalysisMemory Usage Analysis Should critical systems use GC?Should critical systems use GC? Can you not explicitly deallocate all garbage if Can you not explicitly deallocate all garbage if

you can give an upper bound of memory you can give an upper bound of memory usage?usage?

22227-9 October, 20027-9 October, 2002 Increasing Memory Usage in Real-Time GCIncreasing Memory Usage in Real-Time GC

ConclusionConclusion

RT-Reference Counting drastically RT-Reference Counting drastically decrease the memory overhead of real-decrease the memory overhead of real-time systems with a GCtime systems with a GC

The block size have a minor impact on the The block size have a minor impact on the memory overheadmemory overhead

Increasing Memory Increasing Memory Usage in Real-Time GCUsage in Real-Time GC

Tobias Ritzau and Peter FritzsonTobias Ritzau and Peter Fritzson

Department of Computer and Information ScienceDepartment of Computer and Information ScienceLinköpings universitetLinköpings universitet

[email protected]@ida.liu.sehttp://www.ida.liu.se/~tobrihttp://www.ida.liu.se/~tobri