5
Short Communication Two-dimensional memory management using an avail list A.L. Perkins 1, * , L. Bell Stennis Space Centre, University of Southern Mississippi, Building 1007, Mississippi 39529, USA Received 27 November 1996; received in revised form 28 June 1999; accepted 3 August 1999 Abstract A large two-dimensional fortran array is used to simulate a two-dimensional memory. The two-dimensional memory management scheme is discussed in detail, and an optimal two-dimensional scheme is established. The scheme is designed to reduce the need to copy arrays when they grow beyond their original memory allocation. Such a need arises when adaptive mesh refinement, for example, is used on a large scientific grid calculation with many multi-dimensional arrays. The memory management scheme could be realized in hardware; however, it was originally developed as a technique to speed up numerical calculations. q 2000 Elsevier Science Ltd. All rights reserved. Keywords: Two-dimensional memory management; First-fit algorithm; Storage allocation 1. Introduction In fortran over a linear memory, we simulate a two- dimensional memory management scheme by reserving a very large two-dimensional array for our use and manage- ment as in Refs. [1,2]. Our simulated two-dimensional memory is managed with an available list as is the one- dimensional memory management scheme discussed in Ref. [3]. The idea is extensible to higher dimensions as well. Multi-dimensional memory introduces more combina- tion choices for memory management than in one dimen- sion, which may reduce the need to copy arrays when they grow beyond their original memory allocation. Such a need arises when adaptive mesh refinement, for example, is used on a large scientific grid calculation with many multi- dimensional arrays. Anderson and Mirin [4] point out that when the Cray-2 supercomputer was introduced, it had increased the avail- able amount of memory by a factor of 30, while only increasing the number of processors by a factor of 4. Since then, this trend has continued and more recently work- stations and personal computers have undergone a similar architectural redistribution of resources. The more recent IBM ASCI Blue Pacific machine, for example, increased both the number of processors and memory by two orders of magnitude. Memory usage is an important, often over- looked, component of computing. Dynamic memory management of multi-dimensional arrays on underlying linear memories has been examined in Ref. [5]. Two of the criteria they developed for a success- ful manager carry over to the problem of managing multi- dimensional memories directly: simplicity of element access and efficiency of overhead storage utilization. In one-dimensional physical memories, run time redi- mensioning of multi-dimensional arrays require more complex storage access functions than do static arrays. Such redimensioning occurs in applications such as adap- tive mesh refinement (cf. Ref. [6]), where extending very large arrays into physically contiguous space would signifi- cantly improve program efficiency. While many ingenious algorithms exist to improve computational efficiency for large computer problems (cf. Ref. [7]), here we explore the possible impact that the structure of the physical memory itself might have. Specifically, we present a general, multi-dimensional array memory management scheme. The algorithm has good storage overhead utilization, easily extends to avail- able contiguous memory, and works for arrays of dimension less than or equal to an a priori ceiling dimension. To illus- trate how it would work, and without loss of generality, we simulate two spatial dimensions over a physically linear memory. We begin in Section 2 with a discussion of a two-dimen- sional heuristic allocation strategy. Section 3 briefly reviews the one-dimensional analysis presented in Ref. [3]. This is used as a comparison for the two-dimensional analysis presented in Section 4. There the heuristic described in Section 2 is shown to be an optimal two-dimensional Advances in Engineering Software 31 (2000) 217–221 0965-9978/00/$ - see front matter q 2000 Elsevier Science Ltd. All rights reserved. PII: S0965-9978(99)00042-3 www.elsevier.com/locate/advengsoft * Corresponding author. Tel.: 11-228-688-3113; fax: 11-228-466-5836. E-mail address: [email protected] (A.L. Perkins). 1 Also at Naval Research Laboratory.

Two-dimensional memory management using an avail list

Embed Size (px)

Citation preview

Page 1: Two-dimensional memory management using an avail list

Short Communication

Two-dimensional memory management using an avail list

A.L. Perkins1,* , L. Bell

Stennis Space Centre, University of Southern Mississippi, Building 1007, Mississippi 39529, USA

Received 27 November 1996; received in revised form 28 June 1999; accepted 3 August 1999

Abstract

