How do virtualization and virtual memory make a computer act “as if” something were the case?

In this blog post, we’ll examine how the familiar concept of “virtual” is implemented in computers and explore the principles behind virtual memory, a prime example of virtualization.

 

What is “virtualization” in the context of computers?

Have you ever heard the term “virtual couple” on a TV show? If not, you’ve probably heard the term “virtual account.” Even if you’ve never heard of either of these terms, there’s hardly anyone who hasn’t heard of “virtual reality.” Although the word “virtual” is commonly encountered in everyday life, people who aren’t particularly interested in computers may not be aware that the concept of “virtualization” is used within them. As everyone knows, “virtual” means treating something that isn’t real as if it were real. Since computers execute programs precisely on actual hardware, you might think this seems inconsistent with the concept of “virtual.” However, technology is widely used in computing that abstracts the actual structure of physical resources from users and programs, making it seem as though separate resources or environments are being used. Thanks to this virtualization and resource abstraction, it is possible to implement various functions, such as running multiple environments on a single physical computer or providing independent memory space for each program. So, what exactly is “virtualization” in computing, and where and how is it used?

 

How Does Virtualization Hide Physical Resources?

“Virtualization” is a broad term for technology that hides the characteristics of physical computer resources from other systems, programs, or users that utilize them, and provides those resources in the required form. In other words, it places an abstraction layer between the actual physical resources and the entities using them, allowing users to utilize the resources without needing to know their specific physical structure. In a virtual machine, a single physical computer resource can be used as if it were multiple independent environments, and each environment operates as if it had its own separate allocation of CPU, memory, storage, and other resources.
For example, imagine that A asked B to memorize a 300-page book and deliver it later. Since it would be difficult for B to memorize all 300 pages alone, B decided to divide the book among five friends, with each memorizing 50 pages, and then, when delivering it to A later, B would present it as if B had memorized all 300 pages. In this scenario, A would assume that B has memorized all 300 pages without knowing how many friends B actually has or which parts each friend memorized. Of course, this example does not perfectly explain computer virtualization, but it helps illustrate the basic concept of virtualization: presenting resources in the desired form to the user without revealing the physical configuration of those resources.

 

How Is Virtual Memory Created?

Quite a few people have likely seen the term “virtual memory” in their computer settings or received notifications related to “insufficient virtual memory.” As the name suggests, “virtual memory”—which includes the word “virtual”—is a representative resource abstraction technology that allows programs to use an independent address space without directly dealing with the structure of actual physical memory. Let’s explore the principle of virtualization through virtual memory.
Before learning about virtual memory, we must first understand what a process is. A process is an instance of a running program—that is, an execution unit of a program managed by the operating system for execution and resource management. Each process has its own independent virtual address space and, with the help of the operating system and hardware, runs as if it were provided with its own dedicated CPU and memory. In reality, multiple processes share one or more CPU cores, but because the operating system allocates CPU time in slices, each process can run as if it were using the CPU exclusively. This approach—where “resources are actually shared, but it appears as if each process is using them independently”—can also be viewed as an example of virtualization and resource abstraction. Here, we will take a closer look at a technology called “virtual memory,” which allows a process to use a single large main memory as if it were exclusively its own.

 

Why is virtual memory necessary?

When a program runs, it places its instructions and the data it uses into memory. Typically, we do not run just one or two programs at a time; instead, we use multiple programs simultaneously, and the operating system itself runs multiple processes. If a single process were to monopolize all of the physical main memory, other processes would be unable to use it. Therefore, instead of allowing each process to monopolize the entire physical memory, the operating system provides each process with its own independent virtual address space. Each process can run its program as if it were using its own memory, and the operating system manages this by mapping a portion of that virtual address space to the actual physical memory. The size of the virtual address space may exceed the amount of physical memory installed in the actual computer. However, even when virtual memory space is created, the data and instructions actually used within it must be physically stored somewhere. Furthermore, the total amount of memory used simultaneously by multiple processes may exceed the capacity of physical memory. Therefore, the operating system solves this problem by utilizing pages and storage devices: it loads only the necessary portions into physical memory and stores the rest on storage devices as needed.

 

How are pages mapped to physical memory?

