What is Virtual Memory? (2024)

What is virtual memory?

Virtual memory is a memory management technique where secondary memory can be used as if it were a part of the main memory. Virtual memory is a common technique used in a computer's operating system (OS).

Virtual memory uses both hardware and software to enable a computer to compensate for physical memory shortages, temporarily transferring data from random access memory (RAM) to disk storage. Mapping chunks of memory to disk files enables a computer to treat secondary memory as though it were main memory.

Today, most personal computers (PCs) come with at least 8 GB (gigabytes) of RAM. But, sometimes, this is not enough to run several programs at one time. This is where virtual memory comes in. Virtual memory frees up RAM by swapping data that has not been used recently over to a storage device, such as a hard drive or solid-state drive (SSD).

Virtual memory is important for improving system performance, multitasking and using large programs. However, users should not overly rely on virtual memory, since it is considerably slower than RAM. If the OS has to swap data between virtual memory and RAM too often, the computer will begin to slow down -- this is called thrashing.

Virtual memory was developed at a time when physical memory -- also referenced as RAM -- was expensive. Computers have a finite amount of RAM, so memory will eventually run out when multiple programs run at the same time. A system using virtual memory uses a section of the hard drive to emulate RAM. With virtual memory, a system can load larger or multiple programs running at the same time, enabling each one to operate as if it has more space, without having to purchase more RAM.

How virtual memory works

Virtual memory uses both hardware and software to operate. When an application is in use, data from that program is stored in a physical address using RAM. A memory management unit (MMU) maps the address to RAM and automatically translates addresses. The MMU can, for example, map a logical address space to a corresponding physical address.

If, at any point, the RAM space is needed for something more urgent, data can be swapped out of RAM and into virtual memory. The computer's memory manager is in charge of keeping track of the shifts between physical and virtual memory. If that data is needed again, the computer's MMU will use a context switch to resume execution.

While copying virtual memory into physical memory, the OS divides memory with a fixed number of addresses into either pagefiles or swap files. Each page is stored on a disk, and when the page is needed, the OS copies it from the disk to main memory and translates the virtual addresses into real addresses.

However, the process of swapping virtual memory to physical is rather slow. This means using virtual memory generally causes a noticeable reduction in performance. Because of swapping, computers with more RAM are considered to have better performance.

Types of virtual memory

A computer's MMU manages virtual memory operations. In most computers, the MMU hardware is integrated into the central processing unit (CPU). The CPU also generates the virtual address space. In general, virtual memory is either paged or segmented.

Paging divides memory into sections or paging files. When a computer uses up its available RAM, pages not in use are transferred to the hard drive using a swap file. A swap file is a space set aside on the hard drive to be used as the virtual memory extension for the computer's RAM. When the swap file is needed, it is sent back to RAM using a process called page swapping. This system ensures the computer's OS and applications do not run out of real memory. The maximum size of the page file can be 1 ½ to four times the physical memory of the computer.

The virtual memory paging process uses page tables, which translate the virtual addresses that the OS and applications use into the physical addresses that the MMU uses. Entries in the page table indicate whether the page is in RAM. If the OS or a program does not find what it needs in RAM, then the MMU responds to the missing memory reference with a page fault exception to get the OS to move the page back to memory when it is needed. Once the page is in RAM, its virtual address appears in the page table.

Segmentation is also used to manage virtual memory. This approach divides virtual memory into segments of different lengths. Segments not in use in memory can be moved to virtual memory space on the hard drive. Segmented information or processes are tracked in a segment table, which shows if a segment is present in memory, whether it has been modified and what its physical address is. In addition, file systems in segmentation are only made up of segments that are mapped into a process's potential address space.

Segmentation and paging differ as a memory model in terms of how memory is divided; however, the processes can also be combined. In this case, memory gets divided into frames or pages. The segments take up multiple pages, and the virtual address includes both the segment number and the page number.

Other page replacement methods include first-in-first-out (FIFO), optimal algorithm and least recently used (LRU) page replacement. The FIFO method has memory select the replacement for a page that has been in the virtual address for the longest time. The optimal algorithm method selects page replacements based on which page is unlikely to be replaced after the longest amount of time; although difficult to implement, this leads to less page faults. The LRU page replacement method replaces the page that has not been used for the longest time in the main memory.

How to manage virtual memory

Managing virtual memory within an OS can be straightforward, as there are default settings that determine the amount of hard drive space to allocate for virtual memory. Those settings will work for most applications and processes, but there may be times when it is necessary to manually reset the amount of hard drive space allocated to virtual memory -- for example, with applications that depend on fast response times or when the computer has multiple hard disk drives (HDDs).

When manually resetting virtual memory, the minimum and maximum amount of hard drive space to be used for virtual memory must be specified. Allocating too little HDD space for virtual memory can result in a computer running out of RAM. If a system continually needs more virtual memory space, it may be wise to consider adding RAM. Common OSes may generally recommend users not increase virtual memory beyond 1 ½ times the amount of RAM.