A large two-dimensionalfortran array is used to simulate a two-dimensional memory. The two-dimensional memory managementscheme is discussed in detail, and an optimal two-dimensional scheme is established. The scheme is designed to reduce the need to copyarrays when they grow beyond their original memory allocation. Such a need arises when adaptive mesh refinement, for example, is used on alarge scientific grid calculation with many multi-dimensional arrays. The memory management scheme could be realized in hardware;however, it was originally developed as a technique to speed up numerical calculations.q 2000 Elsevier Science Ltd. All rights reserved.

Keywords: Two-dimensional memory management; First-fit algorithm; Storage allocation

1. Introduction

In fortran over a linear memory, we simulate a two-dimensional memory management scheme by reserving avery large two-dimensional array for our use and manage-ment as in Refs. [1,2]. Our simulated two-dimensionalmemory is managed with an available list as is the one-dimensional memory management scheme discussed inRef. [3]. The idea is extensible to higher dimensions aswell. Multi-dimensional memory introduces more combina-tion choices for memory management than in one dimen-sion, which may reduce the need to copy arrays when theygrow beyond their original memory allocation. Such a needarises when adaptive mesh refinement, for example, is usedon a large scientific grid calculation with many multi-dimensional arrays.

Anderson and Mirin [4] point out that when the Cray-2supercomputer was introduced, it had increased the avail-able amount of memory by a factor of 30, while onlyincreasing the number of processors by a factor of 4.Since then, this trend has continued and more recently work-stations and personal computers have undergone a similararchitectural redistribution of resources. The more recentIBM ASCI Blue Pacific machine, for example, increasedboth the number of processors and memory by two ordersof magnitude. Memory usage is an important, often over-looked, component of computing.

Dynamic memory management of multi-dimensionalarrays on underlying linear memories has been examinedin Ref. [5]. Two of the criteria they developed for a success-ful manager carry over to the problem of managing multi-dimensional memories directly: simplicity of elementaccess and efficiency of overhead storage utilization.

In one-dimensional physical memories, run time redi-mensioning of multi-dimensional arrays require morecomplex storage access functions than do static arrays.Such redimensioning occurs in applications such as adap-tive mesh refinement (cf. Ref. [6]), where extending verylarge arrays into physically contiguous space would signifi-cantly improve program efficiency. While many ingeniousalgorithms exist to improve computational efficiency forlarge computer problems (cf. Ref. [7]), here we explorethe possible impact that the structure of the physicalmemory itself might have.

Specifically, we present a general, multi-dimensionalarray memory management scheme. The algorithm hasgood storage overhead utilization, easily extends to avail-able contiguous memory, and works for arrays of dimensionless than or equal to an a priori ceiling dimension. To illus-trate how it would work, and without loss of generality, wesimulate two spatial dimensions over a physically linearmemory.

We begin in Section 2 with a discussion of a two-dimen-sional heuristic allocation strategy. Section 3 briefly reviewsthe one-dimensional analysis presented in Ref. [3]. This isused as a comparison for the two-dimensional analysispresented in Section 4. There the heuristic described inSection 2 is shown to be an optimal two-dimensional

Advances in Engineering Software 31 (2000) 217–221

0965-9978/00/$ - see front matterq 2000 Elsevier Science Ltd. All rights reserved.PII: S0965-9978(99)00042-3

www.elsevier.com/locate/advengsoft

* Corresponding author. Tel.:11-228-688-3113; fax:11-228-466-5836.E-mail address:[email protected] (A.L. Perkins).1 Also at Naval Research Laboratory.

Page 2: Two-dimensional memory management using an avail list

management scheme. Section 5 summarizes the manage-ment scheme and briefly discusses the new issue of packa-ging two-dimensional memory which is not present with theone-dimensional problem. We summarize in Section 6.

2. Two-dimensional heuristic allocation

In Ref. [3], linear memory space is allocated with around-robin search through an available or “avail” list. LetU stand for used and A stand for available space. Our algo-rithm allocates needed two-dimensional space from theupper left corner of the first two-dimensional availablespace encountered when searching through a similar availlist (a first-fit strategy). This creates up to two new availablerectangular spaces, theright and thebottomavailable arrayentries, while consuming one available space. Fig. 1 showstwo recursive applications of this allocation strategy whenthe right available entry is entered into the avail list beforethe bottom one. Notice that each such allocation increasesthe number of available rectangular memory spaces by one(unless a perfect fit is found in any dimension).

