Returned electronic memory retrieval

Abstract: In an electronic data processing apparatus blocks of returned memory 3 are linked by address pointers starting with a pointer in a table 1. Each pointer in the table 1 points to memory of within a predetermined size range varying by integral powers of 2. The memory blocks pointed to by each table pointer are sorted in order of size (alternately by frequency of use). Searching for memory of size needed is very efficient as it is limited to memory blocks within a size range. Additionally, returned memory blocks (7) of the same size as a block 3 are not in the sort list, but are pointed to by the block 3 of the same size and are used when that size block is selected.

Description: This invention relates to electronic data processing with addressable memory which is freed for use during operation, and more specifically apparatus controlled by such electronic data processor in which such returned memory is located for reuse. During normal use of electronic data processing equipment electronic memory which has been used is freed for reuse. Such blocks of memory typically are of a wide variation of sizes and in a wide variation of locations. Although patterns of sizes for such returned memory and their locations can be predicted broadly for individual applications, this information is far from being precise enough for direct use to once again use the returned memory. Prior to this invention such returned memory has been sorted by some category, such as by size or by order of addresses, and located for reuse by searching through such a sort. U.S. Patent No. 5,109,336 to Guenther et al discloses such retrieval of memory. In this patent blocks of memory of different, predetermined sizes are disclosed as allocated by the program being executed. Returned memory of such sizes are added to these allocations. Where the allocated memory is not used, all other returned memory is searched in the order in which it has been sorted. This invention does not employ such allocated blocks of memory and limits the search through sorted returned memory in a manner to be described below. This invention employs address pointers to achieve improved retrieval of returned memory. The use of such pointers per se is widely conventional. U.S. Patent No. 4,807,120 to Courts discloses the use of pointers in a system not particularly similar to this invention except that it is for memory management with respect to returned memory. IBM Technical Disclosure Bulletin vol. 18, no. 8, pages 2582-2583, January 1976, "Space Reclamation in Virtual Storage Systems", E.T. Boyle, K.D. Ryder & I.H. Schneider, discloses a method for reclaiming fragmented virtual storage to minimize wasted space. In this method, any unused memory areas are recorded in one of N size-ordered lists with each list containing memory in a given size range. The appropriate list is scanned to find the first free memory area of adequate size. The preferred embodiment of this invention categorizes returned memory according to sizes which vary by a single integer of powers of 2. The "gmalloc" code of a public UNIX (trademark) source code listing allocates memory to block differing by such powers of 2. However, these allocations are not related to returned memory in any manner similar to this invention since the allocations do not involve memory returned after the allocations. Contemporary computer design employs a working memory space generally referred to as the "heap" or "free memory." The memory manager function of the data processor is given control of this typically large memory space, and it responds to program requests for memory blocks by identifying or creating an appropriate block and giving control of it to the requester in a process known as allocation. When the active program is done with a given memory block, a process known as "freeing," it relinquishes control of it to the memory manager. The memory manager will then store the block in some form from which it can be retrieved for other use in the same or different program at a later time. Traditionally, memory managers must sacrifice memory usage efficiency for performance. Since the performance cost of sorting memory blocks in those systems is too great, comprehensive searches or intelligent allocation strategies are not practical. Subsequently, their searches will often encounter numerous blocks that are too small to be useful, forcing the program designer to either carve the desired size off the first free block encountered that is large enough to fill the request or use a limited number of allowed block sizes and waste the difference between the size needed and the size provided. Although this approach is generally successful in systems with a low to moderate memory utilization ratio, systems requiring higher memory utilization cannot afford the waste. In these environments, such systems can expend significant search effort and may exhibit undesirable fragmentation patterns leading to premature "memory full" conditions. When fragmentation becomes severe, it is not uncommon for "out of memory" failures to occur even though 10 times the requested memory or more is available. This invention requires more initial computational overhead than simple, unordered systems, but quickly makes up the deficit in searches involving more than a very few returned memory blocks. Further, its unique approach is designed to allow elaborate allocation strategies and other memory enhancements that were otherwise performance prohibitive in memory systems suffering from "fragmentation." The invention provides an apparatus in accordance with claim 1. In accordance with at least the preferred embodiments of the invention, a call for memory is made by addressing a single word assigned to memory of the size range encompassing the memory required. That single word contains an address pointer to a sorted list of memory blocks of sizes within the size range assigned to that address. Preferably the list is sorted by size from largest to smallest and the single address pointer is the address of the largest memory block of that sorted list. Each entry in the sorted list contains a pointer to the next entry in the sorted list, as well as containing data defining the memory size and other such routine data describing that block of data. The pointer assigned to memory size is employed as the address to examine the first memory block in the list, and that and the subsequent memory blocks pointed to are examined until the data processor determines that one memory block addressed contains memory of size greater (or less) than that sought and the next memory block addressed contains memory of size less (or more) than that sought (variations include stopping at sizes twice as large on the assumption that the remaining memory taken from that will be sought again by the same program being executed; another variation is sorting by frequency of use). Returned memory is sorted into the list for the size range of that memory. Preferably the size ranges differ by integral powers of 2, and therefore size category of returned memory is determined by simple shifting of binary data defining the size and counting the shifts to reach a numerical zero. When memory is needed during the current program, only blocks of memory within the predetermined range of that needed are searched. Additionally, memory blocks the same size or within a close range of size are not included in the sort, but are pointed to by a second pointer address within the one of that size range reached by examining the sort. When that block is used, the pointer in that block identifies a next block to replace the first block in the sorted list. Accordingly, in the typical search, only one block of returned memory of close to each size is examined. The details of this invention will be described by way of example only in connection with the accompanying drawings in which Fig. 1 is illustrative of the apparatus supporting a printer and Fig. 2 is illustrative of data showing a distribution of memory sizes within logarithmic size categories. Standard terminology for data processing control code to carry out limited, repetitive function is a routine. Such terminology will be used here to mean control code to program the data processing operation to perform a stated function. Routines are activated (typical terminology: called) typically by another routine addressing the initial code in the routine. In this application a pointer is said to reach another address when by the data processor addressing the address pointed to it finds the reached address or it find a pointer which is to the reached address or to an address having a pointer which similarly either points to the reached address or other pointer which ultimately leads to the reached address. This embodiment employs standard data processing addresses, which are in digital codes and standard electronic memory addressing using such addresses. These are highly conventional and therefore will not be described in further detail. Pointers are such digital codes operated on as an address to relate a current address to an address which may be widely separated from the pointer address. An actual implementation operates on 32 bit words, which means that each address specifies 32 bits and reference to size of memory by number is by number of 32 bit words. (Alternative words sizes, specifically 16 bit words, are equally preferred.) This preferred implementation is designed to address three characteristics of memory usage, found particularly in applications such as printers: relatively large heap size; potentially severe fragmentation effects; and significant performance and resource limitations. As shown in Fig. 1, a first element of this implementation is a table or list of addresses 1 which represent where all free memory block are of size 0 to 7, 2 E n to 2 E n+1, where n are consecutive integers between 3 and 14, and equal and greater than 32,768. Each address in table 1 constitutes an address pointer for entry to a sorted list of return memory blocks within the size ranges of 0 to 7, 2 E n to 2 E n+1, and 32,768 and greater. Thus, address 1a in table 1 has a pointer which reaches all memory blocks of size 0 through 7; address 1b in table 1 has pointer which reaches all memory blocks of size 8 through 15; address 1c in table 1 has a pointer which reaches all memory blocks of size 16 through 31; address 1d in table 1 has a pointer which reaches all memory blocks of size 32 through 63; address 1e in table 1 has a pointer which reaches all memory blocks of size 64 through 127; address 1f in table 1 has a pointer which reaches all memory blocks of size 128 through 255; address 1g in table 1 has a pointer which reaches all memory blocks of size 256 through 511; address 1h in table 1 has a pointer which reaches all memory blocks of size 572 through 1023; address 1i has a pointer which reaches all memory blocks of size 1023 through 2047; address 1j has a pointer which reaches all memory blocks of size 2048 through 4095; address 1k has a pointer which reaches all memory blocks of size 4096 through 8191; address 1l has a pointer which reaches all memory blocks of size 8192 through 16,383; address 1m has a pointer which reaches all memory blocks of size 16,284 through 32,767; address 1n has a pointer which reaches all memory blocks of size 32,768 and greater. Table 1 with its pointers directed to memory of predetermined size may be termed a hash bin structure, the term "bin" referring to the separation of memory blocks into a continuum of different size ranges. As shown in Fig. 1, each of the addresses in Fig. 1 are pointers which identify one memory block 3. Thus, address 1f is a pointer to memory block 3a, which is the largest block of free memory between 128 and 255 words in size. If there are smaller blocks of free memory greater in size than 128, a pointer at memory block 3a is an address to the next smaller size memory block 3b. If there is a still smaller memory block greater in size than 128, a pointer at memory block 3b is an address to the next smaller size memory block 3c. In a typical situation, there may be hundreds of free memory blocks in a given bin. The final block in a list has a zero pointer, which may be all zero bits, which is recognized as not pointing to another, small block, but instead signalling the end of the list. At most all of the memory blocks 3 in a given bin will be searched for a memory of the proper size, while the others are not searched, as the search is initiated by data processor 5 addressing the address in table 1 which constitutes the bin for memory containing blocks 3, 7 within the range of the memory sought by data processor 5. For example, when data processor 5 seeks free memory of size of 3000 words, the controlling routine for memory selection is data processor 5 addresses 1j in the table 1 list. Next, the controlling routine in data processor 5 executes as an address the pointer in 1j to reach the largest memory block 3f in the bin of 1j. Only a few returned memories 3, 7 are shown in Fig. 1 for illustration. Each list ends with a memory block having a zero pointer, 3e, 3h and 3i being illustrated for lists 1f, 1a and 1n. It will be understood of course and is widely conventional that instructions or data accessed in sequence in a data processing routines may not necessarily be in such sequence in memory so long as the program code being executed is effective to reach the instructions and data in the required sequence. This can be true also of memory blocks, since the end of a numeric sequence of addresses to free memory might contain a linking instruction of some kind to another part of free memory. Typically, however, in this embodiment a block of memory is that memory which exists between two data processing address and their numeric intermediate addresses, and each block of returned memory contains data explicitly defining its size. Similarly, a pointer address is not necessarily physically near the memory which it represents, since it can be associated with another address pointing to the actual block of memory. Typically, in this application, however, the pointer address for each block of free memory 3 physically occupies that memory, since it is otherwise unused. Similarly, data defining the size of that memory block 3 and other incidental information, including the "third dimension" pointer to be described immediately below, also physically occupy its memory block 3, since it is otherwise unused. The memory blocks 3 carry a pointer to the preceding memory block 3 for operating efficiency in backward searching, as is conventional. The table 1 may be considered a first dimension of search, and the sorted memory blocks 3 from each bin of table 1 may be considered a second dimension of search. The search is further limited and made more efficient by taking more than one memory block 3 of the same size out of the sort list. Thus, as shown illustratively in Fig. 1 as round dots 7, memory blocks which are the same size, are not part of the blocks 3 in the sort list. Instead only one is in that list. For example block 3a, shown with two other blocks 7a and 7b. Block 3a contains a second address pointer in a predetermined location, which is recognized as signalling that a block 7a, the same size as block 3a, exists. When block 3a is selected for use, the existence of the second pointer is determined by data processor 5. When the second pointer is found, the sort pointer to block 3b may be applied to block 7a and the second pointer to block 7b is not changed because another block 7b exists and is another block having the same size as blocks 3a and 7a. When no block exists of the same size, the second pointer is a zero pointer, which may be all zeros, and which is recognized as not pointing to another memory block 7. Such a zero pointer is suggested in Fig. 1 by a bent arrow pointing downward. The memory blocks 7 may be variable in number as illustrated by block 7c, and 7d and an additional number in the omitted part of the drawing to reach block 7e. The last block in the la list points to identical size blocks 7g and 7h, the last, 7h, having a zero pointer for that list. The first block used for system memory by data processor 5 is the next block 7, 7g in this instance. The remaining block 7, such a 7h is then used. The last block used is block 3. This linkage of identical size memory blocks 7 while only one is contained in the sort list, may be expanded to grouping together blocks close in size. Nevertheless, this technique is particularly efficient for small ranges of sizes, such as 64 through 127, since all entries in that category can not vary more than 63 places in size. The same-size lists might be very large in this size range. As is standard for extracting an item from a sorted list, the pointer to the extracted memory 3 is changed to a pointer to the next block in the list. Thus, where 3b is selected for use, the pointer in 3a is changed to a pointer to 3c, the block 3 of the next lower size remaining. Where block 3c is selected, which does have a same-size block 7, the second pointer in 3c is changed to a pointer to 7d, and block 7c is released for use. This preferred implementation is a printer 9. This is suggested by the exit of a printed page of paper 11 by feed rollers 13a, 13b onto an exit tray 15 for use as a finished page of text or graphics, or both. Returned memory is typically explicitly designated by the page preparation software. Thus, data processor 5 typically is explicitly informed that a certain memory block of a certain size at a certain address is no longer needed. This constitutes a return of such memory for reuse. Other techniques to return memory are known, such as counting the calls to a memory block and acting on the block as returned when count reaches zero. Virtually any method of designating or locating returned memory is consistent with this invention and forms no part of this invention, since this invention is to subsequently locating such returned memory with high speed and data processing efficiency. Returned memory typically is given with a beginning and end address. In this embodiment, as is common, the size is explicitly contained in the header of the memory block as a binary number (the header being a portion of memory blocks reserved for associated data). That size number is then shifted in the direction of division by two until all digits are gone. The number of shifts defines the lower size of that memory block and it can not be larger than twice that size since in the natural binary system used, each column represents a significance of twice that of the preceding column. (Similarly, in an exponential numbering system, just the exponent can be used and the bins would vary with the size of integral powers of that base.) If in searching the sorted list for a bin, the first block 3 is too small, then the remaining blocks in the sorted list will be too small. A routine then continues the search through the next largest, non-empty bin as described. When a block 3 is reached that is too small, or the end of the sorted list of a bin is reached, then a system is applied to choose from among the previously encountered blocks 3. In the preferred embodiment the next larger block, which is the closest usable memory in size to that sought, is used when it is a few words close to that sought in size. This preserves larger blocks. Since, in general, breaking up blocks to leave a block on the same size order will create blocks of useful size when the large-enough block 3 is not close in size, a block intermediately found to be twice the size will be used. The search is continued in the higher, non-empty bins, to find a block twice the size sought, from which part is used. The remaining portion of that block is treated as returned memory and included in memory located by the sort list for the bin for memory encompassing the size of that unused portion. The search preference in order is: exact size, a few words larger, double in size, larger than double, and then the first block encountered which was larger. (The address of that first block is stored when it was found, and the address of a double size block is stored while an exact-size and a few-words-larger block is searched for.) The sort routine is conducted with each return of a memory block. The bin list is simply searched from one end with the size of each block 3 encountered compared to the size of the just-returned memory block. When the comparison changes from smaller to larger, the pointer in the larger block 3 is changed to point to the just-returned memory and the just-returned memory has a pointer added to it pointing to the smaller memory block 3. Also, as mentioned the backward pointers and the same size pointers are applied as discussed. If the new memory size is the same as an existing block 3, it is not added to the sort list, but is pointed to by the previous last memory in the same-size list. Although this invention is likely to improve performance in a variety of computer environments, it is particularly well suited to handle some of the worst computer system memory management scenarios: randomly sized memory blocks: widely varying block lifetimes; and a relatively large main memory that tends to "run full." These are all characteristics of demanding applications, such as laser printer and multi-tasking memory usage. The strengths of this invention are its extreme search efficiency, its low storage overhead, the inherent availability of block size alternatives when an exact match does not exist, and the comprehensive ordering of free memory blocks. Furthermore, this invention is applicable to a wide range of electronic memory, including disk storage. In order to provide search efficiency, the number of elements to be searched is reduced. Through grouping the blocks by size, the search is reduced by the immediate elimination of all groups roughly an order of magnitude smaller and larger than the block size sought by the data processor 5 (except for very small and very large blocks, which are grouped more broadly). Simple linear size grouping are not preferred since, for real applications, randomly sized block distributions have the general characteristic curve of the negative exponential function constant E minus x, where x is memory size. For this reason, the blocks would tend to be categorized into the same or a few bins. By contrast, the exponential definition of the bins of the preferred embodiment has the results of "flattening" the block distribution over the range of bins. Fig. 2 shows the average list lengths produced by printing a file for a PostScript (trademark) interpreter that required several thousand memory allocations with the intermediate bins defined exponentially as powers of 2 as described in the foregoing as the preferred embodiment. A somewhat levelled dispersion of the contents of the bins is apparent. Similarly, since the large bins contain blocks of large memory and the system memory is finite in size, they cannot have a large number of blocks 3 in their sort list, since such a large amount of memory is simply unavailable. And the small bins can not contain more blocks than their total range, which is intrinsically limited. In a test application for a printer, the bulk of the requests were for memory blocks no larger that 512 bytes in size and 97.8% of the requested memory blocks were from bins with a worst case search length of between 16 and 128 items in the sort. Of course, actual search lengths are far less than these maximums. And, since the lists are ordered, the number of search steps required will statistically tend toward half the average length of the list being searched. A test case for a sophisticated printer generated an average search depth of 3.86 blocks 3 per search over the entire job. Alternatively, for applications favoring certain memory sizes, the lists of blocks 3 need not be sorted by size and initially are not sorted at all. Instead, they are listed in order of returned, as is known for accessing memory prior to this invention. Thus, each time a certain size memory block is searched for and used, any duplicate size blocks of those used are moved to the front of the search list. Newly returned blocks along with their duplicates, if any exist, are inserted at the front of the search list. As searches are conducted, blocks of sizes more often used tend to move near the front of the list. As another alternative for large lists, table 1 bin addresses can address a second table divided by size in intervals. Each element of that second table would have the address to a list of blocks 3 within the size of that second table element. Other variations can be anticipated within the scope of this invention since it is not dependent upon the manner of addressing memory or determining the existence of free memory, and since wide variations in manner of listing and sorting memory blocks in the lists are acceptable. Similarly, the exponential (i.e., logarithmic to the base 2 in the preferred embodiment) distribution of bin sizes is an advantage but not essential to realizing other advantages as described of this invention.

