CA2136154C - User control of multiple memory heaps - Google Patents

User control of multiple memory heaps

Info

Publication number
CA2136154C
CA2136154C CA002136154A CA2136154A CA2136154C CA 2136154 C CA2136154 C CA 2136154C CA 002136154 A CA002136154 A CA 002136154A CA 2136154 A CA2136154 A CA 2136154A CA 2136154 C CA2136154 C CA 2136154C
Authority
CA
Canada
Prior art keywords
heap
memory
block
runtime library
user application
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Expired - Fee Related
Application number
CA002136154A
Other languages
French (fr)
Other versions
CA2136154A1 (en
Inventor
Jay William Benayon
Brian W. Thomson
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
IBM Canada Ltd
Original Assignee
IBM Canada Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by IBM Canada Ltd filed Critical IBM Canada Ltd
Priority to CA002136154A priority Critical patent/CA2136154C/en
Priority to US08/559,904 priority patent/US5809554A/en
Publication of CA2136154A1 publication Critical patent/CA2136154A1/en
Priority to US09/088,747 priority patent/US6816956B1/en
Application granted granted Critical
Publication of CA2136154C publication Critical patent/CA2136154C/en
Anticipated expiration legal-status Critical
Expired - Fee Related legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5011Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
    • G06F9/5016Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals the resource being the memory
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y10TECHNICAL SUBJECTS COVERED BY FORMER USPC
    • Y10STECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y10S707/00Data processing: database and file management or data structures
    • Y10S707/99951File or database maintenance
    • Y10S707/99952Coherency, e.g. same view to multiple users
    • Y10S707/99953Recoverability
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y10TECHNICAL SUBJECTS COVERED BY FORMER USPC
    • Y10STECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y10S707/00Data processing: database and file management or data structures
    • Y10S707/99951File or database maintenance
    • Y10S707/99956File allocation

Abstract

The present invention provides the user with the ability to control and administer the supply of memory managed in multiple heaps by a library heap management facility. The control data used by the heap management facility is located in the user-supplied memory. Heaps are created dynamically through calls from the application to the runtime library. Allocation within a heap is performed through calls to the runtime library that canvass the available heap memory for each allocation request. If no suitable block of heap memory is located, additional user supplied memory is requested for the application through a callback function. A
second callback function notifies the user when a supplied unit of memory is no longer required by the heap and may he disposed of. The callback functions are specified separately for each heap. The invention also provides the user with means for setting the default heap in the runtime library for use by allocation requests from a vendor library that do not specify a heap. This can be done on a per thread basis in multithreaded applications so that different executing threads can use different default heaps in a non-interfering manner.

Description

`

USER CONTROL OF MULTIPLE MEMORY HEAPS

FIELD OF THE INVENTION

The present invention relates to improved memory management in a computing environment by permitting the dynamic allocation of multiple memory heaps as required during program execution, and providing the user with direct control over all memory managed or used by each heap.

BACKGROUND OF THE INVENTION

The heap is that area in memory that is generally allocated at the commencement of program execution for dynamically constructing data objects used for executing the application. Traditionally, the heap remains static during program execution, and is destroyed at the completion of the application.

While early programming systems allocated only one heap during program e~ecution, the intermingling of 16-bit and 32-bit code within applications has resulted in more recent operating systems, such as IBM's OS/2rM operating system, providing support for allocating two heaps. Generally, these two heaps are referred to as the regular heap for receiving only 32-bit coded data objects, and tiled heap that is usable either for 16 or 32-bit code.

The so-called regular heap is based on flat or linear pointers (addresses) referenced to a zero-based address. The heap ilsclf, then, can span a very large segment ofmemory (up to four gigabytes in sizc) with pointers based on the same flat or zero address base.

Tiled memory, refers to the fact that the pointers are tiled- their base linear addresses are set to be multiples of fi4K because of a limitation in 16-bit code 213615~
`

precluding the referencing of data objects spanning 64K boundaries.

A further type of heap in recent development is a shared memory heap (whether in regular or tiled format) that would permit data objects to be accessed directly by several applications at once, or by multiple instances of a single application.
Clearly, the shared memory concept reduces processing time by avoiding construction of the same data objects in multiple applications and by simplifying the problems of synchronization and coherence where one application modifies thedata.

Multiple heaps (that is, even more than two)? have been provided in very recent products such as "SmartHeap" of MicroQuill Software Publishing. The value of any double or multiple heap system includes hetter data locality, the ability to free one heap in a single efrlcient operation, while retaining data in other heaps, and less contention in multithreaded applications if each thread has its own heap, and this has been accomplished in the prior art through system calls controlled by the runtime library as described below.

As illustrated schematically in Figure l, an application call to allocate/deallocate additional heap memory (tiled or regular) is i.ssuecl to the runtime library and is processed by a memory manager located in the library by issuing system calls to the operating system to acquire or release memory for the heap. Under the traditional approach, allocation Of ad(litiomll hcap mcmory is controlled entirely by the runtime library, nol by the user.
In "A List Box Replacement" - Benge, Mark A. and Smith, Matt, OS/2 Developer, - Jan./Feb. 1994, pages 6fi to 70, a mo(lirlcation of the traditional memory management system is described that is claimed to permit lhe user somewhat more flexibility in allocating memory rrom different heaps and to guarantee minimal memory conf~lgurations when require(l by the user. A new HeapAlloc call initiates 213615~
, the heap by requesting a block of memory using a DosAllocMem system call. The address returned by DosAllocMem is the starting chunk of memory for the heap and is invariably used as the heap handle. When this value is passed to HeapMalloc, HeapCalloc, HeapRealloc, and HeapFree routines, each routine will correctly select the starting chunk and determine from which memory chain to carve or free the memory. To discard the heap, a new HeapRelease call is used that releases all the memory of the heap, (not individua] memory blocks) back tothe system.

Attempts have been made to deal with memory management without having to resort to expensive system calls at each instance. For example, in US Patent #5,339,411 - Heaton, a method is disclosed in which the memory is allocated intoa number of memory blocks of varying size at the time the memory space is initialized (usually during initialization of the appl;cation program). Then, inresponse to a memory allocation re~luest during execution of the application, a routine is initiated that scans the stored block constants to locate a memory block of the appropriate size to meet the specifications of the allocation request. A
mechanism is also provided that permits encroachment into a second adjacent memory block where no one memory block is large enough to meet the specifications of the memory allocation request.

Other references, such as US Patent # 5,08~,036 - Ellis, et. al. and 5,136,706 -Courts propose methods for more efficient memory management through dividing the available memoty space into regions with specific attributes so that only active objects are located in active regions, to reduce paging and other accessing operations.

Improved garbage collection, such as in the methods proposed in US Patent #4,907,151 - Bartlett and 5,1()9,336 - Guenther, et al., is another way to maximize memory management efficiency in a predefined memory space.

`_ In addit;on to the foregoing, US Patent #5,317,706 - Pechter provides a hardwaresolution to increasing available virtual memory spacing in a processing environment through the addition of extended memory circuits. The extended memory is logically located or mapped to a portion of the original virtual address space which has been partitioned into a reduced virtual address space and an extended real memory address space.

However, none of the prior art methods proposed in the patent literature improveupon the traditional method for increasing heap memory allocation during programexecution described above, that is through the routine allocation of additional memory instituted through system calls.

In addition, nothing in the prior art suggests a memory management system that actually permits the user to control the heap or type of heap in which the objects are to be constructed and controls the creation (allocation) and destruction (deallocation~ of different heaps and different heap types.

SUMMARY OF THE lNVENTlON

It is therefore an object of the present invent;on to provide user control of multiple heaps in an operating system.

It is also an object of this invention to provicle better performance of allocation and freeing operations within a heap, and to provide the user with the ability to free a single heap in one emcient operation while retaining data allocated in other heaps.

A further object is to provide ]ess contention in multithreadecl applications, by providing the user with the ability to allocate to each executing thread its owndedicated heap.

-Aeeordingly, the present invention provides a meehanism for user heap management during program exeeution ;n an operating system having means for alloeating dynamie memory. The meehanism consists of eontrol means located in the exeeuting program for d;recting heap allocation requests, preferably on datastorage media adapted to be executed on a general purpose computer.

Preferably, in one aspect, the control means consists of means for locating a block of heap memory of a suitable size for fulfilling the alloeation request along with means for storing information in a portion of the heap memory defining parameters of the heap memory.

Preferably, in another aspeet, the eontrol means eonsists of means for setting adefault heap definition in the runtime library means.

The present invention also prov;des a proeess for managing heap alloeation from a user applieation exeeuting ;n an operating system having means for extending heap memory. The process includes the steps of issuing a callback function from the runtime library means to the user application for a heap extension of at least the minimum size, determining if a block of memory of at least the minimum size is available, and removing and returning to the user application an object of atleast the minimum size from the block of heap memory.

Preferably, the process also includes the steps of initiating a call to the operating system from the user application for heap memory extension on receiving a null determination of available heap memory and insetting heap eontrol data into a bloek of heap memory alloeated by the eall to the operating system.

Alternatively, the invention provides a proeess for directing heap memory use from a user application exeeuting in an operating system having runtime library meansand at least secondary library means. The process includes the steps of issuing a function call from the user application to the runtime library means to define adefault heap in the runtime library means, the issuing of a function call from the user application to the secondary library means for construction of a data object on the default heap, and finally issuing a heap allocation request from the secondary library means to the runtime library means for construction of the data object on the default heap.

Preferably, the above steps may be repeated for e~ery thread in a multithreaded user application.

BRIEF DESCRIPTION OF THE DRAWINGS

Embodiments of the invention will now be described in cletail in association with accompanying drawings, in which:
Figure I is a simplirled block diagram illustrating the processing requests for heap memory allocation from an executing application, according to the method of the prior art;
Figure 2 is a simplified block diagram illustrating the processing of requests for heap memory allocation from an executing application, according to one aspect of the present invention;
Figure 3 is a flow diagram illustrating the use of the _ucreate function to create a new heap;
Figure 4 is a flow (liagr,lm illustrating the use Of ~he _uopen function to openan existing heap for use;
Figure 5 is a flow diagram illustrating the use of the user exhausted routine during operation of a memory allocation, according to one aspect of the present invention;
Figure 6 is a flow diagram illustrating the use of thc _udestroy function to collapse the entire heap, according ~o one aspect of the present invention;
Figure 7, on the same l~age as Figure 4, is a schematic diagram showing the 213615~
~,.
CA9-~4-029 7 partitioning of memory allocated in the heap according to the present invention;and Figure 8 is a schematic diagram illustrating the setting of a default heap, according to another aspect of the present invention.

DETAILED DESCRIPTION OF PREFERRED EMBODIMENTS

Unlike the prior art process illustrated in Figure l, in the present ;nvention, heap expansion or contraction requests from the runtime library are made to the application, which can then issue corresponding requests to the operating systemas illustrated schematically in Figure 2. There is no longer a direct communication for this purpose between the runtime library and the operating system, with the result that the user has full control over heal- memory allocation.

This is accomplished by locating the heap control data, that include the heap type (tiled, shared, etc.) and semaphores for multithreading in memory supplied by the application, rather than in the runtime library as in the prior art. In the preferred embodiment, the heap control data includes "sanity marks" which are known to those skilled in the art and which are data or a predetermined value, such valuebeing selected with the expectation that it would be unlikely to be found in a memory area chosen at random. In the preferred embodiment, the presence of the sanity marks in the expected location within the control data area of a purported heap is considered evidellce that the purported heap is a valid heap. Then, for heap memory allocation, the runtime library must make callbacks to the application rather than system calls to the operating system to grow or shrink the pool of available memory on a heap.

The application thereby controls requests to create, free, allocate, release, exhaust and destroy heaps as illustrated by the event edges in Figure 2.

213615~
-Growable and shrinkable heaps are implemented by two cal]back functions, according to the preferred embodhnent of the invention. One function, exhausted,is called during an allocat;on request that cannot be satisfied by available free heap memory and al]ows the heap creater to optionally grow the heap with memory of the appropriate type. The second function7 release, is called when the heap is being destroyed and allows the heap creator to release all blocks of memory provided to that heap. The heap may al.so be grown by the user function _uaddmemdescribed below.

The user provides an initial ~tarting block for the heap routines to use. If a particular pool cannot satisfy an allocation recluest, then an exhausted routineprovided by the user will be called specifying the minimal amount of memory thatthe heap requires to satisfy the user allocation. This process will continue until the heap is destroyed and the user release routine is called for every block of memory that was inserted into the heap by the user.

The initial block of memory of the desired type is supplied by the user using the _ucreate function, to be described in detail below. In addition to this, the following functions are defined in the rllntime library in the preferred embodiment of theinvention in order to implement callbacks from tlle runtime library:

Heap_t _ucreate(void *pool, size_t init_sz, int blockclean, int mem_f lags void *(*exhausted) (size_t *sz, int *clean), void (*release) (void *b1Ock size_t sz) ) As illustrated in Figure 3 and in the C code fragment above, in a preferred embodiment, the invention provides_uereate which creates a user heap. The function operates similarly whethcr or not another heap already exists. In the first step (block 1) the application initiates the_uereate call and defiries an initial chunk of memory needed, size, flags, exhausted function and release function.

-The _ucreate function returns tlle handle heap_t identifying the heap. The parameters passed by the user include pool, which is the memory address of the initial block available for use, of the size init_sz bytes, which must be at least _HEAP_MIN_SIZE (block 2). lf the initial size init_sz of the block is smaller than HEAP_MIN_SIZE, the system returns a NULL (block 3). Tf the initial size is at least equal to _ HEAP_ MIN_SIZ~ bytes, the runtime will mark the first _ HEAP_MIN_SIZEbytes as a reserved area for the heap which will be used to store information relative to the heap as describecl below with respect to the heap structure (block 4). NULL will also be returned if any other errors occur on the call.

Sanity markers are placed at the start ancl end of the reserved area (block 5). A
pointer to the release functiollis assigned with the value passed (block 6), and a pointer to the exhausted function is assigned with the value passed (block 7). Apointer to the list of all the chunks of memory inserted into the heap is cleared (block 8), all these pointers in blocks G, 7 and 8 being in the reserved area. A flag in the reserved area is set if the heap will be using shared memory, and is cleared if the heap will not be using shared memory (blocks 9, lO, and l l).

A structure containing all the necessary ;nformation for the heap management routines is initialized (block 12). This structure may contain the start of the free object list, a pointer to the used list, the minimum and maximum addresses inserted into the heap, ancl statistics indicating the amount of used memory. This is equ;valent to placing all the global variables specific to the single heap implementation in a structure withh~ this rcservcd area.
In the case of a multithreaded environment, a semapllore specific to this particular heap is created (block 13 and 14) via a system call, ancl the structure for it is also stored with the reserved area.

The remaining pool that was passed in, less the area marked as reserved, is 21~6159 -inserted into the heap used to manage the memory (block l S and l 6). The operation of insertion onto the heap is specific to the base memory management algorithm used.

A pointer to the start of the reserved area is returned to the user as a heap handle to the newly created heap (block l 7). The user will reference this value as a heap handle in future heap specific calls.

In void* (*exhausted)(size_t *sz, int *clean), exhausted iS a pointer to a callback function that wil] be issued hy the runtime library if it has insufficient memory available in the heap to satisfy an allocation request from the application.
The sz points to an unsigned integer variable initialized to the minimal amount of memory that this routine must provide back to the heap routines. The returned value is a pointer to a chunk of memory supplied by the application to extend the heap or is a null if the application declines to extend the heap. The user has the option to return a larger block than requested by modifying the size variable *sz.

The clean parameter will point to an integer variable that must be set by the exhausted function to the value _BLOCK_CLEAN to indicate that the block is all zeros or to !_BLOCK_CLEAN to indicate otherwise.

void (*release)(void *block, size_t sz), the block will point to a memory block that was provided by the user hy the exhausted routine or _uaddmem.

This callback routine will be callcd from _udestroy for a user created (or assigned) memory pool that requ;res blocks to be returned back to the operating system.

mem_flags: can be defined as _HEAP_TILED, _HEAP_SHARED, or _HEAP_REGULAR

21~615~

exhausted: is the user callback function called when memory is required by the heap.
release: is the user callback function callecl when memory is released by the heap.

int _uopen(Heap_t heap) where heap is a valid heap handle identifying a heap that will be opened for usage.

This function allows the cur rent process to use the heap, and must be called in all processes where the heap will be accessed implicitly and explicitly. If successful, 0 [zero] is returned.

In operation, the _uopen function called by the user application (Figure 4, block 20) accepts a heap handle that points to the heap internal structure. The heap internal structure sanity marks are checked within the reserved area and an error reported if they are not the predetermined values (blocks 22, 24).

Knowing that a valid internal heap structure exists, the system specirrc structure for the semaphore is passed On to the operating system to grant access to this semaphore to the current process that initiated the call (block 26).

The return code received by the operating system is then returned to the user indicating the opening Or the semaphore was pcrformcd successrully (block 28).

int _uclose(Heap_t heap) where: heap is a valid heap handle identifying a heap that will be closed for usage.

-This function notifies the runtime that the executing application will no longerrequire the usage of this heap. If successful, () is returned.

The operation of this routine although opposite in purpose to the operation of the _uopen function, follows the same steps as those illustrated in Figure 4. When called by the application (block 2()), _uclose will accept a heap handle that points to the heap internal structure. The heap internal structure sanity marks will bechecked within the reserved area and an error reported if it is not a predetermined value (block 22, 24).

Knowing that a valid internal heap structure exists, the system specific structure for the semaphore will be passed on to thc operating system to remove access of this semaphore by the current process that initiated the call (block 26).

The return code received from the operating system is then returned to the user indicating if the opening of the semaphore was performed successfully (block 28).

void * _umalloc(Heap_t heap, size_t size) void * _ucalloc(Heap_t heap, size_t size, size_t qty) These functions will behave differently from the prior art single-heap versions malloc and calloc respectively in that allocations will be made from the supplied heap. NULL will be returned if the request cannot be satisfied by the exhausted function.
_umalloc allocates memory from the supplied heap area of the size specified, as illustrated in Figure S. The routine is called by the applieation, and accepts a heap handle that points to the heap internal structure (block 30). The heap internal structure sanity marks will be checked within the reserved area and an error reported if they are not predetermined values (blocks 34, 36).

The heap is serialized by methods known to those skilled in the art, for exampleby locking a system scmaphore stored in the heap reserved area ~block 38).

Using this heap handle, a call to the memory allocation algorithm is made for a request of the provided size (block 3~). If there is not enough memory available in the specirled heap to satisfy the request (block 4), then the user's exhausted callback function (specirled in _ucreate)is called with the size re~uired (block 42).
If the callback returns a NULL indicating that it could not satisfy the request, then NULL is returned back to the original caller (block 44, 46). Othcrwise, the new object inserted is added to the linked list maintained within the heap reserved area for inserted user objccts.

The new block returned hy the callback routine is inserted into the heap (block 48).
The object of the required size is removed from the heap (block 50) and the sizeand handle are stored in the first eight bytes of the object (block 52). The user part of the object is returned to the application (block 54).

In order to recognize the heap where an object was allocated from during deallocation, an internal area within the object returned must be set to mark the size and heap handle used as illustrated in Figure 7. The portions of the heap allocated to size 70 and heap handle 72 making up the internal information of the allocated object, are returned hy rcgular _umalloc function to the user. The remaining sz bytes constitutes the user area 74 in the ohject. The address returned to the user is the addless or the user area 74 within the ohject.
The heap is deserialized by methocls known to thl)se skilled in the art, for example by unlocking a system semaphore stored in thc heap reserved area.

The _ucalloc function is sim;lar to that of _umalloc except the memory area is cleared with the null byte on return.

void free(void *ptr) void *realloc(void *ptr, size_t size) The routines will determine the hcap used during the initial allocation, and then perform the given operation bascd on that heap. If NULL is passed to realloc, then the default heap will be used for the allocation. The return values and expectedarguments will be thc same as in free and realloc calls known to those skilled in the art.

Heap_t _uaddmem (Heap_t heap, void *block, size_t sz, int clean) This user function can be used to extend a heap by adding a chunk of memory to it. The parameter block here points to the chunk of memory that the application is providing to extend the heap.

int _udestroy(Heap_t heap, int force) where: heap is a handle idcntifying a valid heap that will be destroyed.
_FORCE forces destruction if allocated objects still exist This function collapses the cntire heap specificd by calling the release function specirled in _ucreate for every chunk of memory supplied by the user via _uaddmem, or via the exhausted callback function. Usage of the heap after _udestroy results in undcfinecl behaviour. If successful, (} is rcturned.
The operation of this routinc is illustrated in Figure 6. Thc _udestroy function call issued by the application tblock 6) acccpts a heap handlc that points to the heap internal structure. The heap internal structure sanity marks are checkcd within the reserved area (block 62) and an error reported if it is not a predetermined value 3 0 (block 63) .

Access to the heap is serialized hy locking a ~y~tem semaphore stored in the heap reserved area (block 64).

Next the linked list of user-inserted extensions of thc reserved heap area is scanned (block 65). Each of the extensions was inserted into the ]inked list following a call to the user s exhausted routine when an allocation request could not be satisfied with the contents of the heap at that time.

For each of these extensions within the linke(l list the user s release routine is called so they can properly return the memory extensions from wherever they obtained it (block 66). The call to the callback function returns the memory pointer originally provided as well as the size.

Access to the heap is deserialized by unlocking a system semaphore stored in theheap reserved area (block 67) and the semaphore specific to this heap is returned back to the operating system (block 68).

The remaining original chunk of memory suppliecl by the user during the _ucreate, containing heap control data is cleare<l to plevent furtller allocations from this heap (block 69).

Example The following example illustrates how the user heap routines are used to implement a separate allocation pool. In this example a user heap is crcated with the minimum startup sizc. The example lhen allocates an object of 1000 bytes using the _u~nalloc function which causcs thc user get_fn to be called since the heap is empty at this point. The get_fn iS called with a length of 1000 bytes plus some overhead which it modifies to 65536 since it is a much more practical increment to get from the operating system.

The get_fn callback routine rounds up the requested length to a multiple of the system page size and attempts to obtain a block of memory of this size directly from the operating system.

#define sys_page_size (4096*16) static void *get_fn(size_t *length, int *clean) void *p;

/* mark the block we are returning as clean */

*clean = _BLOCK_CLEAN;

*length = t*length / sys_page_size) * sys_page_size +

sys_page_size;

/* Make a system call to acquire memory */

p=GetMemFromSystem(*length);

return(p);

To collapse the heap, a call to _udestroy is made which would call the user's free_fn release function f(lr every chunk that was provided, and then clear the original starting chunk provided during heap creation.

The following free_fn callback routine will be called when the memory routines deem that a block of memory that was provided earlier is no longer needed and can be returned back to the operating system.

21361~4 static void free_fn(void *p, size_t sz) {

ReturnMemToSystem(p,sz);
return;
}
int main(void) ( Heap_t my_heap;
char starting_chunk [_HEAP_MIN_SIZE];
void *p;
/* create a user heap with the starting chunk being the minimum size */
my_heap = _ucreate(starting_chunk, _HEAP_MIN_SIZE, !_BLOCK_CLEAN, _HEAP_REGULAR, get fn, free_fn);
if (my_heap == NULL) puts(_ucreate failed);
p = _umalloc(my_heap,1000) if (p == NULL) puts(_umalloc failed);
free(p);
/* Now destroy the heap since it is no longer needed */
_udestroy(my_heap);
return(O);

In the above examples, GetMemFromSystem and ReturnMemToSystem indicate standard system calls to obtain and release memory.

For compiler and runtime library writers that wish to implement a multiple heap memory manager on top of a single heap implementation, the goal is to convert a single heap implementalioll into a multiple heap version that can process all memory types seamlessly. Therefore, the base memory allocator must be modified as follows:

- Create a heap structure to store all the global variables related to the memory routines. This information will be stored in the heap reserved area.

- Declare a heap structure internally to contain the following;

- Sanity value - Base memory allocator ;nformation - pointers to free list allocation lists temporary variables ancl semaphore structures - A function pointer to the exhausted routine - A function pointer to the release routine - A flag denoting thc type of memory it is handling. This is only necessary if the base memory allocator needs to process different types of memory differently. For example tiled memory is required in a segmented architecture to ensure a block of memory does not cross a segment boundary.
- A pointer to maintain a linked list of blocks of memory that the user s callback routine returned during an allocation request.

- Modify the routine that acquired memory from the operating system to usethe exhausted callback routine specific for the heap call.

- Modify the routine that returned memory to the operating system on heap destruction or termination to use the release callback routine specific for the heap call.

- If the environment supports threads then support should be added to synchronize code at the heap Icvcl rather than the function level. This will allow calls in separate threads to thc same heap to execute concurrently.
- Modify the base memory allocator to encode the heap handle used for the allocation within the returned object.

- Modify the free and realloc routines to determine the heap used for the object to be released and perform the necessary operation on that speci~lc heap only.

Define the following macros:
_BLOCK_CLEAN - Specify if inserted memory into the heap is all zeroes.
_HEAP_MIN_SIZE - Minimum memory size required to create a heap.
This value must be at least equal to the size of the heap structure previously declared in the runtime library.

A further aspect of the present invention is illustrated in the flow diagram of Figure 8. Multiple dynamic memory heaps give users flexibility in managing theirstorage use, and allow them to selectively allocate data in different types of memory. For example, an application may use one private heap of regular memory, and a second heap built with shared memory that is accessible to other applications and processes.

However, a severe problem with allocations occurs in vendor supplied object codeonly (OCO) libraries that were not constructed with multiple heaps in mind, since the user is not in a position lo make the source Ievel modifications necessary to use multiple heaps.

Accordingly, this aspect of the invention is directed to p roviding a mechanism whereby users can specify a heap to temporal ily replace the standard default heap defined in the runtime library. This specifie(l default heap will be used for all allocation requests that do not explicitly specify a heap, and allows for transparent migration from single to multiple heap strategies, particularly for using sharedmemory heaps in unmodified OCO libraries.

As illustrated in Figure 8, the application 8() first calls down to the runtime library 82 to set the default ~4 to the required heap (X8a, 88b or 88c).

The application 80 then calls the vendor library ~6, which in turn issues a malloc call that will use the default 84 set previously set by the application.

New routines are written with the old names of the allocation routines that determine which heap is considered the default and call the multiple heap version with it as an argument.

Functions Heap_t _udefault(Heap_t newHeap) This routine must be called within each thread that the default allocation routines are to be implicitly acquired from a private heap. Internally, all that is done is change an internal variable within the runtime library that denotes the current default heap to the value passed in by the user. The return value is the previous default heap prior to replacement.

void * malloc(size_t sz) This allocation routine will acquire storage size sz from the current active default heap. The active default heap is set previously within the application by the user making a _udefault call. If SUCIl call was not made then the default runtime heap that the library determine~ will he used.

void * calloc(size_t size, size_t qty) This function is similar to that of malloc except the memory area is cleared with the null byte on return.

213615~

void *realloc (void *p, size_t newsize) This function reallocates the object pointed to by the p parameter, such that it will have size newsize. The object is reallocated in the same heap, except if pointer p is null, it will be reallocated in the current default heap.

In a multithreaded environment, the default heap handle set by the _udefault call can be set on a per thread basis. and would be stored by the runtime library separately for each thread.

The invention can be used with user libraries that are built to use only one heap, by defining the secondary library function with reclefines the default shared memory heap prior to the calling of the secondary library function. Following the completion of the secondary library function, the default heap is redefined to the previous heap, and thus the secondary library function does not interfere with the operations performed with any other thread. An example of such function is below:

Heap_t oldHeap;

oldHeap = _udefault(sharedMemoryHeap);
LibraryFunction; /* call OC0 routine */
void _udefault(oldHeap); /* restore previous heap */

The library function and all functions it calls will use shared memory heap to satisfy all non-heap-specific all--cation requests in a way that it does not interfere with later operations performe(l in the current thread.

The foregoing invention has been described in association with specific embodiments. However, modifications to those skilled in the art are intended to be covered by the appended c]aims.

Claims (24)

1. A mechanism for user heap management during program execution in an operating system having means for allocating dynamic memory and runtime library means, the mechanism comprising control means for directing heap allocation requests, said control means being located in the memory supplied by an executing program and including heap control data defining heap type and semaphores for multithreading.
2. A mechanism according to Claim 1, wherein the control means comprises:
means for locating a block of heap memory of a suitable size for fulfilling the allocation request; and means for storing information in the block of heap memory defining parameters of the block of heap memory.
3. A mechanism, according to Claim 2, wherein the means for locating a block of heap memory having a minimum size comprises:
means for reviewing existing available heap memory for a block of at least the minimum size;
and means for initiating a system allocation of heap memory where no existing heap allocation block of at least the minimum size exists.
4. A mechanism according to Claim 2, further comprising means for deallocating an allocated block of heap memory.
5. A mechanism according to Claim 2, further comprising means for deallocating all allocated blocks of heap memory.
6. A mechanism according to Claim 1, wherein the control means comprise means for setting a default heap definition in the runtime library means.
7. A mechanism according to Claim 6, wherein the control means comprises means for setting a heap definition in the runtime library means for automatic heap allocation in response to an unspecified heap allocation request.
8. A process for creating at least one heap from a user application executing in an operating system having means for allocating heap memory and runtime library means, comprising the computer implemented steps of:
(i) issuing a function call from the user application of the runtime library means to create a heap of a size at least equal to a minimum size;
(ii) allocating a reserved area for said block of heap memory of at least the minimum size;
(iii) assigning a pointer to a function in said runtime library adapted to issue one or more calls for additional heap memory;
(iv) assigning a pointer to a function in said runtime library adapted to release heap memory; and (v) returning the heap to the user application.
9. A process according to Claim 8, wherein steps (i) to (v) are repeated for every thread in a multithreaded user application.
10. A process according to Claim 8 or 9, wherein steps (i) to (v) are repeated for each heap creation request issued by a plurality of user applications that are open concurrently.
11. A process for managing heap allocation from a user application executing in an operating system having means for allocating heap memory and runtime library means, comprising the computer implemented steps of:
(i) issuing a first function call from the user application of the runtime library means for a heap allocation of a size at least equal to a minimum size;
(ii) determining if a block of heap memory of at least the minimum size is available;

(iii) removing an object of a size equal to the size of the heap allocated, from the available heap memory; and (iv) returning the object to the user application.
12. A process according to Claim 11, whrein steps (i) to (iv) are repeated for every thread in a multithreaded user application.
13. A process according to Claim 11 or Claim 12, wherein steps (i) to (iv) are repeated for each heap allocation request issued by a plurality of user applications that are open concurrently.
14. A process according to Claim 11, further comprising the steps of:
invoking a callback function for heap memory expansion from the runtime library means to the user application on receiving a determination that no block of heap memory of at least the minimum size is available; and returning a block of memory from the user application to the runtime library means increasing the amount of heap memory available.
15. A process according to Claim 11, further comprising the step of issuing a second function call from the user application to the runtime library means for an increase in a heap allocation of at least a minimum size.
16. A process according to Claim 11, further comprising the step of issuing a second function call from the user application to the runtime library means identifying the callback function for heap memory expansion.
17. A process according to Claim 8, further comprising the step of inserting heap control data into a block of heap memory returned to the user application.
18. A process for managing heap allocation from a user application executing in an operating system having means for allocating heap memory and runtime library means, comprising the computer implemented steps of:
issuing a first call from the user application to the runtime library means specifying a heap to be destroyed;
serializing access to the heap;
scanning the heap memory for blocks of memory added to the heap by the user application for heap memory expansion;
invoking a callback function from the runtime library means to the user application for releasing each such scanned block of memory added to the heap;
deserializing access to the heap; and clearing the heap control data of the heap.
19. A process according to Claim 18, further comprising the step of issuing a second call from the user application to the runtime library means identifying the callback function for releasing blocks of memory added to the heap.
20. A process according to Claim 17, wherein the step of inserting heap control data into a block of heap memory returned to the user application comprises inserting a first value into an initial four bytes of the block defining size of the block and inserting a second value into a second four bytes of the block defining a heap handle.
21. A process for directing heap memory use from a user application executing in an operating system having runtime library means and at least secondary library means, comprising the computer implemented steps of;
i) issuing a first callback function from the user application to the runtime library means to define a default heap in the runtime library means;
ii) subsequently issuing a second callback function from the user application to the secondary library means for construction of a data object on the default heap;
and iii) subsequent issuing a heap allocation request from the secondary library means to the runtime library means for construction of the data object on the default heap.
22. A process according to Claim 21, wherein steps i) to iii) are repeated for every thread in a multithreaded user application.
23. A computer program product comprising a computer readable medium having computer program logic recorded thereon for controlling a processor in a computer operating system provided with means for allocating heap memory and runtime library means, said computer program product comprising:
control means for directing heap allocation requests, said control means being locatable in memory supplied by an executing program and including heap control data defining heap type and semaphores for multithreading.
24. A computer-readable memory tangibly embodying a program of instructions for use in the execution in a computer of any one of the methods of claims 8 to 22.
CA002136154A 1994-11-18 1994-11-18 User control of multiple memory heaps Expired - Fee Related CA2136154C (en)

Priority Applications (3)

Application Number Priority Date Filing Date Title
CA002136154A CA2136154C (en) 1994-11-18 1994-11-18 User control of multiple memory heaps
US08/559,904 US5809554A (en) 1994-11-18 1996-02-26 User control of multiple memory heaps
US09/088,747 US6816956B1 (en) 1994-11-18 1998-06-02 User control of multiple memory heaps

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CA002136154A CA2136154C (en) 1994-11-18 1994-11-18 User control of multiple memory heaps
US08/559,904 US5809554A (en) 1994-11-18 1996-02-26 User control of multiple memory heaps

Publications (2)

Publication Number Publication Date
CA2136154A1 CA2136154A1 (en) 1996-05-19
CA2136154C true CA2136154C (en) 1999-08-24

Family

ID=25677624

Family Applications (1)

Application Number Title Priority Date Filing Date
CA002136154A Expired - Fee Related CA2136154C (en) 1994-11-18 1994-11-18 User control of multiple memory heaps

Country Status (2)

Country Link
US (2) US5809554A (en)
CA (1) CA2136154C (en)

Families Citing this family (57)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6023712A (en) * 1997-07-30 2000-02-08 Quarterdeck Corporation Method and apparatus for brokering memory resources
WO1999015965A1 (en) * 1997-09-25 1999-04-01 British Telecommunications Public Limited Company Memory allocation
US6065019A (en) * 1997-10-20 2000-05-16 International Business Machines Corporation Method and apparatus for allocating and freeing storage utilizing multiple tiers of storage organization
JP4562910B2 (en) * 1998-03-23 2010-10-13 マイクロソフト コーポレーション Operating system application program interface
US6490670B1 (en) * 1998-04-24 2002-12-03 International Business Machines Corporation Method and apparatus for efficiently allocating objects in object oriented systems
US6510504B2 (en) * 1998-06-29 2003-01-21 Oracle Corporation Methods and apparatus for memory allocation for object instances in an object-oriented software environment
US6412053B2 (en) * 1998-08-26 2002-06-25 Compaq Computer Corporation System method and apparatus for providing linearly scalable dynamic memory management in a multiprocessing system
US6782537B1 (en) 1999-09-23 2004-08-24 International Business Machines Corporation Establishing a communicator across multiple processes in a multithreaded computing environment
US6629236B1 (en) * 1999-11-12 2003-09-30 International Business Machines Corporation Master-slave latch circuit for multithreaded processing
US6633405B1 (en) 1999-12-17 2003-10-14 Hewlett-Packard Development Company, L.P. Method and apparatus for interfacing generic and device-specific control codes
US6539464B1 (en) * 2000-04-08 2003-03-25 Radoslav Nenkov Getov Memory allocator for multithread environment
US6629227B1 (en) * 2000-05-04 2003-09-30 Scientific-Atlanta, Inc. System and method for a communication terminal to manage memory and maintain a current application version for multiple applications
US6711595B1 (en) * 2000-05-09 2004-03-23 Openwave Systems Inc. Method and apparatus for sharing standard template library objects among processes
EP1174791B1 (en) 2000-07-10 2017-09-27 Microsoft Technology Licensing, LLC Unified data type system and method
US20020016878A1 (en) * 2000-07-26 2002-02-07 Flores Jose L. Technique for guaranteeing the availability of per thread storage in a distributed computing environment
US6643753B2 (en) * 2000-10-04 2003-11-04 Microsoft Corporation Methods and systems for managing heap creation and allocation
US7111141B2 (en) * 2000-10-17 2006-09-19 Igt Dynamic NV-RAM
US6804763B1 (en) 2000-10-17 2004-10-12 Igt High performance battery backed ram interface
US8550922B2 (en) 2006-03-03 2013-10-08 Igt Game removal with game history
US7111294B2 (en) * 2001-01-16 2006-09-19 Microsoft Corporation Thread-specific heaps
US7334228B2 (en) * 2001-07-27 2008-02-19 International Business Machines Corporation Runtime-resource management
US6499094B1 (en) * 2001-09-14 2002-12-24 Unisys Corporation Management of memory heap space for data files accessible to programs operating in different addressing modes
CA2382718C (en) * 2002-04-12 2007-02-13 Ibm Canada Limited-Ibm Canada Limitee Memory balancing and optimization services
US7243342B2 (en) * 2002-06-11 2007-07-10 Intel Corporation Methods and apparatus for determining if a user-defined software function is a memory allocation function during compile-time
US7069396B2 (en) * 2002-06-27 2006-06-27 Hewlett-Packard Development Company, L.P. Deferred memory allocation for application threads
US7406699B2 (en) * 2003-04-02 2008-07-29 Microsoft Corporation Enhanced runtime hosting
CA2426619A1 (en) * 2003-04-25 2004-10-25 Ibm Canada Limited - Ibm Canada Limitee Defensive heap memory management
US7827375B2 (en) * 2003-04-30 2010-11-02 International Business Machines Corporation Defensive heap memory management
US7185167B2 (en) * 2003-06-06 2007-02-27 Microsoft Corporation Heap allocation
US7290110B2 (en) 2003-09-11 2007-10-30 International Business Machines Corporation System and method of squeezing memory slabs empty
US7434020B2 (en) * 2003-12-31 2008-10-07 Microsoft Corporation Overwrite detection diagnostic for memory heap
US7296139B1 (en) * 2004-01-30 2007-11-13 Nvidia Corporation In-memory table structure for virtual address translation system with translation units of variable range size
KR20050088853A (en) * 2004-03-03 2005-09-07 엘지전자 주식회사 A method and a apparatus of managing dynamic memory for mobile phone
US7284107B2 (en) * 2004-04-30 2007-10-16 Microsoft Corporation Special-use heaps
US7197619B2 (en) * 2004-06-09 2007-03-27 Sony Ericsson Mobile Communications Ab Methods, systems, and computer program products for managing a memory by storing external objects in a dynamic heap
JP4144609B2 (en) 2004-09-29 2008-09-03 ソニー株式会社 Information processing apparatus, memory area management method, and computer program
US7519867B2 (en) * 2004-12-21 2009-04-14 National Instruments Corporation Test executive which provides heap validity checking and memory leak detection for user code modules
US20060253503A1 (en) * 2005-05-05 2006-11-09 International Business Machines Corporation Method and apparatus for aging a versioned heap system
US7962707B2 (en) * 2005-07-06 2011-06-14 Honeywell International Inc. Apparatus and method for deterministic garbage collection of a heap memory
US8078636B2 (en) * 2005-08-24 2011-12-13 Temporal Dynamics, Inc. Database heap management system with variable page size and fixed instruction set address resolution
US20070088908A1 (en) * 2005-10-17 2007-04-19 Phison Electronics Corp. Method for arranging heap memory
US7552305B2 (en) * 2005-10-25 2009-06-23 International Business Machines Corporation Dynamic and real-time management of memory
US7827373B2 (en) * 2005-10-31 2010-11-02 Honeywell International Inc. System and method for managing a short-term heap memory
US7500077B2 (en) * 2005-12-09 2009-03-03 International Business Machines Corporation Use of region-oriented memory profiling to detect heap fragmentation and sparse memory utilization
US7951008B2 (en) * 2006-03-03 2011-05-31 Igt Non-volatile memory management technique implemented in a gaming machine
US7545382B1 (en) * 2006-03-29 2009-06-09 Nvidia Corporation Apparatus, system, and method for using page table entries in a graphics system to provide storage format information for address translation
US8181177B1 (en) * 2006-10-16 2012-05-15 Oracle America, Inc. Reducing the number of heap handles in a program
US20080148102A1 (en) * 2006-12-15 2008-06-19 International Business Machines Corporation Method for enhancing debugging of runtime memory access errors by using an integrated visualization tool and a runtime memory error detection tool
US8099577B2 (en) * 2007-03-20 2012-01-17 Oracle International Corporation Managing memory in a system that includes a shared memory area and a private memory area
US8996834B2 (en) * 2007-05-21 2015-03-31 International Business Machines Corporation Memory class based heap partitioning
US8566481B2 (en) * 2009-06-10 2013-10-22 Cisco Technology, Inc. Managing configuration data
JP2011003072A (en) * 2009-06-19 2011-01-06 Toshiba Corp Multi-core processor system
US8495107B2 (en) * 2011-06-23 2013-07-23 Oracle International Corporation System and method for use with garbage collected languages for enabling the allocated heap memory to be updated at runtime
US8918616B2 (en) 2011-08-24 2014-12-23 Microsoft Corporation Memory allocation analysis
US9141510B2 (en) 2011-08-24 2015-09-22 Microsoft Technology Licensing, Llc Memory allocation tracking
US9804962B2 (en) 2015-02-13 2017-10-31 Microsoft Technology Licensing, Llc Garbage collection control in managed code
KR20180052466A (en) * 2016-11-10 2018-05-18 (주) 글루시스 Imdb extracting method by using memory forensic

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CA2119788C (en) * 1992-07-24 1996-12-31 Peter L. Morse Computer method and system for allocating and freeing memory
US5437006A (en) * 1993-01-27 1995-07-25 Microsoft Corporation Spreadsheet command/function capability from a dynamic-link library
US5559980A (en) * 1993-03-18 1996-09-24 Lucent Technologies Inc. Method and apparatus for detecting references to deallocated memory in a dynamic memory allocation system

Also Published As

Publication number Publication date
US6816956B1 (en) 2004-11-09
CA2136154A1 (en) 1996-05-19
US5809554A (en) 1998-09-15

Similar Documents

Publication Publication Date Title
CA2136154C (en) User control of multiple memory heaps
US4775932A (en) Computer memory system with parallel garbage collection independent from an associated user processor
US6209066B1 (en) Method and apparatus for memory allocation in a multi-threaded virtual machine
US6970991B2 (en) Computer system with virtual memory and paging mechanism
US5218695A (en) File server system having high-speed write execution
US5822562A (en) Method and apparatus for expansion, contraction, and reapportionment of structured external storage structures
Liskov et al. Providing persistent objects in distributed systems
EP0881576B1 (en) Method and apparatus for generational garbage collection in a shared heap memory by means of multiple processor units
Flood et al. Parallel garbage collection for shared memory multiprocessors
EP0892347B1 (en) Parallel file system and method for independent metadata logging
US5946686A (en) Parallel file system and method with quota allocation
US5940838A (en) Parallel file system and method anticipating cache usage patterns
US6571259B1 (en) Preallocation of file system cache blocks in a data storage system
US5940841A (en) Parallel file system with extended file attributes
US6032216A (en) Parallel file system with method using tokens for locking modes
US5974424A (en) Parallel file system and method with a metadata node
US5950199A (en) Parallel file system and method for granting byte range tokens
US5893086A (en) Parallel file system and method with extensible hashing
US5956734A (en) Parallel file system with a quota check utility
US6023706A (en) Parallel file system and method for multiple node file access
US5963963A (en) Parallel file system and buffer management arbitration
US5987477A (en) Parallel file system and method for parallel write sharing
US6182089B1 (en) Method, system and computer program product for dynamically allocating large memory pages of different sizes
JPH1063568A (en) Method and system for allocating memory in multithread environment
US6681306B1 (en) Method and apparatus for increasing scavenging garbage collection effectiveness

Legal Events

Date Code Title Description
EEER Examination request
MKLA Lapsed