In more than one dimension there is sometimes more thanone allocation choice for a given block of availablememory, and a multi-dimensional management schemeneeds to know how to make a “good” decision. For example,is it better to allocate space from the center of the availablespace, or the side, or the corner? It has been our experiencethat, since combinations for returning space also proliferatein multi-dimensional memory management, the allocationstrategy that simplified returning space to the avail list wasto be preferred. We found that our largest time cost forsimulated multi-dimensional memory arose when spacewas returned. The three-part division of the allocation

space into one used and two new available entries (Fig. 1)that we use was chosen to correspond to the way we returnavailable space.

We now briefly discuss returning space. For each of thefour sides of a two-dimensional array, there are nine possi-ble neighbor relationships (omitting symmetries). Considerjust one side or face of the rectangular memory to bereturned. For now, we can pretend that it is one-dimen-sional. Fig. 2 shows the nine possibilities that can occuralong any of these sides, related choices side by side (i.e.(a)’s, (b) with (c), (d) with (e), and (f) with (g)). These ninechoices, which we call tilings, are derived by dividing a sideinto three sections: a section that is equal to the size of thememory to be returned to the available list (the centerportion), and the space surrounding this portion—the“left” and “right” sections. One tile pattern is associatedwith each side of a used space, U. The space, U, beingreturned is adjacent to the center section and can recombinewith any sides that are configured as a (c), (e), (g) andpossibly (a1), (a2) and (a3) (i.e. those side with centersection available).

We decide which recombination to use based on a prior-itized list of tiling combinations. For example, an adjacentside (corner) recombination (Fig. 3) corresponds to ourcorner allocation policy diagramed in Fig. 1. Such a corneroccurs when tilings (c) or (e) (and possibly (a2)) are contig-uous and aligned. Corner allocations promote evenly rectan-gular available spaces, returning space that can be morereadily used by applications that are evenly distributed ineach spatial dimension. We may also combine oppositesides. These can involve the return of more tilings of type(c), (e), (g) (and possibly any of the (a)’s), with each other.Of course, we can combine with any one side, matching a(c), (e), (g) (or possibly (a)) configuration.

3. One-dimensional analysis

This section relates our work to existing memorymanagement analysis. Knuth [3] examined dynamic storage

A.L. Perkins, L. Bell / Advances in Engineering Software 31 (2000) 217–221218

Fig. 1. Two consecutive corner allocations.

Fig. 2. One-dimensional recombination tilings. The space to be returned isdirectly below the center section of slide shown (the top side of an availspace is shown here).

Fig. 3. Corner memory recombination when returning the upper (used)corner block.

Page 3: Two-dimensional memory management using an avail list

allocation and reviewed the performance of different availspace strategies.

Following his work, but using the above tile options, thethree possible tilings for a linear memory are (b), (d) and (f).Define the operatoru·u as the number of tiles that occur ineach tiling pattern, ignoring boundary tilings. Then

N � ubu 1 udu 1 uf u

is the total number of used spaces. Knuth noticed thatM �12 �2uf u 1 udu� is the associated number of available blocks.

When a used space is returned to a one-dimensional availlist, it will decrementN by one. Returning a (b), (d) or (f) tilealtersM as follows:

• �f � : M ! M 2 1;• �d� : M ! M;

• �b� : M ! M 1 1;

and the percentage of (f), (d) and (b) tiles is altered concur-rently. Such an analysis predicts an equilibrium state for therespective memory allocation/deallocation strategy in termsof M andN.

4. Two-dimensional analysis

In two dimensions, combination options proliferate.There are eight possible neighbors around each used spaceU (Table 1). And each of these neighbors is either a U, an A,or a U : A, as shown in Fig. 2. The straightforward enumera-tion of all possible combinations needed to analyze thebehavior of a two-dimensional memory is more extensivethan for the linear memory in Section 3, but differs funda-mentally in only one major respect: the shape of each availspace created when recombining is now important. Forexample, it may now be better to return evenly rectangularspaces than to save an extra entry in the avail list.

