Virtual Memory 8
Virtual Memory 8
Virtual Memory 8
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.
Page 1 of 6
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. The two ways computers handle virtual memory are through paging and
segmenting.
1. Paging
Paging is a virtual memory technique that separates memory into sections called paging files.
When a computer reaches its RAM limits, it transfers any currently unused pages into the part
of its hard drive used for virtual memory. The computer performs this process using a swap
file, a designated space within its hard drive for extending the virtual memory of the computer's
RAM. By moving unused files into its hard drive, the computer frees its RAM space for other
memory tasks and ensures that it doesn't run out of real memory.
As part of this process, the computer uses page tables, which translate virtual addresses into
the physical addresses that the computer's memory management unit (MMU) uses to process
instructions. The MMU communicates between the computer's OS and its page tables. When
the user performs a task, the OS searches its RAM for the processes to conduct the task. If it
can't find the processes to complete the task in RAM, the MMU prompts the OS to move the
required pages into RAM and uses a page table to note the new storage location of the pages.
In general, the process includes the following steps are as follows:
1. If the CPU tries to refer to a page that is currently not available in the main memory,
it generates an interrupt indicating a memory access fault.
2. The OS puts the interrupted process in a blocking state. For the execution to proceed
the OS must bring the required page into the memory.
Page 2 of 6
3. The OS will search for the required page in the logical address space.
4. The required page will be brought from logical address space to physical address
space. The page replacement algorithms are used for the decision-making of replacing
the page in physical address space.
5. The page table will be updated accordingly.
6. The signal will be sent to the CPU to continue the program execution and it will place
the process back into the ready state.
Hence whenever a page fault occurs these steps are followed by the operating system and the
required page is brought into memory.
2. Segmenting
Segmentation is another method of managing virtual memory. A segmentation system divides
virtual memory into varying lengths and moves any segments that aren't in use from the
computer's virtual memory space to its hard drive. Like page tables, segment tables track
whether the computer stores the segment in memory or a physical address.
Segmentation differs from paging because it divides memory into sections of varying lengths,
while paging divides memory into units of equal size. With paging, the hardware determines
the size of a section, but the user can select the length of a segment in a segmentation system.
Segmentation is often slower than paging, but it offers the user more control over how to divide
memory and may make it easier to share data between processes. You can customize the
segments based on the machine's purpose and usage. Casual computer users may prefer a
paging system because it automatically handles memory divisions.
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.
Page 3 of 6
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.
Page 4 of 6
What are the limitations of using virtual memory?
Although the use of virtual memory has its benefits, it also comes with some trade-offs 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.
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.
Page 5 of 6
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.
Page 6 of 6