1
CS3351-DIGITAL PRINCIPLES AND COMPUTER ORGANIZATION
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 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.
Working Principle
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.
[Link] [Link]. AI&DS Department, KVCET
2
CS3351-DIGITAL PRINCIPLES AND COMPUTER ORGANIZATION
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 page files 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.
[Link] [Link]. AI&DS Department, KVCET
3
CS3351-DIGITAL PRINCIPLES AND COMPUTER ORGANIZATION
Page Table
Page Table is a data structure used by the virtual memory system to store the
mapping between logical addresses and physical addresses.
Logical addresses are generated by the CPU for the pages of the processes
therefore they are generally used by the processes.
Physical addresses are the actual frame address of the memory. They are generally
used by the hardware or more specifically by RAM subsystems.
The CPU always accesses the processes through their logical addresses. However,
the main memory recognizes physical address only.
In this situation, a unit named as Memory Management Unit comes into the
picture.
It converts the page number of the logical address to the frame number of the
physical address. The offset remains same in both the addresses.
To perform this task, Memory Management unit needs a special kind of mapping
which is done by page table.
The page table stores all the Frame numbers corresponding to the page numbers of
the page table.
In other words, the page table maps the page number to its actual location (frame
number) in the memory.
[Link] [Link]. AI&DS Department, KVCET
4
CS3351-DIGITAL PRINCIPLES AND COMPUTER ORGANIZATION
Translation look aside buffer (TLB)
A Translation look aside buffer can be defined as a memory cache which can be
used to reduce the time taken to access the page table again and again.
It is a memory cache which is closer to the CPU and the time taken by CPU to
access TLB is lesser then that taken to access main memory.
In other words, we can say that TLB is faster and smaller than the main memory
but cheaper and bigger than the register.
TLB follows the concept of locality of reference which means that it contains only
the entries of those many pages that are frequently accessed by the CPU.
In translation look aside buffers, there are tags and keys with the help of which, the
mapping is done.
TLB hit is a condition where the desired entry is found in translation look aside
buffer.
If this happens then the CPU simply access the actual location in the main
memory.
However, if the entry is not found in TLB (TLB miss) then CPU has to access
page table in the main memory and then access the actual frame in the main
memory.
Therefore, in the case of TLB hit, the effective access time will be lesser as
compare to the case of TLB miss.
[Link] [Link]. AI&DS Department, KVCET
5
CS3351-DIGITAL PRINCIPLES AND COMPUTER ORGANIZATION
Advantages of Virtual Memory
1. The degree of Multiprogramming will be increased.
2. User can run large application with less real RAM.
3. There is no need to buy more memory RAMs.
Disadvantages of Virtual Memory
1. The system becomes slower since swapping takes time.
2. It takes more time in switching between applications.
3. The user will have the lesser hard disk space for its use.
[Link] [Link]. AI&DS Department, KVCET