Virtual memory is an area of storage space for a computer system’s secondary memory (such as a hard disk or solid state drive) that acts as part of the system’s RAM or primary memory.
Ideally, the data needed to run applications is stored in RAM, where they can be quickly accessed by the CPU. But when large applications are running or when several applications are running simultaneously, the system’s RAM may become full.
To resolve this issue, some data stored in RAM that is not actively used may be temporarily moved to virtual memory (which is physically located on a hard disk or other storage device). This frees up space in RAM, which can then be used to host data that the system needs to access imminently.
By switching data between RAM and virtual memory when not needed and returning from virtual memory to RAM when needed, a system can continue to run smoothly with much less physical RAM than would otherwise be required.
Virtual memory allows a system to run larger applications or run multiple applications at the same time without running out of RAM. Specifically, the system can function as if the total RAM resources were equal to the amount of physical RAM plus the amount of virtual RAM.
Why is virtual memory needed?
Virtual memory was developed when physical RAM was very expensive, and RAM is still more expensive on Gigabyte than storage media such as hard disks and SSDs. For this reason, it is much less expensive to use a combination of physical RAM and virtual memory than to equip a computer system with more RAM.
Because using virtual memory (or increasing virtual memory) has no additional financial cost (because it uses existing storage space), it provides a way to use more computer memory than is physically available on the system.
Virtual memory vs. physical memory
Because RAM is more expensive than virtual memory, it would seem – all things being equal – that computers should be equipped with as little RAM as possible and as much virtual memory as possible.
So a system with 2 GB of physical memory and 2 GB of virtual memory will not provide the same performance as a similar system with 4 GB of physical memory. To understand why, we need to understand how virtual memory works.
How does virtual memory work?
When an application (including the operating system) is running, it stores the location of program threads and other data to a virtual address, while the data is actually stored to a physical address in RAM. If later that RAM space is needed more urgently by another process, then the data can be changed from RAM and virtual memory.
The responsibility for tracking all this data as it is changed between physical and virtual memory lies with the computer’s memory manager. The memory manager maintains a table that maps the virtual addresses used by the operating system and applications to the physical addresses where the data is stored. When data is exchanged between RAM and virtual memory, the table is updated so that a specific virtual address is always indicated at the correct physical location.
A computer can only run wires and handle data stored in RAM, rather than virtual memory. And it takes a not inconsiderable amount to change the necessary data in RAM. Consequently, it turns out that the use of virtual memory implies a successful performance.
In other words, a system with 4 GB of RAM will generally perform better than a system with 2 GB of RAM and 2 GB of virtual memory due to the performance affected by swapping, and for this reason it is said that virtual memory is more slower than RAM.
To prevent thrashing, it is usually necessary to reduce the number of applications running simultaneously or simply increase the amount of RAM in the system. Operating systems, such as most versions of Windows, generally recommend that users not increase their virtual memory by more than 1.5 times the amount of physical RAM present. So, a system with 4 GB of RAM should have a virtual memory of at most 6 GB.
Virtual memory can work with the main memory of the computer to allow faster and smoother operations.
How to increase virtual memory in a system
Most operating systems allow users to increase the virtual memory of a configuration page.
- In Windows, users can also allow the system to dynamically manage the amount of virtual memory provided.
- Similarly, in Mac OS, users can use the preferences panel to allocate virtual memory.
Types of virtual memory: paging and segmentation
Virtual memory can be managed in many different ways by the operating system of a system, and the two most common approaches are paging and segmentation.
Virtual memory page
In a system that uses paging, RAM is divided into a number of blocks – usually 4k in size – called pages. Processes are then allocated only enough pages to meet their memory requirements. This means that there will always be a small amount of wasted memory, unless an unusual process requires exactly an integer number of pages.
Virtual memory segmentation
Segmentation is an alternative approach to memory management, where instead of fixed-size pages, processes are assigned segments of different lengths to meet their exact requirements. This means that, unlike a paged system, no memory is wasted in a segment. Segmentation also allows applications to be divided into logically independent address spaces, which can make them easier to share and more secure.
The advantages and disadvantages of virtual memory
Even though RAM is now relatively cheap compared to its cost when virtual memory was first developed, it is still extremely useful and is still used in many, perhaps most computer systems. The key issue of virtual memory is performance.
The advantages of virtual memory
- Allows you to run multiple applications at the same time.
- Allows larger applications to run on systems that do not have enough physical RAM to run them.
- It provides a way to increase memory, which is less expensive than buying more RAM.
- Provides a way to increase memory in a system that has the maximum amount of RAM that its hardware and operating system can support.
Disadvantages of virtual memory
- It does not offer the same performance as RAM.
- May adversely affect the overall performance of a system.
- Occupies storage space that could otherwise be used for long-term data storage.
KOSMIK Systems offers virtual memory services. We look forward to discussing more to find the best option for your business.