Managing virtual memory differs by OS. For this reason, IT professionals should understand the basics when it comes to managing physical memory, virtual memory and virtual addresses.

RAM cells in SSDs also have a limited lifespan. RAM cells have a limited number of writes, so using them for virtual memory often reduces the lifespan of the drive.

What are the benefits of using virtual memory?

The advantages to using virtual memory include:

  • It can handle twice as many addresses as main memory.
  • It enables more applications to be used at once.
  • It frees applications from managing shared memory and saves users from having to add memory modules when RAM space runs out.
  • It has increased speed when only a segment of a program is needed for execution.
  • It has increased security because of memory isolation.
  • It enables multiple larger applications to run simultaneously.
  • Allocating memory is relatively inexpensive.
  • It does not need external fragmentation.
  • CPU use is effective for managing logical partition workloads.
  • Data can be moved automatically.
  • Pages in the original process can be shared during a fork system call operation that creates a copy of itself.

In addition to these benefits, in a virtualized computing environment, administrators can use virtual memory management techniques to allocate additional memory to a virtual machine (VM) that has run out of resources. Such virtualization management tactics can improve VM performance and management flexibility.

What is Virtual Memory? (1)

What are the limitations of using virtual memory?

Although the use of virtual memory has its benefits, it also comes with some tradeoffs worth considering, such as:

  • Applications run slower if they are running from virtual memory.
  • Data must be mapped between virtual and physical memory, which requires extra hardware support for address translations, slowing down a computer further.
  • The size of virtual storage is limited by the amount of secondary storage, as well as the addressing scheme with the computer system.
  • Thrashing can occur if there is not enough RAM, which will make the computer perform slower.
  • It may take time to switch between applications using virtual memory.
  • It lessens the amount of available hard drive space.

Virtual memory (virtual RAM) vs. physical memory (RAM)

When talking about the differences between virtual and physical memory, the biggest distinction commonly made is to speed. RAM is considerably faster than virtual memory. RAM, however, tends to be more expensive.

When a computer requires storage, RAM is the first used. Virtual memory, which is slower, is used only when the RAM is filled.

What is Virtual Memory? (2)

Users can actively add RAM to a computer by buying and installing more RAM chips. This is useful if they are experiencing slowdowns due to memory swaps happening too often. The amount of RAM depends on what is installed on a computer. Virtual memory, on the other hand, is limited by the size of the computer's hard drive. Virtual memory settings can often be controlled through the OS.

In addition, RAM uses swapping techniques, while virtual memory uses paging. While physical memory is limited to the size of the RAM chip, virtual memory is limited by the size of the hard disk. RAM also has direct access to the CPU, while virtual RAM does not.

The history of virtual memory

Before virtual memory was developed, computers had RAM and secondary memory. Early computers used magnetic core memory for main memory and magnetic drums for their secondary memory. Computer memory was expensive and, usually, in short supply back in the 1940s and 1950s. As computer programs grew in size and complexity, developers had to worry that their programs would use up all of a computer's main memory and run out of memory.

In those early days, programmers used a process called overlaying to run programs that were larger than available memory. Parts of a program that were not continually in use were set up as overlays that, when needed, would overwrite the existing overlay in memory. It required extensive programming to make overlaying work, and that was a key impetus for the development of automated virtual memory.

German physicist Fritz-Rudolf Güntsch has been credited with developing the concept of virtual memory in 1956 -- though this point has been contested. Güntsch did, however, end up describing a form of cache memory.

The first apparent real instance of a virtual memory system came from the University of Manchester in Manchester, England, in its attempt to develop a one-level storage system for the Atlas computer. The system used paging to map virtual addresses to a programmer onto the primary memory. Atlas was developed in 1959 and later commissioned in 1962.

In 1961, the first commercial computer with virtual memory was released by the Burroughs Corp. This version of virtual memory used segmentation, as opposed to paging.

In 1969, IBM researchers demonstrated that virtual memory overlay systems worked better than the earlier manual systems. Up until this point, there was still a debate over this. Mainframes and minicomputers in the 1970s generally used virtual memory. Virtual memory technology was not included in early PCs because developers thought running out of memory would not be a problem in those machines. That assumption proved incorrect. Intel introduced virtual memory in the protected mode of the 80286 processor in 1982, and paging support when the 80386 came out in 1985.

Learn what factors control and limit desktop memory. Also, learn the best ways to manage virtual memory on the Windows 10 OS.

What is Virtual Memory? (2024)

FAQs

What is virtual memory explain? ›

Virtual memory is a common technique used in a computer's operating system (OS). Virtual memory uses both hardware and software to enable a computer to compensate for physical memory shortages, temporarily transferring data from random access memory (RAM) to disk storage.

Is virtual memory the same as RAM? ›

Virtual memory and physical memory serve distinct roles in a computer system. Physical memory (RAM) is the actual hardware that provides temporary storage for active data, while virtual memory is a reserved space on the storage device (usually a hard drive or SSD) used when physical memory is exhausted.

How much virtual memory should I set for 16GB RAM? ›