If the straightforward choice is applied where we let themost restrictive (highest number of side combinations) takeprecedence when returning U (as did Knuth implicitly).There are two points to resolve: mixed side neighbors (the

(a)’s in Fig. 2), and which two-face combination to selectfirst, corner or opposite. Prioritizing based on the highestnumber of available spaces to recombine combines both thetwo-face corner and the two-face opposite combinationwhen they occur together, eliminating that point. In ouranalysis we treat mixed side neighbors�U : A� as usedspaces, eliminating that point also. We postpone recombi-nations of mixed side neighbors unless we need to repack-age the memory to find available contiguous space. In thissense, our straightforward precedence rules are optimal:given that we wish to recombine with the maximum numberof agreeable neighbors, no other precedence rules are avail-able. Further, the maximal side choice avoids vanishingdimensions more often, and in our work returned the mostbalanced available spaces on average.

We mention here that we could compute which returnwould produce the most rectangular space each time,however this would increase the overhead of our allocationstrategy, so it was not implemented.

The precedence rules define the deallocation or recombi-nation strategy, which is conceptually independent of theallocation strategy. However, to optimize applications thatwish to extend large arrays into contiguous memory, wechoose to view returning space as a mirror image of alloca-tion, equivalent to extending an array.

We now analyze the performance of such a two-dimen-sional scheme. Letn refer to the epoch immediately beforean allocation is made andn 1 1 refer to the epoch immedi-ately after the allocation. Recall the one-dimensionalchanges to a tiling when returning a used space, U, sittingwithin two adjacent used spaces. The change will alter oneof the three five-wide tiling layouts in Table 2. There thetable is divided into two parts by a triple vertical line. Theleft-hand side is the possible five-wide tiling layouts and theright-hand side is the three types of tilings that could possi-bly be altered by a recombination of the center used space.

The tiling changes are given in Table 3. There the figurehas been expanded to include three parts. The secondsection contains the new tilings. The third section showsthe changes that occur to the total number of tilings ofeach type. Notice that all choices maintain the same overallnumber of tilings when recombinations are not possible(when recombinations are possible, the number of tilingsdecreases).

Analogous to the one-dimensional analysis summarizedin Section 3, we could compute the number of used spacesgiven by

N � ubu 1 udu 1 uf u

and the number of available spaces with

M � ucu 1 ueu 1 ugu

Each allocation increasesN by one. Each deallocationdecreasesM by zero or more.

Since there is sometimes more than one recombination ofspaces possible in multiple dimensions, the number of avail

A.L. Perkins, L. Bell / Advances in Engineering Software 31 (2000) 217–221 219

Table 1Eight neighbor choices

– – –

– U –

– – –

Table 2Five-wide one-dimensional tiling layout options with tile types

A U U U A d, b, d

U U U U A b, b, d

U U U U U b, b, b

Page 4: Two-dimensional memory management using an avail list

spaces created is no longer unique: the number of availablespaces is a function of the packaging. In this case, thenumbersM andN are no longer useful for analysis.

4.1. Probability of tiling occurrence

We analyze the two-dimensional case, instead, by firstenumerating all possible surrounding states. We thencompute the probability with which each configurationoccurs. Table 4–14, even numbered, show representativepossible re-combination configurations. Table 5–15, oddnumbered, show the effect when each of these is returned.We have omitted many of the possible combinations forbrevity.

Assume that each neighbor has an equal probability ofbeing available or used, so that each state has an equal like-lihood of occurrence. Let the total number of states beT.The probability of a four-face recombination (Table 14),which we call 4f, is P4f � 1=T: The probability of a threecorner return (3f) being available isP3f � 4=T: The prob-ability of returning a two corner combination isP2c � 16=T;for an opposite-face combination it isP2f � 1302=T: Theprobability of a one-face combination isP1f � 390=T:Notice that these are true regardless of the tilings chosen.

The number of faces available for combination, our new“counter”, is given by

M � u1f u 1 u2fcu 1 u2fo

u 1 u3f u 1 u4f u

A.L. Perkins, L. Bell / Advances in Engineering Software 31 (2000) 217–221220

Table 3Side analysis

A U A U A f, g, f d 2 2; b 2 1; g 1 1; f 1 2

U U A U A d, g, f b 2 2; g 1 1; f 1 1

U U A U U d, g, d b2 3; d 1 2; g 1 1

Table 4No available spaces