First, each process is allocated a large virtual address space, which is divided into units of a fixed size called “pages.” Since only the pages currently needed for execution can be kept in physical memory, there is no need to store the entire vast virtual address space of each process in physical memory at once. Even so, since the total volume of pages used by multiple processes can far exceed the capacity of physical memory, the operating system divides the pages between physical memory and storage devices, retrieving the necessary pages as needed. This approach allows physical memory to be concentrated on the data currently in use.
When the CPU accesses instructions and data, virtual addresses are used, and the MMU (Memory Management Unit)—a hardware memory management device—converts these virtual addresses into actual physical addresses. The page table is used in this process; the MMU uses the page table to determine which physical memory region corresponds to a given virtual address. Hardware caches, such as the Translation Lookaside Buffer (TLB), are also used to quickly access recently used address translation information. However, if the required page is not currently present in physical memory, the MMU generates a page fault, which is then handled by the operating system’s memory management code. If the required page is located on a storage device, the operating system fetches that page into physical memory, updates the page table, and resumes execution from where it was interrupted.

 

How does virtual memory maintain performance?

Since actual storage devices are much slower than DRAM, which is used as main memory, wouldn’t this approach make the computer run significantly slower than when using only main memory? In fact, performance can drop significantly if page faults occur frequently. In particular, a considerable performance degradation can occur in situations where pages must be moved frequently between storage devices and physical memory. However, typical programs do not access memory regions completely at random; instead, they often follow certain patterns. This is due to a principle known as “locality.”
Locality includes “temporal locality,” which states that “an area recently used is likely to be used again within a short time,” and “spatial locality,” which states that “an area adjacent to a used area is likely to be used.” In other words, due to temporal locality, pages recently accessed are likely to be accessed again, and due to spatial locality, when a piece of data is accessed, the data surrounding it is also likely to be accessed next. Therefore, the operating system can utilize physical memory by focusing on pages that are immediately needed and frequently accessed, thereby reducing the number of accesses to storage devices. Of course, since a page fault can result in significant overhead due to access to storage devices, virtual memory does not always provide the same speed as physical memory. By leveraging these locality principles and memory management techniques, virtual memory provides a large virtual address space that transcends the limitations of physical memory while ensuring that programs can run efficiently. Furthermore, the use of virtual addresses prevents a specific process from arbitrarily accessing the private memory regions of other processes, and since access permissions can be set on a per-page basis, it is advantageous for memory protection. Another advantage is that multiple processes can share instructions and data that they have in common.

 

How far can virtualization be applied?

The principles of virtualization and resource abstraction are applied not only to virtual memory but also to numerous fields of computer engineering, including virtual machines, storage virtualization, and network virtualization. Cache memory is a separate hierarchical storage structure that places frequently used data in faster storage to improve access speed; RAID is a technology that configures multiple storage devices to function as a single logical storage resource; and a VPN is a technology that establishes a logical private network over a public network. Therefore, rather than referring to all of these as “virtualization” in the same sense, it is more appropriate to understand them from a broader perspective: abstracting or logically organizing physical resources to provide different forms of resources to users and programs. Virtual machines enable the execution of multiple independent computing environments on a single physical computer, and virtualization is also utilized as a foundational technology in cloud computing to efficiently partition and share physical resources.
The fact that we can now use high-performance computers at a relatively reasonable cost and run multiple programs simultaneously on a single computer is due to the integration of various computer system technologies. Among these, virtual memory plays a crucial role by providing each program with an independent address space and efficiently managing the limitations of physical memory. Additionally, processes can operate as if they were running independently while sharing the CPU, and cache memory enables fast access to frequently used data. Ultimately, throughout computer systems, we can find various abstraction and virtualization technologies that create a distinction between the actual structure and what the user perceives. If we were to describe virtualization in a single phrase, couldn’t we say it’s “as if ~”? As if a single process were using a single CPU, as if each process were using independent memory, as if a single physical computer were multiple computers. It is precisely this “as if” experience that is made possible by virtualization and resource abstraction in computer systems.

 

About the author

Cam Tien

I love things that are gentle and cute. I love dogs, cats, and flowers because they make me happy. I also enjoy eating and traveling to discover new things. Besides that, I like to lie back, take in the scenery, and relax to enjoy life.