2011 Talk

mangledcobwebΛογισμικό & κατασκευή λογ/κού

14 Δεκ 2013 (πριν από 3 χρόνια και 8 μήνες)

100 εμφανίσεις

M
ARK
-
S
WEEP

G
ARBAGE

C
OLLECTION

An Efficient Machine
-
Independent Procedure for Garbage
Collection in Various List Structures
,
Schorr

and Waite

CACM

August 1967, pp 501
-
506

Curtis Dunham

CS 395T Memory Management, Spring 2011

S
OME

INTERESTING

NOTES

(1)


Technique
not

called “Mark
-
Sweep” in this work


SCHEME
-
79 paper (Holloway, Steele,
Sussman
, and
Bell) the first to use this label


The verbs “trace” and “mark” are used however

S
OME

INTERESTING

NOTES

(2)


Credit for the idea given to John McCarthy

(Lisp, 1960)


Section 4c of his
Recursive Functions of Symbolic
Expressions and Their Computation by Machine,
Part I
describes the same process of using the sign
bit to mark memory cells, then scanning the heap

S
OME

INTERESTING

NOTES

(3)


Algorithm independently discovered by

L Peter Deutsch

H
ISTORICAL

B
ACKGROUND


Words in memory called “registers”


IBM 7094


2
15

36
-
bit words; 144 KB


0.5 MHz, or more charitably, 500 KHz


M
EMORY

M
ANAGEMENT
,
IN

THEIR

WORDS

Three options for reclaiming memory:

1.
Programmer does it manually

2.
Reference Counting

3.
“Garbage collection”, like McCarthy suggested

S
O

W
HAT

S

T
HE

B
IG

D
EAL
, A
NYWAY
?


McCarthy pretty much solved this, right?


Three problems, our authors claim:

1.
Algorithms for “tracing the lists” (today, traversing
the directed graph) at that time were expensive in
either time or space

2.
Signed numbers, or,

Hey, I was using that sign bit

3.
Heap objects occupying multiple words



L
ARGE

(M
ULTIPLE

W
ORD
) H
EAP

O
BJECTS


3 bits of the 36
-
bit words in a 7094 are for a
prefix
field


Use one of those bits to indicate what is
actually stored in that word

1.
the number of words that make up the heap
object, or

2.
the heap object itself

data

data

Another word

3


A word

S
IGNED

N
UMBERS


Use a large heap object,

then the “interior” words have usable sign bits

T
HE

A
LGORITHM

-

C
ONSTRAINTS


Must run in fixed space


No queue for breadth
-
first


No stack growth for recursive techniques, e.g. depth
-
first


Must trace efficiently


Bounded visits per object


Must handle circular lists




3 words

2 visits

That, too.

T
HE

A
LGORITHM



T
HE

T
RICK


Mutator

and collector
do not

run concurrently


Heap can be arbitrarily modified, so long as it is
correct when the
mutator

resumes


In a depth
-
first recursive scheme, the stack
provides “breadcrumbs” that allow us to find
our way back


Reverse pointers as they are traversed


Easy to do, easy to undo, provides “breadcrumbs”
for free

(in terms of space)


V
ISUALIZATION

Mark (sign bit)

Depth (prefix bit)

Head (car)

Tail (
cdr
)

Trace through (follow) Tail elements:

1.
Reverse Pointers

2.
Set Mark Bits

Trace through (follow) Tail elements (again),

Only this time, traversal is reversed.

1.
Reverse Pointers (again)

2.
Check Head fields for pointers.

If any are found, recursively apply this

procedure.

F
INALLY



This technique will mark everything on the heap
that is reachable.


A sweep of the entire heap is necessary to find
all the unmarked words, which are returned to
the free list.



This algorithm solves “one
-
way list” tracing.
With modification, it can trace others

(see section 7 of paper)

E
XPERIMENTAL

R
ESULTS


Testbed
: pathological 5
-
list, 20K
-
element
depth
-
12 “mess”


1.85s for this work


2.75s for Wilkes


0.448s for breadth
-
first with 48 element queue


Authors’ opinion


Space is available: use the breadth
-
first approach


Otherwise: this approach takes essentially no
space; use it instead


Cannot handle circular lists

H
IGHER

T
HINKING
, P
LEASE


The authors mention a concern for
portability


The final sweep through the heap is machine
-
dependent, but with just 6 special functions,

the tracer/marking algorithm can be written in
the higher level language (Wisp)


Analogous to
MMTk’s

Java GC in Java


R
EFERENCES
/R
ESOURCES
/A
CKNOWLEDGEMENTS

(other than this paper, cited on title slide)


http://en.wikipedia.org/wiki/IBM_7090


http://www
-
03.ibm.com/ibm/history/exhibits/mainframe/mainframe_PP7094.html


Gries
, David.
The
Schorr
-
Waite graph marking algorithm.
1979.
http://dx.doi.org/10.1007/BF00289068


McCarthy, John.
Recursive functions of symbolic expressions and their computation by
machine, Part I
. CACM April 1960
http://dx.doi.org/10.1145/367177.367199


Holloway, Jack; Steel, Guy Lewis, Jr.;
Sussman
, Gerald Jay; Bell, Alan.
The SCHEME
-
79 Chip.
1980.
http://hdl.handle.net/1721.1/6334


Previous slides by
Sowmiya

Chocka

Narayanan


D
ISCUSSION


Experimental methodology


Performance of pointer reversals


Performance


Human
-
noticable

delay in stop
-
the
-
world design


Motivation for
incrementality
, not waiting for heap to fill up,
etc.?


Significance of “no
-
space” design today