When multiple processes are executing on a computing device, the processes share the hardware resources of the computing device. Successful execution of all processes requires that no process use so much of any resource that other processes are unable to obtain enough of that resource to execute effectively. Among the hardware resources that can impact effective execution is memory of the computing device.
A computing device may have two types of memory, which can be termed “fast memory” and “slow memory.” Fast memory is termed “fast” because exchanging information between fast memory and a processor is relatively quick as compared to exchanging information between slow memory and a processor. Fast memory includes memory that is directly accessible by a processor (e.g., a central processing unit (CPU) or a graphics processing unit (GPU)). Fast memory of a device may include “internal memory” and can be implemented as random access memory (RAM). Slow memory includes memory that is not directly accessible by a processor, but is instead installed in a computing device remote from a processor. Slow memory of a device may include secondary storage and can be implemented as one or more storage drives. Examples of storage drives include hard disk drives and solid-state drives (SSDs).
Computing devices typically include a memory manager that determines how processes will use memory. A process may request from the memory manager one or more blocks of memory space and the memory manager may allocate to each executing process memory space consisting of a range of memory addresses for that process to use. Once the memory space is allocated, the process can write data to and read data from memory using addresses in its assigned range of addresses. When the process finishes using the memory, the process can again interact with the memory manager to request that the memory space be de-allocated or “freed” so that the memory space is available for use by another process.
Because of the speed advantage of fast memory, when processes are interacting with content stored in memory, the content is placed in fast memory. However, the total amount of memory requested by all processes executing on a computing device may be greater than the amount of fast memory available on the computing device. To counter this problem, it is known for memory managers to us a technique called “paging.” Using paging, content that a process has requested be stored can be temporarily stored in slow memory.
In paging, the ranges of memory addresses assigned to processes may be divided into pages. When a process reads or writes content to memory, the “page” containing that content is loaded in the fast memory. Though, when the page is not actively being accessed by a process, the memory manager may keep the content from the page in a page file in slow memory. A memory manager, for example, may move a page used by a process out of fast memory and store the page in the page file in slow memory, to allow space in the fast memory to be made available for storing other content (and other pages) that are actively being accessed by other processes. When a process needs to use content that has been placed into slow memory, the memory manager can retrieve the page containing the content from the page file in the slow memory and place the page and the content back in fast memory.
As mentioned above, a memory manager will allocate memory space containing a range of addresses of memory to a process upon receiving from the process a request for memory. The range of addresses provided to the process are not hardware addresses of fast memory. This is because, when paging is used, the exact location at which content can be accessed in fast memory is not known at the time the memory space and the range of addresses is allocated. Instead, memory space in “virtual memory” is allocated to a process in response to a request for memory, and “virtual addresses” are provided to the process. The total amount of virtual memory available on a computing device is the sum of the size of fast memory and the maximum permitted size of the page file in slow memory.
Virtual memory addresses are known to the memory manager and can be used by the memory manager to identify the actual locations in memory at which content is stored. A virtual memory address may correspond to an address of fast memory or to a location in the page file in slow memory. When a request to access a particular virtual memory address is received by the memory manager, the memory manager may review records regarding the virtual memory to determine an actual storage location corresponding to the virtual memory address. When the virtual memory address corresponds to a location in the page file in slow memory, the memory manager may retrieve the page containing the virtual memory address from the slow memory and write the page to fast memory. This may include removing another page from the fast memory to make space in fast memory for the page to be written and placing that other page in the page file of slow memory, then updating the actual storage locations of both in records regarding the virtual memory addresses.
Accordingly, a process may interact with a memory manager to perform various functions regarding the memory. A process may first request an allocation of memory, in which case the memory manager may “allocate” to the process an amount of memory space in virtual memory. When the process is interacting with content stored in memory space, the memory manager may ensure that the content is stored in fast memory, and the memory manager may place the content in the page file in slow memory when the process is not interacting with the content. The process may also request that the memory manager “de-allocate” memory space in virtual memory that was previously allocated if the process will not use the contents of that memory space again. If the process later requires additional memory to store newly generated content, the process can request another allocation of memory space in virtual memory.
Interactions with the memory manager, particularly the memory manager's allocation and de-allocation operations, can take a relatively long time for a process and therefore can slow down execution of a process. Because of this, when software designers write the code that defines the processes, the developers may try to reduce the number of allocation and de-allocation operations that are performed by the processes. The software designers may instead use memory “reset” operations in their code when memory space allocated to that process contains content that is not to be further used by the process. Upon receiving an instruction to “reset” specified memory space, if pages for that memory space are stored in the fast memory, the memory manager stops preserving the content of the memory space in the fast memory, such as by not writing content of the memory space into the page file when a page in fast memory is to be replaced with another page. No de-allocation of memory space is performed in response to a “reset.” Though there is no content (and possibly no pages) corresponding to the memory space following a reset of that memory, that memory space of virtual memory continues to be allocated to the process. By retaining the allocation, the memory space will already be available to the process when the process needs memory for some purpose in the future, without the need for a subsequent allocation operation. In this way, the process can avoid lengthy allocation and de-allocation operations. Also, because the content of the reset memory space is not occupying valuable space in the fast memory that can be used by other pages storing content for other memory space, the memory manager is not wasting time or resources managing that content using paging techniques.