Virtual memory, a memory management technique, lets an overtaxed operating system (OS) create a synthetic form of memory that allows it to operate beyond its memory limitations.
Essentially, when too many computer programs exhaust memory, virtual memory enables the OS to repurpose random access memory (RAM) for hard disk drive use.
A quick financial analogy aptly describes the situation: Think of the physical memory in your computer as the money in your personal checking account. All is well and everything functions fine until you exhaust your funds. Once you hit rock bottom, your bank (which offers overdraft protection on checking accounts) issues an overdraft (virtual memory) that temporarily covers account expenses.
Such an overdraft contains obvious limits. First, a financial cap controls the size of the expenses the bank will support. Plus, a time limit governs how long your financial institution will allow the situation to continue without an influx of emergency capital into your account.
Virtual memory is an essential component of computer systems and enables smoother general operation, but it’s crucial to note that it’s not a sustainable permanent solution. It’s intended to provide an emergency amount of memory. More like a quick fix that kind of gets the job done—but only for the moment.
Virtual memory is a modern creation of computing; at its core, it simply updates the ancient concept of “borrowing from Peter to pay Paul,” in which resources get shifted from one source to another.
Stay up to date on the most important—and intriguing—industry trends on AI, automation, data and beyond with the Think newsletter. See the IBM Privacy Statement.
A central processing unit (CPU) is the primary functional component of a computer, and it uses different forms of memory. RAM is a faster and more quickly accessed form of memory usage, but not unlimited in size. The CPU’s hard disk drive, alternatively, offers plenty of disk storage space, but at slower access times.
Real memory is installed on the CPU. Real memory refers to the RAM hardware where data is temporarily retained for immediate and active use. (Programmers also refer to real memory as physical memory or main memory.) In contrast, secondary memory is considered non-volatile, meaning such storage devices retain storage capabilities even when the machine is turned off and disconnected from its power source. That differs from RAM, as do several other performance variables.
Were the two types reconstituted as automobiles, RAM would be like a flashy little sports car: speedy, costly and with barely enough room for a driver and a passenger (small capacity). Secondary memory is slower and cheaper, like an economical minivan, with considerably more capacity than primary memory offers.
The hard drive, also called the hard disk drive (HDD), functions as a combined storage unit and player, while the hard disk itself is the physical platter inside the HDD and where magnetic data is encoded.
In most cases, HDD use has been replaced by the solid state drive (SSD). The SSD carries out the same functions but uses flash memory in the form of non-volatile memory chips that don’t require the use of moving parts. SSDs compare favorably to HDDs by virtue of their robust speed, slimmer physical profile and reduced power consumption.
Virtual memory operates by temporarily converting RAM that had been used previously but has since remained dormant and unused for some time. The OS extracts the data from that barely used RAM and places it into a swap file (or page file) on the hard disk drive.
The OS then puts the newly cleaned RAM into immediate service. The additional memory “borrowed” from that RAM helps run the computer user’s multiple programs without any system performance glitches or perceived slowdowns in operating speed.
Regarding data, pages serve as the coin of the realm and function like the basic medium of exchange. In terms of virtual memory management, the modules it enlists are pages, the smallest unit of data. Pages are contiguous (adjoined) blocks of virtual address space.
Pages come in one fixed size, generally. Originally, pages weighed in uniformly at 4 KB and this size has traditionally been the industry standard. Lately, more modern systems are employing a considerably larger fixed size, including sizes up to 2 MB or 1 GB or even larger.
In virtual memory, most pages are either 4 KB or 8 KB, depending on the architecture followed. Microsoft Windows, Linux and Apple’s macOS are all built around a 4-KB page size. UNIX virtual memory page size is structured according to each system’s particular hardware architecture as either a 32-bit or 64-bit system. (UNIX systems usually devote 3 GB to 4 GB to each executed process.)
Within a particular OS, all pages will usually conform to one page size. The exception to this rule involves dynamic partitioning, which serves up memory in various sizes, based on particular demand. Having pages identically sized makes it easier for an OS to successfully manage them all in concert.
Also, due to their matching size, it’s easier for the OS to prevent external fragmentation, which takes place when pockets of unused memory take root between allocated memory blocks. The result: too little available memory to allocate in a single, useful chunk.
By using pages, an OS can map out the logical memory of a process, essentially translating it for non-contiguous physical memory in the form of page frames. Page frames are blocks of physical memory (RAM) that an OS uses as a type of container for memory pages. The size of the page frame matches that of the page itself, be that 4 KB or some greater size.
A CPU creates virtual memory addresses, which act as a memory location reference that will be used by the software processes running on that OS. Programmers employ page tables to track and manage page frames and to serve as the primary data structure. A page table entry is used to link a virtual address to a physical address within the OS.
A virtual page number (VPN) uses the first 20 bits of a virtual address to serve as an identifier for the virtual address space within that computer process’s virtual memory space. The page number identifies the page so the memory management unit (MMU) can retrieve it from a physical memory frame or from disk.
Meanwhile, the remaining part of the address serves as the page offset, which specifies the exact physical location of that page within the OS, right down to the locations of individual bytes.
In a perfect world, a computer’s RAM would prove sufficient for running programs. However, modern computing lends itself superbly to multitasking and operating multiple programs concurrently, which can easily confound the memory allocation process. This heightened demand routinely puts excessive demands on the available memory of the OS.
When available disk space is fully exhausted, virtual memory steps in to keep your programs running. However, this operating extension usually comes at a significant cost: operating speed. Virtual memory operates at a slower clip than physical RAM (because storage drives take longer to access). Thus, the more virtual memory an OS drains, the more likely that an operator is going to experience a drop in performance.
This form of performance slowdown is called “thrashing.” Thrashing is also used to refer to a prolonged and dysfunctional state of operation in which an OS devotes most of its processing ability to shuffling data in and out of memory instead of executing code.
Another type of phenomenon that regularly occurs is known as a “page fault.” Page faults take place when a functioning program tries to grab a data page that isn’t mapped in its physical RAM at that time.
This spurs a hardware interruption, while the page fault handler in the OS kernel is activated. The OS kernel accesses the necessary data from a secondary storage source. Then, the OS updates the page table that tracks all virtual addresses and their corresponding physical addresses before returning to normal program operation.
Several forms of page faults exist, each classified based on its perceived severity:
One way an OS streamlines processing is through demand paging. This technique foregoes front-loading an entire program, and instead, the OS loads only those pages needed at any particular moment.
On the upside, the system can run more programs this way. The downside can mean a high incidence of page faults (possibly leading to thrashing) caused by constantly interrupting program operation to retrieve pages from storage.
Various algorithm-based methodologies are used in conjunction with demand paging. Each of these page replacement algorithms addresses the problem with a distinct spin:
Unlock faster, more resilient operations by unifying storage, protection, and orchestration for AI, VM, and container workloads.
Optimize and scale workloads across virtual and physical environments with efficient, flexible virtualization.
Comprehensive technical expertise for your IBM Systems servers and storage.