The present invention relates to memory performance in computer operating systems. In particular, but not by way of limitation, the present invention relates to organizing data placement in swap storage in computer operating systems.
In computer operating systems, active computer programs typically utilize volatile memory known as random access memory, or RAM. When a user uses many programs, or a particular program requires a high amount of RAM, various methods are utilized to free up more available RAM. One of these methods includes temporarily offloading data from RAM to an area in non-volatile storage that is typically known as “swap.” The particular data that gets offloaded to swap in non-volatile storage at any given time is usually data that is not actively needed by a running program at that particular time. When the data that is offloaded is needed again by a running program, the data is loaded from swap in non-volatile storage back into RAM.
Many operating systems use non-volatile storage media (including flash-based non-volatile storage media), which are also known as solid state drives. While flash storage provides many performance benefits over hard disk drive storage, these performance benefits are most useful when the flash storage is used for large, sequential accesses. However, some operating systems, such as Linux, use a Memory Management subsystem that tends to result in small, random accesses from swap to RAM, getting slow performance from the storage media. As a result, the methods used to access data from swap in Linux systems with flash storage can be slow and may become even slower over time. Therefore, a need exists for ways to optimize accesses from swap to RAM to improve overall performance.
An aspect of the present disclosure provides a method for using volatile and non-volatile computer memory. The method may comprise dividing at least a portion of the non-volatile computer memory into a plurality of bins, wherein each bin comprises a plurality of contiguous blocks of physical memory in the non-volatile memory. The method may further comprise assigning one or more processes to each of the plurality of bins, storing a process ID with metadata of a page belonging to the one or more processes, matching the page to one of the plurality of bins based on the process ID, and writing the page to a matched one of the plurality of bins.
Another aspect of the disclosure provides a computing device which may comprise volatile memory, non-volatile memory, and a hardware processor configured to execute a memory management subsystem that performs a method for utilizing the volatile memory and non-volatile memory. The method may comprise dividing at least a portion of the non-volatile computer memory into a plurality of bins, wherein each bin comprises a plurality of contiguous blocks of physical memory in the non-volatile memory. The method may further comprise assigning one or more processes to each of the plurality of bins, storing a process ID with metadata of a page belonging to the one or more processes, matching the page to one of the plurality of bins based on the process ID, and writing the page to a matched one of the plurality of bins.
Yet another aspect of the disclosure provides a non-transitory, tangible computer readable storage medium, encoded with processor readable instructions to perform a method for using volatile and non-volatile computer memory. The method may comprise dividing at least a portion of the non-volatile computer memory into a plurality of bins, wherein each bin comprises a plurality of contiguous blocks of physical memory in the non-volatile memory. The method may further comprise assigning one or more processes to each of the plurality of bins, storing a process ID with metadata of a page belonging to the one or more processes, matching the page to one of the plurality of bins based on the process ID, and writing the page to a matched one of the plurality of bins.
In kernels of operating systems such as Linux, memory management subsystems utilize virtual memory, which is a memory management technique known in the art that maps physical addresses in computer memory to virtual addresses. Virtual memory allows a particular process to operate as if its data were located in physical memory as one contiguous address space, even though the data may actually be located in non-contiguous physical address spaces. Virtual memory works in part by dividing up data from processes into same-size blocks known as pages, and by using a page table that maps virtual addresses to physical addresses. A common page size used for blocks of data in Linux and other operating systems is 4 KB, though other page sizes may be used without departing from the present disclosure. Since a page is comprised of data used for a process, the terms “page” and “data” may be used somewhat interchangeably throughout the disclosure.
When an operating system is running many processes, a computing device's RAM may run out of physical space to store process data. For example, if an operating system user opens many programs, or opens a few programs that run processes requiring a high amount of RAM, eventually, the RAM may become full. When the RAM becomes full, but space is still needed, a memory management subsystem may transfer certain pages from the RAM to temporarily store them in swap. It is more inefficient for a process to retrieve data from swap than to retrieve it from RAM, because of the properties of non-volatile memory that are commonly used (i.e., hard disk drives and flash storage). However, utilizing swap as a sort of “last resort” type of storage is better than not having needed data stored at all. The alternative to having data stored in swap would be to completely kill a process. Typically, a memory management subsystem implements an algorithm to determine which pages get transferred to swap, which involves determining which pages are least likely to be used again in the near future, or at all. Various methods may be used to determine which pages are least likely to be used, including lists and algorithms that detect how long a page has gone without being “touched.” The swapping algorithm used in Linux is known as the “Least Recently Used” (“LRU”) algorithm. Throughout this disclosure, a page may be referred to as being touched whenever it is actively used for process execution by a central processing unit (CPU), such as by being read from memory or written to memory.
The present disclosure provides a method for increasing the spatial locality of pages that belong to a process in swap through a process referred to herein as “binning.” At a high level, binning is a way to group data that belongs to the same process together in a swap disk. Ordinarily, the LRU algorithm or other similar swapping algorithms cause pages from the same process to be written to swap in non-sequential disk space. This occurs because the operating system algorithms manage memory based primarily on which pages have gone the longest without being used, and with little or no regard for what process the pages belong to.
Operating systems typically use several lists to manage processes and their pages that are allocated to memory. In Linux, for example, three types of lists are typically used. These include “file system cache data lists,” which include two subtypes known as “active file list” and “inactive file list.” Another type of list is known as “unevictable,” which contains allocated memory that cannot be moved to swap. The third type of lists are “anonymous” lists, which have two subtypes known as “active anonymous” and “inactive anonymous.” In Linux, the pages that may ultimately be moved to swap are managed using these two lists—Active Anonymous and Inactive Anonymous. These lists are called “anonymous” because the system does not necessarily know which process the pages belong to without referring to a page table. Aspects of a page table will be described throughout the disclosure. Though the present disclosure refers to the specifically named data structures called the “Active Anonymous list” and the “Inactive Anonymous list” which are their names in Linux, aspects of the disclosure may also apply to the operating systems, data structures, and/or lists that function similarly, even if they are known by other names in other operating systems. A list is one of several types of data structures used to physically allocate and organize memory.
Turning briefly to
In current approaches, such through the LRU algorithm, pages that have not been touched recently are placed on the Active Anonymous list 200. If the pages continue to not be touched, the pages get places on the Inactive Anonymous list 250. The pages 252-260 on the Inactive Anonymous list 250 represent pages that have not been touched recently enough to be on the Active Anonymous List 200 but have not yet been written to swap 280. As discussed previously, pages may be written to swap 280 if there is not enough room in RAM to store inactive pages. While pages are on the Inactive Anonymous List 250, they may still be placed back on the Active Anonymous list 200 if they are touched. The pages 252-260 on the Inactive Anonymous List 250 are depicted showing that the pages will be written to swap 280 in order from right to left (i.e., page 260, then 259, then 258, etc.). Though only one process 210 is depicted in
Turning now to
An aspect of the disclosure is that swap may be organized by the memory management subsystem into “bins” by the bin division component 522 of
A process may access RAM memory during its regular execution. If the page that the process is accessing is not available, the operating system will read this page from disk. Having to read a page from non-volatile storage is known as a “a page miss.” A page miss indicates that the page has been written to swap and needs to be retrieved from there. Because reads from swap can take a relatively long time, some memory management subsystems attempt to mitigate any latency by “reading ahead” for other pages that may be in swap and may be needed by the process. When the system reads ahead, it typically retrieves other pages from swap that are nearby in spatial locality to the requested page. However, as previously discussed, the implementation of the LRU algorithm often results in pages of different processes being written to swap next to each other. For example, referring briefly to
An aspect of the disclosure is that when a page is placed on a list in RAM (e.g., the Active Anonymous List), a process ID is created and stored with the page metadata in the page's page table entry by the process ID component 523 of
It is contemplated that at least some of the particular processes that get written to swap are known in advance, and that the amount of space required by these particular processes is also known. Therefore, sizes of bins in swap may be pre-determined and optimized for a particular target process. A commonly used page size is 4 KB, but entire processes are typically on the order of megabytes. Therefore, bins may be several megabytes in size.
In order to use the process ID to write a page to the intended bin, the memory management subsystem may create and utilize a hash function to identify a bin number. As previously noted, the process ID may be a very large numerical value, and as such, may need to be converted to a corresponding bin number which may be many orders of magnitude smaller. For example, a process ID may be 232, but there may be less than 100 bins. In order to convert the process ID to a bin number, an exemplary hash function could comprise multiplying the process ID by another numerical value (e.g., 256) and then dividing by the swap disk size. The resulting remainder of the division would then indicate the bin number in which the page should be written. The hash function described herein is just one example of a possible hash function. Any hash function may be used, though ideally a given hash function will result in highly accurate placement of the page in the correct bin. The memory management subsystem (in particular, the bin location component 525 of
As shown in
Referring next to
This display portion 712 generally operates to provide a presentation of content to a user. In several implementations, the display is realized by an LCD or OLED display. In general, the nonvolatile memory 720 functions to store (e.g., persistently store) data and executable code including code that is associated with the functional components described herein, in addition to other functions and aspects of the nonvolatile memory unique to the present disclosure. In some embodiments for example, the nonvolatile memory 720 includes bootloader code, modem software, operating system code, file system code, and code to facilitate the implementation of one or more portions of the memory management subsystem 720.
In many implementations, the nonvolatile memory 720 is realized by flash memory as described throughout the disclosure (e.g., NAND or ONENAND™ memory), but it is certainly contemplated that other memory types may be utilized as well, such as traditional hard disk drives. Although it may be possible to execute the code from the nonvolatile memory 720, (e.g., via the swap read/write functionality described herein) the executable code in the nonvolatile memory 720 is typically loaded into RAM 724 and executed by one or more of the N processing components in the processing portion 726. In many embodiments, the system memory may be implemented through the nonvolatile memory 720, the RAM 724, or some combination thereof.
The N processing components in connection with RAM 724 generally operate to execute the instructions stored in nonvolatile memory 720 to effectuate the functional components described herein. As one of ordinarily skill in the art will appreciate, the processing portion 726 may include a video processor, modem processor, DSP, and other processing components.
In conclusion, embodiments of the present invention improve user experience by reducing latency and/or power consumption associated with reads from and writes to swap. Those skilled in the art can readily recognize that numerous variations and substitutions may be made in the invention, its use and its configuration to achieve substantially the same results as achieved by the embodiments described herein. Accordingly, there is no intention to limit the invention to the disclosed exemplary forms. Many variations, modifications and alternative constructions fall within the scope and spirit of the disclosed invention.
This application claims priority to U.S. Provisional Application No. 62/296,882, filed Feb. 18, 2016 and entitled PROCESS DATA BINNING FOR MEMORY SWAPPING, which is incorporated herein by reference.
Number | Date | Country | |
---|---|---|---|
62296882 | Feb 2016 | US |