Claims: Apparatus (9) comprising: electronic data processing apparatus (5); reusable electronic memory (3,7) addressable by address codes; means for providing a list of different pointer addresses (1a-1n), each address reaching memory regions within a particular first predetermined size range; and means (5) for determining in which first predetermined size range a particular region of returned memory lies; means for providing first address pointers associated with regions of returned memory within each first predetermined size range, characterised by each first address pointer indicating a region of returned memory (3a-3i) of a different size within the first predetermined size range; and in that the apparatus further comprises means for providing second address pointers associated with regions of returned memory, each second address pointer indicating regions of returned memory (7a-7j) of the same size or within a second predetermined size range smaller than and contained in a particular first predetermined size range; means (5) for comparing the size of the region of returned memory to previously returned memory regions to determine difference in size within the second predetermined range; and means (5) for setting first and second address pointers associated with the returned memory regions within the respective predetermined size ranges in accordance with the comparison. The apparatus as in claim 1 in which the lower boundary of each first predetermined size range varies by a factor of two from those of the adjacent ranges. The apparatus as in claim 1 or 2, in which said apparatus comprises a printer (9) controlled by said data processing apparatus (5).

Inventors: MURPHY DAVID WILLIAM, SHERWOOD GREGORY JOHN, MURPHY, DAVID WILLIAM, SHERWOOD, GREGORY JOHN
Applicants: LEXMARK INT INC, LEXMARK INTERNATIONAL, INC.
Application year: 1995
Main classification: G06F12
IPC codes: G06F12