However, with advancements in technology and more efficient operating systems, this rule is not as rigid as it once was. For a system with 16GB RAM, setting the virtual memory between 24GB to 32GB is a good starting point, but adjustments might be needed based on specific use cases.

How much virtual memory should I set for 8gb RAM? ›

As a rule of thumb, the paging file should be a minimum of 1.5 times the size of your installed RAM, and a maximum of 3 times your RAM size. For example, if you have 8 GB RAM, your minumum would be 1024 x 8 x 1.5 = 12,288 MB, and your maximum would be 1024 x 8 x 3 = 24,576 MB.

What are examples of virtual memory? ›

For example, suppose a program requires 5 GB of memory, but the computer system has only 4 GB of RAM installed. In this case, the virtual memory system will allocate additional memory needed by creating a larger virtual address space and mapping it to both the available RAM and the computer's secondary storage device.

What are the disadvantages of virtual memory? ›

Disadvantages of Virtual Memory

Thrashing is a phenomenon where a computer with little RAM always alternates between virtual and physical memory. Performance lags may result from the computer becoming slower as a result. A computer's available memory is usually decreased if it has little secondary storage.

What is faster RAM or virtual memory? ›

If your computer is running slowly due to a lack of RAM, you might be tempted to increase virtual memory because it is less expensive. However, adding RAM is a better solution because your processor can read data from RAM faster than from a hard drive.

Why is it better to use RAM than virtual memory? ›

Virtual memory runs slower than physical memory, so most computers prioritize using physical memory when possible. Moving data between a computer's virtual and physical memory requires more from the computer's hardware .

Why is RAM better than virtual memory? ›

Using virtual memory makes a computer run slower, as the processor has to wait while data is swapped between hard disk and RAM. As secondary storage devices have slower access times than RAM, the computer's processing performance can be severely impaired.

Does 32GB RAM need virtual memory? ›

Microsoft's recommendation: Microsoft suggests setting the virtual memory size at no less than 1.5 times and no more than 3 times the amount of RAM on the computer [1]. Following this recommendation, the virtual memory size for a system with 32GB RAM would be between 48GB and 96GB.

Is virtual memory necessary? ›

As a result, computers tend to consider secondary and primary memory as one. Virtual memory is crucial for multitasking. It enhances overall system performance as computers need not worry about memory constraints surrounding heavier programs.

What does increasing virtual memory do? ›

When virtual memory is increased, the empty space reserved for RAM overflow increases. Having enough available space is absolutely necessary for virtual memory and RAM to function properly. Virtual memory performance can be improved automatically by freeing up resources in the registry.

What should my virtual memory be set at? ›

You can change this to match the maximum size, or you can increase both beyond the maximum size. Microsoft recommends that you set virtual memory to be no less than 1.5 times and no more than 3 times the amount of RAM on your computer.

Should virtual memory be be on C or D? ›

Microsoft advice when setting virtual memory is to enable it on all drives, maybe set to Auto, and Windows will take care of rest. Windows knows speed of each drive and will use them as needed. Eg if C drive is busy it will switch to D drive, etc. For most users setting swap file to Auto is more than enough.

Can virtual memory increase performance? ›

) that increasing the Virtual Memory from Advanced System Settings on Windows 10 will improve the performance. I did some research about this, and I found it is to be true.

Where is the virtual memory? ›

There's a workaround to this problem: data stored in RAM that isn't actively being used can be temporarily moved to virtual memory, which is physically located on a hard drive or other storage device. This frees up space in RAM, which can then accommodate data the system needs to access immediately.

What is virtual memory quizlet? ›

Virtual memory (VM) VM is simulated memory that is implemented as a page file on a hard drive. Virtual memory is used by operating systems to simulate physical RAM using hard disk space. The process of moving data from RAM to disk (and back) is known as swapping or paging.

What is a virtual machine and explain it? ›

A virtual machine (VM) is a digital version of a physical computer. Virtual machine software can run programs and operating systems, store data, connect to networks, and do other computing functions, and requires maintenance such as updates and system monitoring.

How do I get virtual memory? ›

Procedure
  1. Access the System Properties settings. Go to Start > Run. Type sysdm.cpl and click OK. In the System Properties dialog box, click the Advanced tab. Under Performance, click Settings. In the Performance Options dialog box, click the Advanced tab.
  2. Adjust the virtual memory setting.
Oct 5, 2023

Top Articles
Latest Posts
Article information

Author: Foster Heidenreich CPA

Last Updated:

Views: 6575

Rating: 4.6 / 5 (76 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Foster Heidenreich CPA

Birthday: 1995-01-14

Address: 55021 Usha Garden, North Larisa, DE 19209

Phone: +6812240846623

Job: Corporate Healthcare Strategist

Hobby: Singing, Listening to music, Rafting, LARPing, Gardening, Quilting, Rappelling

Introduction: My name is Foster Heidenreich CPA, I am a delightful, quaint, glorious, quaint, faithful, enchanting, fine person who loves writing and wants to share my knowledge and understanding with you.