This invention relates generally to data processing systems, and more particularly, to methods for optimizing the allocation and deallocation of shared memory to programs executing in a data processing system.
During execution, programs typically make many dynamic memory access requests. Such requests involve requesting allocation of memory from a system call (e.g., malloc), utilizing the memory, and deallocating the memory using a system call (e.g., free). Dynamic memory allocation is a fundamental and very important part of many computer programs. It is therefore desirable to improve the performance of memory access functions.
In accordance with methods and systems consistent with the present invention, an improved memory access function (e.g., malloc) is provided that dynamically improves its performance by changing its operation at runtime. The memory access function adapts its operation based on previous memory access requests to be able to provide the fastest response to those kinds of memory access requests that it predicts will be the most common. For purposes of this description “access to system memory” includes both requests for allocation of system memory and release of system memory, or deallocation. Similarly, a “memory request” refers to either an allocation (a request for system memory), or a deallocation (a return of previously requested memory).
In accordance with methods and systems consistent with the present invention, as embodied and broadly described herein, a method is provided in a data processing system for allocating memory. The method receives a memory request for a reference to a block of memory. Then it returns the reference to the block of memory to satisfy the request. Next, it adjusts an operation of the memory access function based on the memory request.
Furthermore, in accordance with methods and system consistent with the present invention, as embodied and broadly described herein, a system for providing access to memory includes a memory which further includes a program including a memory access function that provides access to memory and adjusts its operation according to a memory request for a reference to a block of memory, and a processor for executing the program.
Methods and systems consistent with the present invention provide a function called “smart-alloc” that adapts in real-time the memory allocation process to threads executing in a data processing system. More specifically, smart-alloc observes past memory allocation behavior and adjusts the process of providing memory access such that the most frequently requested memory blocks of a specific size are allocated faster than less frequently requested memory block sizes. Smart-alloc is a language-independent library function which may be linked to one or more programs operating in a multi-processing environment.
Overview
When a program begins execution, smart-alloc secures access to an amount of memory that may be accessed as needed by threads executing within the program. Upon receiving a pointer from a system memory call to an amount of memory requested, smart-alloc divides the memory into blocks of varying sizes, grouping blocks of like size together in a linked-list, referred to as a free memory linked-list. Smart-alloc creates two trees that point to the free memory linked-lists: a fast access tree and a general access tree. As a program executes, the fast access tree points to the most frequently accessed memory block sizes, and the general access tree points to block sizes not pointed to by the fast access tree. Each free memory linked-list will be pointed to by either the general access tree, or the fast access tree, but not both.
Upon receiving a request from an executing thread for access to memory, smart-alloc increments a counter associated with the block size that will be used to satisfy the memory request. To satisfy the memory request, smart-alloc first determines whether the fast access tree points to memory blocks of the size needed to satisfy the request. If the fast access tree includes memory blocks of the size needed to satisfy the request, smart-alloc satisfies the request from the fast access tree. Otherwise, smart-alloc satisfies the request from the general access tree. If a request is satisfied from the general access tree, smart-alloc compares the value of the counter associated with the allocated block size to the counter values for block sizes included in the fast access tree to determine whether the general access tree refers to block sizes most frequently requested. If the counter value for the allocated block size (from the general access tree) is greater than any of the counter values of block sizes included in the fast access tree, smart-alloc replaces that general access tree pointer to the block size having the highest counter value with a pointer from the fast access tree, and replaces the pointer to the block size included in the fast access tree having the lowest counter value with a pointer from the general access tree. This process ensures that the fast access tree continues to point to the most frequently requested block sizes.
Smart-alloc also receives requests from executing threads desiring to release references to blocks of memory. After receiving a released reference, smart-alloc adds the reference to the free memory linked-list that includes memory blocks corresponding to the size of the returned reference.
Implementation Details
Programs 155, 160, and 165 share access to shared memory 180. Programs 155, 160, and 165 may include a single thread or multiple threads. Although multiple processors are shown, one skilled in the art will appreciate that programs 155, 160, and 165 may execute on a single processor to implement methods and practice systems consistent with the present invention.
Operating system 170 represents the Solaris® operating system from Sun Microsystems, Inc., which specifically facilitates multi-threaded program execution, although any operating system may be used to implement methods and systems consistent with the present invention.
Although aspects of this implementation are depicted as being stored in memory 150, one skilled in the art will appreciate that all or part of systems and methods consistent with the present invention may be stored on or read from other computer readable media, such as secondary storage devices, like hard disks, floppy disks, and CD-ROM; a digital signal received from a network such as the Internet; or other forms of RAM or ROM, either currently known or later developed. Sun, Sun Microsystems, and the Sun logo are trademark or registered trademarks of Sun Microsystems, Inc. in the United States and other countries.
Upon receiving a memory request from an executing thread (step 325), smart-alloc increments the value of a counter associated with the block size used to satisfy the request (step 330). Thus, if a thread requests 1026 bytes of memory and the free memory linked-lists include 1K and 2K blocks, a reference to the 2K block will be returned to the requesting thread, and the value of the counter associated with the 2K free memory linked-list will be incremented. If this memory request is satisfied from the fast access tree (step 335), processing ends.
Otherwise, if the memory request is satisfied from the general access tree (step 340), then the counter associated with the block size used to satisfy the request is compared with the counter for block sizes pointed to by the fast access tree (step 370). Smart-alloc then determines whether the block size should be added to the free memory linked-list pointed to by the fast access tree step 375 because it includes memory blocks of a size most often requested by the executing program. In this step, smart-alloc compares the value of the counter associated with a block size included in the general access tree with the value of the counter of a block size included in the fast access tree. If the counter value for the block in the general access tree is greater than the counter value for the block in the fast access tree, the pointer from the general access will be replaced with a pointer from the fast access tree. Additionally, the fast access tree pointer that points to the block size having the lowest counter value is replaced with the pointer from the general access tree (step 380). Changing the pointers in this manner ensures that the fast access tree continually points to the most frequently allocated block sizes, thereby increasing the efficiency of memory allocation. Otherwise, if the counter value associated with the block in the general access tree is not greater than the counter value of any of the free memory linked-lists pointed to by the fast access tree, processing ends.
If a memory request cannot be satisfied from either the general or fast access trees, smart-alloc requests additional memory from a system memory call (step 345). If the additional memory is available (step 350), a pointer to the amount of memory is returned to smart-alloc (step 355), the memory is divided into blocks that are added to the free memory linked-lists pointed to by a pointer from the general access tree (step 360), and processing continues to step 335. Otherwise, if the requested amount of memory is not available, the system memory call returns a null pointer to smart-alloc (step 365), and processing ends.
Methods and systems operating in accordance with the principles of the present invention optimize the process of allocating memory to threads executing in programs operating in a data processing system by adapting the allocation process according to the behavior of an executing program. This smart-alloc function is a library function that may be linked to any program executing in a data processing system. As discussed above, smart-alloc operates in the user space and does not require accessing the operating system each time memory is allocated or deallocated. These distributive and adaptive features of smart-alloc allow it to minimize the number of accesses to the operating system, a costly and time consuming event, and ultimately yields increased system performance.
Methods and systems consistent with the present invention are applicable to all single and multi-threaded programs written in all computer programming languages, including Fortran 77, Fortran 90, Java, C, and C++. Although maximum increases in efficiency will be realized in a multi-processor computing environment, methods and systems consistent with the present invention may also provide operational benefits in a single or multi-threaded, single processor environment.
Although the foregoing description has been described with reference to a specific implementation, those skilled in the art will know of various changes in form and detail which may be made without departing from the spirit and scope of the present invention as defined in the appended claims and the full scope of their equivalents.
Number | Name | Date | Kind |
---|---|---|---|
4675832 | Robinson et al. | Jun 1987 | A |
4685082 | Cheung et al. | Aug 1987 | A |
4812996 | Stubbs | Mar 1989 | A |
5073851 | Masterson et al. | Dec 1991 | A |
5075847 | Fromme | Dec 1991 | A |
5079707 | Bird et al. | Jan 1992 | A |
5119465 | Jack et al. | Jun 1992 | A |
5146593 | Brandle et al. | Sep 1992 | A |
5168563 | Shenoy et al. | Dec 1992 | A |
5179702 | Spix et al. | Jan 1993 | A |
5274813 | Itoh | Dec 1993 | A |
5274821 | Rouquie | Dec 1993 | A |
5297274 | Jackson | Mar 1994 | A |
5301312 | Christopher, Jr. et al. | Apr 1994 | A |
5325499 | Kummer et al. | Jun 1994 | A |
5325533 | McInerney et al. | Jun 1994 | A |
5353401 | Iizawa et al. | Oct 1994 | A |
5390314 | Swanson | Feb 1995 | A |
5438659 | Notess et al. | Aug 1995 | A |
5450542 | Lehman et al. | Sep 1995 | A |
5485619 | Lai et al. | Jan 1996 | A |
5497458 | Finch et al. | Mar 1996 | A |
5499349 | Nikhil et al. | Mar 1996 | A |
5500881 | Levin et al. | Mar 1996 | A |
5519866 | Lawrence et al. | May 1996 | A |
5530816 | Holt | Jun 1996 | A |
5535364 | Resman et al. | Jul 1996 | A |
5535393 | Reeve et al. | Jul 1996 | A |
5539907 | Srivastava et al. | Jul 1996 | A |
5553235 | Chen et al. | Sep 1996 | A |
5574922 | James | Nov 1996 | A |
5613063 | Eustace et al. | Mar 1997 | A |
5636374 | Rodgers et al. | Jun 1997 | A |
5640550 | Coker | Jun 1997 | A |
5673387 | Chen et al. | Sep 1997 | A |
5675790 | Walls | Oct 1997 | A |
5675802 | Allen et al. | Oct 1997 | A |
5689712 | Heisch | Nov 1997 | A |
5696937 | White et al. | Dec 1997 | A |
5710727 | Mitchell et al. | Jan 1998 | A |
5724262 | Ghahramani | Mar 1998 | A |
5734822 | Houha et al. | Mar 1998 | A |
5737605 | Cunningham et al. | Apr 1998 | A |
5740431 | Rail | Apr 1998 | A |
5740433 | Carr et al. | Apr 1998 | A |
5742793 | Sturges et al. | Apr 1998 | A |
5745897 | Perkins et al. | Apr 1998 | A |
5748892 | Richardson | May 1998 | A |
5748961 | Hanna et al. | May 1998 | A |
5754820 | Yamagami | May 1998 | A |
5761426 | Ishizaki et al. | Jun 1998 | A |
5774724 | Heisch | Jun 1998 | A |
5784698 | Brady et al. | Jul 1998 | A |
5787480 | Scales et al. | Jul 1998 | A |
5805795 | Whitten | Sep 1998 | A |
5812799 | Zuravleff et al. | Sep 1998 | A |
5835705 | Larsen et al. | Nov 1998 | A |
5850554 | Carver | Dec 1998 | A |
5860024 | Kyle et al. | Jan 1999 | A |
5864867 | Krusche et al. | Jan 1999 | A |
5867649 | Larson | Feb 1999 | A |
5867735 | Zuravleff et al. | Feb 1999 | A |
5872977 | Thompson | Feb 1999 | A |
5890171 | Blumer et al. | Mar 1999 | A |
5905488 | Demers et al. | May 1999 | A |
5905856 | Ottensooser | May 1999 | A |
5913223 | Sheppard et al. | Jun 1999 | A |
5920895 | Perazzoli, Jr. et al. | Jul 1999 | A |
5963975 | Boyle et al. | Oct 1999 | A |
5968114 | Wentka et al. | Oct 1999 | A |
5970510 | Sher et al. | Oct 1999 | A |
5974510 | Cheng et al. | Oct 1999 | A |
5974536 | Richardson | Oct 1999 | A |
5978892 | Noel et al. | Nov 1999 | A |
5987479 | Oliver | Nov 1999 | A |
5991708 | Levine et al. | Nov 1999 | A |
5991893 | Snider | Nov 1999 | A |
6006031 | Andrews et al. | Dec 1999 | A |
6009514 | Henzinger et al. | Dec 1999 | A |
6014517 | Shagam et al. | Jan 2000 | A |
6016474 | Kim et al. | Jan 2000 | A |
6018793 | Rao | Jan 2000 | A |
6023583 | Honda | Feb 2000 | A |
6044438 | Olnowich | Mar 2000 | A |
6049798 | Bishop et al. | Apr 2000 | A |
6049855 | Jeddeloh | Apr 2000 | A |
6052708 | Flynn et al. | Apr 2000 | A |
6052763 | Maruyama | Apr 2000 | A |
6055368 | Kunioka | Apr 2000 | A |
6065019 | Ault et al. | May 2000 | A |
6066181 | DeMaster | May 2000 | A |
6072951 | Donovan et al. | Jun 2000 | A |
6077312 | Bates et al. | Jun 2000 | A |
6081868 | Brooks | Jun 2000 | A |
6085029 | Kolawa et al. | Jul 2000 | A |
6088771 | Steely, Jr. et al. | Jul 2000 | A |
6098169 | Ranganathan | Aug 2000 | A |
6101325 | Flaat | Aug 2000 | A |
6101525 | Hecker | Aug 2000 | A |
6108343 | Cruickshank et al. | Aug 2000 | A |
6119198 | Fromm | Sep 2000 | A |
6125430 | Noel et al. | Sep 2000 | A |
6141692 | Loewenstein et al. | Oct 2000 | A |
6145054 | Mehrotra et al. | Nov 2000 | A |
6167565 | Kanamori | Dec 2000 | A |
6173327 | De Borst et al. | Jan 2001 | B1 |
6173368 | Kreuger et al. | Jan 2001 | B1 |
6205537 | Albonesi | Mar 2001 | B1 |
6223134 | Rust et al. | Apr 2001 | B1 |
6253252 | Schofield | Jun 2001 | B1 |
6263485 | Schofield | Jul 2001 | B1 |
6269457 | Lane | Jul 2001 | B1 |
6282702 | Ungar | Aug 2001 | B1 |
6286130 | Poulsen et al. | Sep 2001 | B1 |
6295600 | Parady | Sep 2001 | B1 |
6304951 | Mealey et al. | Oct 2001 | B1 |
6311320 | Jibbe | Oct 2001 | B1 |
6314429 | Simser | Nov 2001 | B1 |
6317871 | Andrews et al. | Nov 2001 | B1 |
6341338 | Dennie | Jan 2002 | B1 |
6351845 | Hinker et al. | Feb 2002 | B1 |
6353829 | Koblenz et al. | Mar 2002 | B1 |
6353869 | Ofer et al. | Mar 2002 | B1 |
6366994 | Kalyur | Apr 2002 | B1 |
6369725 | Busaba | Apr 2002 | B1 |
6430657 | Mittal et al. | Aug 2002 | B1 |
6434714 | Lewis et al. | Aug 2002 | B1 |
6438745 | Kanamaru et al. | Aug 2002 | B1 |
6442162 | O'Neill et al. | Aug 2002 | B1 |
6473833 | Arimilli et al. | Oct 2002 | B1 |
6480818 | Alverson et al. | Nov 2002 | B1 |
6496902 | Faanes et al. | Dec 2002 | B1 |
6502136 | Higuchi et al. | Dec 2002 | B1 |
6523090 | Tremblay | Feb 2003 | B1 |
6542919 | Wendorf et al. | Apr 2003 | B1 |
6574725 | Kranich et al. | Jun 2003 | B1 |
6629214 | Arimilli et al. | Sep 2003 | B1 |
6647546 | Hinker et al. | Nov 2003 | B1 |
6684296 | Hayter et al. | Jan 2004 | B1 |
20010003831 | Boland | Jun 2001 | A1 |
20010051974 | Saad | Dec 2001 | A1 |
20020046201 | Hembry | Apr 2002 | A1 |
20020073360 | Lewis et al. | Jun 2002 | A1 |
20020078010 | Ehrman et al. | Jun 2002 | A1 |
20030061395 | Kingsbury et al. | Mar 2003 | A1 |
Number | Date | Country |
---|---|---|
199 34 515 | Jan 2000 | DE |
0 390 339 | Oct 1990 | EP |
0 703 534 | Mar 1996 | EP |
0 817 044 | Jan 1998 | EP |
0 965 921 | Dec 1999 | EP |
1 024 432 | Aug 2000 | EP |
1 026 592 | Aug 2000 | EP |
1 081 585 | Mar 2001 | EP |
2 793 908 | Nov 2000 | FR |
2 324 942 | Nov 1998 | GB |
2 343 029 | Apr 2000 | GB |
2 357 873 | Jul 2001 | GB |
03-282731 | Dec 1991 | JP |
07-056716 | Mar 1995 | JP |
07-156716 | Mar 1995 | JP |
WO 9910812 | Mar 1999 | WO |