Abstract:
A system for dynamically allocating memory to a file buffer cache manager and a virtual memory space manager is provided. The file buffer cache memory is time stamped at times of acquisition and access, and the acquired virtual memory space memory is time stamped at times of acquisition and access. If the file buffer cache manager or the virtual memory address manager requests memory, the time stamps of the memories acquired by the file buffer cache manager and the virtual memory space manager are compared. The piece of memory which has the earlier time stamp is preempted and allocated to the manager which has requested memory.

Description:
TECHNICAL FIELD OF THE INVENTION 
     This invention relates in general to the field of computer systems. More particularly, the present invention relates to dynamic memory allocation for a file buffer cache. 
     BACKGROUND OF THE INVENTION 
     In a computer system which utilizes a file system buffer cache (FBC) scheme, it is often difficult to determine how much main memory to allocate between the buffer cache and the virtual address space used by user applications. The allocation is typically performed at system boot time, at which instance a specified amount of memory is allocated to the FBC and the remaining memory is allocated as virtual address space. The amount of memory required by the FBC and user processes is therefore very load dependent and application specific, which can vary greatly. Such demand variations can even fluctuate by the hour. Therefore, static memory allocation have at least two problems. First, it is difficult to arrive at a good estimate of the demand for memory for the initial allocation. Second, once the memory space is allocated, the allocation may result in memory not being used efficiently because of over-allocation, or improper operation because of under-allocation. 
     In recognition of this problem, one solution has been formulated. This solution allows the mapping of FBC onto the virtual address space, so that in effect both the FBC and the user processes satisfy memory requirements by acquiring memory space from the same pool. Although effectively resolving the problems associated with static memory allocation, the implementation of such a scheme involves a substantial reprogramming of the FBC and virtual memory (VM) management software modules. In addition, it is possible for either FBC or user processes to dominate by acquiring a major portion of available memory space. In constant contention for available memory space, either FBC or user processes may lose when there is a heavy demand by the other. 
     Therefore, it is desirable to provide for a memory allocation scheme which allows FBC and user processes to request memory and allocate it accordingly in a dynamic fashion. Furthermore, it is desirable to achieve dynamic memory allocation without major revision and modification of current FBC and VM management software. 
     In addition, in a multiprocessor system, though the management of FBC and VM does not cross processor boundaries, access to memory may. This multiprocessor environment poses special challenges in implementing a dynamic memory allocation system. Thus, it is desirable to achieve dynamic memory allocation that functions in a multiprocessor environment. 
     SUMMARY OF THE INVENTION 
     In accordance with the present invention, a dynamic file buffer cache is provided which substantially eliminates or reduces disadvantages and problems associated with prior buffer cache systems. 
     In one aspect of the present invention, a system for dynamically allocating memory to a file buffer cache and a virtual memory space is provided. The system comprises means for time stamping the acquired file buffer cache memory at times of acquisition and access, and means for time stamping each of the acquired virtual memory space memory at times of acquisition and access. If one manager requests memory, the time stamps of the memories acquired by the file buffer cache management means and the virtual memory space management means are compared. The piece of memory which has the earlier time stamp is preempted and allocated to the manager which has requested memory. 
     In another aspect of the present invention, a method for dynamically allocating a predetermined amount of memory between a first and a second competing resource is described. The steps comprise allocating memory for the first resource, and time stamping the memory allocated to the first resource. The memory allocated to the second resource is also time stamped. Thereafter, in the event of a memory request by the first or second resource, the time stamps of the least recently used memories allocated thereto are compared. The memory having the older time stamp is preempted. 
     An important technical advantage of the present invention provides a simple yet elegant way of altering a static file buffer cache to a dynamic one that responds to system load conditions. 
     Another important technical advantage of the present invention provides a solution to the under- or over-allocation problem involved in file buffer cache systems. 
    
    
     BRIEF DESCRIPTION OF THE DRAWINGS 
     For a better understanding of the present invention, reference may be made to the accompanying drawings, in which: 
     FIG. 1 is a top level diagram of the preferred embodiment of the present invention; 
     FIG. 2 is a hybrid flowchart illustrating the logic of the preferred embodiment of the present invention; and 
     FIG. 3 is a diagram showing the preferred data structure of the present invention. 
    
    
     DETAILED DESCRIPTION OF THE INVENTION 
     With reference to the drawings, FIG. 1 illustrates a preferred embodiment of the dynamic file buffer cache, indicated generally at 10 and constructed according to the teaching of the present invention. In a computer (not shown) utilizing a file buffer cache, its operations are typically managed by a file buffer cache (FBC) manager 12. FBC manager 12 oversees what portions of the disk file system are being cached, flushing cache buffers to accommodate more recently used file system data, etc. Therefore, FBC manager 12 has under its control some memory which is being used to cache the file system data 14, and some memory which is free 16. Free memory may be unused memory or memory which holds very outdated data. A virtual memory (VM) manager 18 generally manages the allocation and use of the virtual address space of the computer. VM manager 18 may also have some memory which is in use 20, and some which is not 22. 
     In a computer which allocates memory to the file buffer cache statically, a fixed amount of memory is assigned to the buffer cache at system boot time. The remaining memory which was not allotted to the buffer cache then becomes the VM manager&#39;s domain. Therefore, in such a static allocation system, the size of memory under the control of FBC manager 12 or VM manager 18 does not vary and is not adaptable to system load conditions. Therefore, either memory is wasted because of over-allocation, or in the case of FBC manager 12, buffers are preempted prematurely to accommodate more recently used file data. 
     On the other hand, FBC manager 12 and VM manager 18 in the present invention do not preempt memory under its own control until it first issues a request to the other manager. A comparison is made to determine which manager 12 or 18 has in its possession free memory or memory with less recently used data. The control of that piece of memory is then passed to the other manager if the comparison indicates that the other manager&#39;s memory should be preempted. The communication between VM manager 18 and FBC manager 12 is shown as path 24. 
     Referring to FIG. 2 for an exemplary communication session between VM manager 18 and FBC manager 12. As shown in block 30, VM manager 18 receives a request for memory from user processes and the like (not shown). VM manager 18, upon receiving the request, examines the memory under its control to determine whether it holds any free memory 22, as shown in block 32. If it has free memory in its possession, it allocates it to the requesting user process, as shown in block 34, and execution terminates in block 36. If VM manager 18 does not own any free memory, it obtains a time stamp of its least recently used (LRU) memory (block 38) and communicates this information along with a memory request to FBC manager 12, as shown in path 40. 
     In block 42, FBC manager 12 receives the communication from VM manager 18. FBC manager 12 obtains a time stamp of its own LRU memory, as shown in block 44. It then compares the time stamp provided by VM manager 18 and its own LRU time stamp, as shown in block 46. If the time stamp of VM manager&#39;s 18 LRU memory is substantially earlier or older than FBC manager&#39;s 12 LRU memory time stamp, then VM manager&#39;s 18 request is denied. This is communicated to VM manager 18 via path 48. Otherwise, in block 54 FBC manager 12 preempts its own LRU memory so that it may be passed to VM manager 18. VM manager 18&#39;s request is granted and control of the preempted memory is passed to VM manager 18, as shown in path 56. FBC manager&#39;s execution subsequently terminates in block 58. In block 60, VM manager 18, upon receipt of FBC manager&#39;s 12 communication, obtains control of the preempted memory, and allocates it for use. Execution terminates in block 62. 
     Note that the comparison of the time stamps must be such that the difference therebetween must be great enough to justify the passing of memory to VM manager 18 rather than preempting its own memory. Additionally, the identities of VM manager 18 and FBC manager 12 may be switched in FIG. 2. In other words, FBC manager 12 may issue a request for memory to VM manager 18, causing VM manager 18 to preempt a piece of memory under its control because it carries an older time stamp than FBC manager&#39;s 12 LRU memory. 
     In the simplest scenario, both VM manager 18 and FBC manager 12 manipulate memory under their control in the same unit. However, a more complex scenario arises when VM manager 18 operates with memory chunks of size X and FBC manager 12 operates with memory chunks of size Y, where X does not equal Y. In such systems, the passing of memory ownership between managers 12 and 18 must be so coordinated that no fraction of memory sizes occur. For example, if the cache buffer size is in 1K-byte blocks and the virtual memory are in 4K-byte pages, the memory passed between them should be 4K bytes. There are a number of ways to accomplish this. 
     One method may be used where FBC manager 12 identifies the most inactive or LRU buffer, and forcibly preempts the other three buffers in the same page when the time stamp of the LRU buffer is substantially older than VM manager&#39;s 18 LRU memory. However, this method may cause premature preemption of still active buffers. 
     Another method involves requiring FBC manager 12 to identify the four most inactive buffers, say one in page W, two in page Z, and another in page Q. The data in the active buffers of each page are then shuffled to other pages in order to preempt a page of memory. For example, since page Z contains two LRU buffers, only two buffers of data are needed to be copied to pages W and Q to yield one preempted page Z. It may be seen that although this method evaluates each buffer on a LRU basis and thus would not preempt a buffer prematurely, this method is complex and may require more data manipulation than is saved by passing memory ownership. 
     The preferred method of resolving the memory size inconsistency problem is to assign a time stamp only to groups of memory, the size of which equals the size of memory to be passed between VM manager 18 and FBC manager 12. For example, a time stamp is assigned to four cache buffers which consist of one page of memory. Implemented in this manner, the time stamp for a page of cache buffer memory represents the status of the most recently used buffer. All other buffers within the same page are less active than the most recently used buffer. 
     Referring to FIG. 3 for a diagram of a preferred embodiment of data structures used to implement and resolve the memory size inconsistency problem as described above. The data structure preferably consist of two stacks: one page-oriented stack 70 and one buffer-oriented stack 72. Page-oriented stack 70 maintains an ordering of the pages 74-78 under the control of FBC manager 12, where page 74 at the top of stack 70 is the most active page, and page 78 at the bottom of stack 70 is the least active page. Similarly, buffer-oriented stack 72 maintains an ordering of buffers 80-87, where buffer 80 at the top of stack 72 is the most active buffer and buffer 87 at the bottom of stack 72 is the least active buffer. If the size of a page under VM manager 18 control is equal to the size of four buffers combined, then each page 74-78 in stack 70 in effect is composed of four buffers occupying contiguous memory in stack 72. Therefore, each page 74-78 possesses a pointer 90-94 pointing to the first buffer in the contiguous block of memory which comprises the page. 
     As a buffer is accessed, its timestamp is set to the current time or the time of access, and moved to the top of stack 72. Concurrently, the corresponding page is also assigned the same timestamp and also moved to the top of stack 70. In this manner, if a comparison of time stamps results in a preemption of a group of four buffers, no data is prematurely erased because the pages are ordered and preempted according to the most active or most recently used buffer timestamp in the group. 
     In the multiprocessor environment, each processor possess main memory and a VM manager and a FBC manager. The ownership of memory may shift between the FBC manager and VM manager in each processor, but no sharing of memory is permitted between processors. The data structure described above is preferably replicated for each processor to implement dynamic memory allocation. However, processors may have access to buffer cache and virtual address space of other processors. This may be accomplished by including a processor identification code, for example, in each buffer 80-87 and page 74-78 to identify the processor and the correct data structure each belongs. 
     Although the present invention has been described in detail, it should be understood that various changes, substitutions and alterations can be made thereto without departing from the spirit and scope of the present invention as defined by the appended claims.