On-The-Fly Garbage Collection: an Exercise in Cooperation
Total Page:16
File Type:pdf, Size:1020Kb
8. HoIn, B.K.P. Determining lightness from an image. Comptr. Graphics and Image Processing 3, 4(Dec. 1974), 277-299. 9. Huffman, D.A. Impossible objects as nonsense sentences. In Machine Intelligence 6, B. Meltzer and D. Michie, Eds., Edinburgh U. Press, Edinburgh, 1971, pp. 295-323. 10. Mackworth, A.K. Consistency in networks of relations. Artif. Intell. 8, 1(1977), 99-118. I1. Marr, D. Simple memory: A theory for archicortex. Philos. Trans. Operating R.S. Gaines Roy. Soc. B. 252 (1971), 23-81. Systems Editor 12. Marr, D., and Poggio, T. Cooperative computation of stereo disparity. A.I. Memo 364, A.I. Lab., M.I.T., Cambridge, Mass., 1976. On-the-Fly Garbage 13. Minsky, M., and Papert, S. Perceptrons. M.I.T. Press, Cambridge, Mass., 1968. Collection: An Exercise in 14. Montanari, U. Networks of constraints: Fundamental properties and applications to picture processing. Inform. Sci. 7, 2(April 1974), Cooperation 95-132. 15. Rosenfeld, A., Hummel, R., and Zucker, S.W. Scene labelling by relaxation operations. IEEE Trans. Systems, Man, and Cybernetics Edsger W. Dijkstra SMC-6, 6(June 1976), 420-433. Burroughs Corporation 16. Sussman, G.J., and McDermott, D.V. From PLANNER to CONNIVER--a genetic approach. Proc. AFIPS 1972 FJCC, Vol. 41, AFIPS Press, Montvale, N.J., pp. 1171-1179. Leslie Lamport 17. Sussman, G.J., and Stallman, R.M. Forward reasoning and SRI International dependency-directed backtracking in a system for computer-aided circuit analysis. A.I. Memo 380, A.I. Lab., M.I.T., Cambridge, Mass., 1976. A.J. Martin, C.S. Scholten, and 18. Tenenbaum, J.M., and Barrow, H.G. IGS: A paradigm for E.F.M. Steffens integrating image segmentation and interpretation. In Pattern Philips Research Laboratories Recognition and Artificial Intelligence, C. H. Chen, Ed., Academic Press, New York, 1976, pp. 472-507. 19. Ullman, J.R. Associating parts of patterns. Inform. and Control 9, 6(Dec. 1966), 583-601. As an example of cooperation between sequential 20. Ullman, J. R. Pattern Recognition Techniques. Crane Russak, New York, 1973. processes with very little mutual interference despite 21. Ullman, J.R. An algorithm for subgraph isomorphism. J.A CM frequent manipulations of a large shared data space, a 23, l(Jan. 1976), 3142. technique is developed which allows nearly all of the 22. Unger, S.H. GIT--a heuristic program for testing pairs of directed line graphs for isomorphism. Comm. ACM 7, l(Jan. 1964), activity needed for garbage detection and collection to 26-34. be performed by an additional processor operating con- 23. Waltz, D.L. Generating semantic descriptions from drawings of currently with the processor devoted to the computation scenes with shadows. AI-TR-271, A.I. Lab., M.I.T., Cambridge, Mass., 1972. proper. Exclusion and synchronization constraints have 24. Zucker, S.W. Relaxation labelling, local ambiguity, and low-level been kept as weak as could be achieved; the severe vision. In Pattern Recognition and Artificial Intelligence, C. H. Chen, complexities engendered by doing so are illustrated. Ed., Academic Press, New York, 1976, pp. 593-616. Key Words and Phrases: multiprocessing, t'me- grained interleaving, cooperation between sequential processes with minimized mutual exclusion, program cor- rectness for multiprogramming tasks, garbage collection CR Categories: 4.32, 4.34, 4.35, 4.39, 5.24 1. Introduction In any large-scale computer installation today, a considerable amount of time of the (general purpose) Permission to copy without fee all or part of this material is granted provided that the copies are not made or distributed for direct commercial advantage, the ACM copyright notice and the title of the publication and it s date appear, and notice is given that copying is by permission of the Association for Computing Machinery. To copy otherwise, or to republish, requires a fee and/or specific permission. Authors' addresses: E.W. Dijkstra, Burroughs, Plataanstraat 5, 5671 A1 Nuenen, The Netherlands; L. Lamport, SRI International, 333 Ravenswood Ave., Menlo Park, CA 94025; A.J. Martin, C.S. Scholten, and E.F.M. Steffens, Philips Research Laboratories, 5656 AA Eind- hoven, The Netherlands. For reference purposes a glossary of names has been added as an Appendix. © 1978 ACM 0001-0782/78/1100-0966 $00.75 966 Communications November 1978 of Volume 21 the ACM Number 11 processor is spent on "operating the system." With the actions (2) and (4) a garbage node is "recycled," i.e. advent of multiprocessor installations, the question arises made reachable again. to what extent such "housekeeping activities" can be The representation of the graph is such that each carded out concurrently with the computation(s) proper. node can be identified independently of the structure of One of the problems that have to be dealt with is the graph, and that finding the left- or right-hand suc- organizing the cooperation of the concurrent processes cessor of a node can be regarded as a primitive operation, so as to keep exclusion and synchronization constraints whereas finding its predecessor nodes would imply a extremely weak, in spite of very frequent manipulations search through the complete collection of nodes. Because (by all processes involved) of a large shared data space. of this representation, finding garbage is a nontrivial The problem of garbage collection was selected as one task, which is delegated to a so-called "garbage collec- of the most challenging problems in this respect (and tor." The garbage collector maintains a so-called "free hopefully a very instructive one). Our exercise has not list," i.e. a collection of nodes that have been identified only been very instructive, but at times even humiliating, as garbage and are available to be added to the data as we have fallen into nearly every logical trap possible. structure. In our presentation we have tried to blend a condensed In classical Lisp implementations the computation design history--so as not to hide the heuristics too proper (i.e. the modifications of the data structure as much--with a rather detailed justification of our final described above) proceeds until the free list is exhausted solution. We have tried to keep exclusion and synchro- (or nearly so). Then the computation proper comes to a nization constraints between the processes as weak as grinding halt, after which garbage is collected: starting possible, and how to deal with the complexities engen- from the roots, all reachable nodes are marked; upon dered by doing so is the main topic of this paper. completion of this marking cycle all unmarked nodes It has hardly been our purpose to contribute specifi- can be concluded to be garbage, and are appended cally to the art of garbage collection, and consequently to the free list, after which the computation proper is no practical significance is claimed for our solution. For resumed. that reason we felt justified in tackling a specific form of The minor disadvantage of this arrangement is the the garbage collection problem as it presents itself in the delay of the computation proper; its major disadvantage traditional implementation environment of pure Lisp. is the unpredictability of these garbage collecting inter- We are aware of the fact that we have left out of ludes, which makes it hard to design such systems so as consideration several aspects of the garbage collection to meet real-time requirements as well. It was therefore problem that are important from other points of view tempting to investigate whether a second processor-- (see, for instance, [4]). called "the collector"--could collect garbage concur- In our abstract form of the problem, we consider a rently with the activity of the other processor--for the directed graph of varying structure but with a fixed purpose of this discussion called "the mutator"--which number of nodes, in which each node has at most two would be dedicated to the computation proper. In order outgoing edges. More precisely, each node may have a to investigate an exemplary problem, we have imposed left-hand outgoing edge and may have a right-hand upon our solution a number of constraints (compare outgoing edge, but either of them or both may be missing. [4]). In this graph a fixed set of nodes exists, called "the First, we wanted the synchronization and exclusion roots." A node is called "reachable" if it is reachable constraints between the mutator and the collector to be from at least one root via a directed path along the edges. as weak as possible. (The classical implementation pre- The subgraph consisting of all reachable nodes and their sents in this respect the other extreme: a garbage collect- interconnections is called "the data structure;" nonreach- ing interlude can in its entirety be regarded as a single able nodes, i.e. nodes that do not belong to the data critical section that excludes all mutator activity!) We structure, are called "garbage nodes." The data structure wanted in particular to avoid highly frequent mutual can be modified by actions of the following types: exclusion of "elaborate" activities, as this would defy our (1) Redirecting an outgoing edge of a reachable node aim of concurrent activity: our ultimate aim was some- towards an already reachable one. thing like no more interference than the mutual exclusion (2) Redirecting an outgoing edge of a reachable node of a single read and/or write of the same single variable. towards a not yet reachable one without outgoing edges. One synchronization measure is evidently unavoidable: (3) Adding--where an outgoing edge was missing-- when needing a new node from the free list, the mutator an edge pointing from a reachable node towards an may have to be delayed until the collector has appended already reachable one.