Cache Memory
Definition of cache memory
A cache memory is a physical memory like RAM. It is smaller in capacity but faster in
operation than RAM. It is positioned in between processor and RAM.
There are two types of cache memory, such as L1 type cache memory and L2 type
cache memory. L1 type cache memory is built-in into the processor and L2 type cache
memory is built-in outside the processor but inside the motherboard. In modern multi-
core processors; there may be 3 types of cache (L1, L2, L3) where each L1 cache is
attached to each core, L2 cache is located just after the L1 cache. Every core has it’s
separate L1, L2 caches but all the cores may share a common cache located outside
the cores which is the L3 cache memory.
Importance of cache memory in a computer system
There is an unbelievable speed mismatch in between the operation of a processor and
RAM. Processor is the fastest unit in a computer system, but RAM is not as fast as
processor. So, there is always a speed mismatch problem in between them when they
work together. To overcome this speed mismatch problem, a faster (but smaller)
memory is used in between processor and RAM. This faster memory is called cache
memory. Cache memory stores frequently accessed data from RAM, so that CPU can
easily get them whenever needed.
Question: Discuss the function of a cache memory.
Answer:
Function of a Cache Memory
When processor needs any data/instruction, at first it goes to search that in
cache memory. If the required data/instruction is available in cache memory,
processor then takes it from cache. Otherwise, it goes to RAM to bring that
required data/instruction. Processor brings that required data/instruction from
RAM and a block of next data/instruction of same program is stored in cache
memory from RAM for future use.
Cache Memory RAM
Processor
Figure: Block diagram of the function of a cache memory.
Virtual Memory
:
Definition of virtual memory
A virtual memory is not a physical memory like RAM or cache. It is simply a
memory management technique adopted by an operating system when the
size of a program is larger than the size of RAM. This technique enables a
computer to be able to compensate shortages of physical memory by
transferring blocks of data from random access memory to hard disk storage.
(in HDD)Program=8GB
Page-1
Swap in
RAM=5GB Page-2
Frame-1 Page-3
Frame-2 Page-4
Frame-3 Page-5
Frame-4 Page-6
Frame-5 Swap out Page-7
Page-8
Figure: Block diagram of implementation of virtual memory technique.
Implementation of Virtual Memory
The virtual memory technique is taken place in between RAM and hard disk.
In this technique, the entire program is not loaded into the RAM at a time.
Instead of that, the program is divided into some equal size which are called
pages. The RAM is also divided into some equal size which are called
frames. Here the page size is equal to frame size. A page is loaded into a
frame which is called swap in. When a page is no more essential, it is back
to its previous location which is called swap out, This swap in and swap out
technique is called swapping. It is also called demand paging technique.
Using demand paging technique virtual memory is implemented.
Why Is Virtual Memory Important?
Useful when RAM capacity is lower than a program size. Possible to
run programs that are larger than size of primary storage without
adding more RAM.
Can be useful for multi-tasking.
Increases program flexibility.
Ensures protection so that one process cannot access another
process’s data.
Disadvantage of Virtual Memory
Since hard disk storage is much slower than RAM, computer works
slower than usual when virtual memory is implemented. That’s why
adding more physical RAM is a better solution.