U U U

U U U

U U U

Table 5One available space returned, no recombinations possible

U U U

U A U

U U U

Table 6One corner available space (1f)

U U U

U U U

U U A

Table 7One available space returned, no recombinations possible

U U U

U A U

U U A

Table 8One adjacent face available space (1f)

U U U

U U A

U U U

Table 9One available space returned, one recombination possible

U U U

U A A

U U U

Table 10All but one corner available space (3f)

A A U

A U A

A A A

Table 11One available space returned, two recombinations possible

A A U

A A A

A A A

Table 12All but one adjacent face available (3f)

A A A

A U A

A U A

Page 5: Two-dimensional memory management using an avail list

For a linear memory, had we counted available faces insteadof available spaces,

u4f u � u3f u � u2fcu � u2fo

u ; 0

Then our equation forM reduces to Knuth’s one-dimensionalresult �d 1 2f � where the 1/2 factor is lost because we arenow counting available faces rather than available spaces.

5. Packaging

From just an avail list, it is costly to recover hidden avail-ability of contiguous memory. The memory space might bepackaged poorly for the current needs and need to berepacked to be usable (cf. Ref. [1]). Hence, a search throughthe available list might not demonstrate the desired andavailable contiguous shape even if it existed. So when theavail list indicates that the desired available memory doesnot exist, we construct a connectivity graph to see if suffi-cient contiguous space is available. As this step requiresoverhead, it is done only when no other options are avail-able. At this step when re-copying would require an abovethreshold limit of computer resources, we repackage theavail spaces locally to satisfy the request.

To package available memory we keep the used spaceordered in both thex and y direction. This allows simplealgorithms, such as Manhattan Geometry [8], to be used toquickly organize the used spaces, and repackage locally.

6. Summary

Since the extension to two-dimensional memory intro-duced many more combination choices for memorymanagement than in one dimension, returning space infully two dimensions has many options for each configura-tion. Higher-dimensional memory has even more options,but the principles are the same. This is due, in part, to theflexible (i.e. non-unique) nature of selecting available spacesizes.

With our implementation of an avail list with first fitround-robin allocation, we demonstrated the feasibility ofmulti-dimensional allocation strategies. Further, it is easilyimplemented, and can significantly improve the perfor-mance of some applications by saving frequent data copies.The two-dimensional scheme reduces to Knuth’s one-dimensional result. The implementation required only asimple allocation and deallocation strategy.

Acknowledgements

This work was performed under the auspices of the NavalResearch Laboratory and the Office of Naval Research,Navy Ocean Modeling Program, and the University ofSouthern Mississippi Scientific Computing program. Theauthors wish to thank Christopher Perkins for dedicatinghis time, as well.

References

[1] Perkins AL. Parallel heterogeneous mesh refinement for multidimen-sional convection–diffusion equations using an Euler–Lagrangemethod. PhD Thesis. UCRL-53950, University of California atDavis, 1989.

[2] Perkins AL. A mixed directed–undirected data structure for a parallelimplementation of a domain decomposition algorithm. BIT1992;32:598–608.

[3] Knuth DE. The art of computer programming, 2. Reading, MA: Addi-son-Wesley, 1975 ISBN 0 201 03809 9.

[4] Anderson DV, Mirin AA. Strategies for multitasking, NationalMagnetic Fusion Energy Computer Center buffer 1986;10:9–11.

[5] Otoo EJ, Merrett TH. A storage scheme for extendible arrays. Comput-ing 1983;31:1–9.

[6] Berger MJ. Adaptive mesh refinement for hyperbolic partial differen-tial equations. PhD Dissertation. Stanford University, 1982.

[7] Derby WS, Engle JT, Martin JT.LRLTRANLanguage used with theCHATand CIVIC Compilers, LCSD-302 Rev.1 (a Lawrence Liver-more National Laboratory Publication), June 1982.

[8] Sedgewick R. Algorithms in C, Reading, MA: Addison-Wesley,1990.

A.L. Perkins, L. Bell / Advances in Engineering Software 31 (2000) 217–221 221

Table 13One available space returned, two recombinations possible

A A A

A A A

A U A

Table 14All faces available (4f)

A A A

A U A

A A A

Table 15One available space returned, any recombination possible

A A A

A A A

A A A