Cache Memory | Locality of Reference in Computer Organization and OS

Cache Memory | Locality of Reference in Computer Organization and OS

What is Cache Memory

Definition of Cache Memory – Cache memory is variant of DRAM (Dynamic RAM), and it is embedded into the CPU (processor) or between CPU and main memory of computer system that helps to access data or instructions from computer’ memory (Primary and Secondary Memory) with higher efficiency. This memory works as a temporary storage unit that is trashed when power get turn-off. Cache memory is more readable form to access for the CPU chip compare to computer’s primary memory.

cache memory

Cache Memory Diagram

Cache memory has speed higher like as between 10 to 100 times faster to Random Access Memory (RAM), so it is more expensive to primary memory of computer system. Main objective of designing cache memory is to decrease the average time to retrieving from primary memory, and it helps to save some piece of data which are used regularly in primary memory unit.

Read More – Operating System Tutorial

Importance of Cache Memory

Read More – Virtual Memory in OS | Demand Paging

CPU Cache memory plays very important role for memory unit in the computer system because it offers the principal assistant to enhance the computer’s performance. It has limited space but having higher speed compare to main memory, as well as it is also more expensive to primary memory. Cache memory is placed in between the processor registers and RAMs (Random Access Memory).

Cache memory is located on the two places Motherboard and Processor. If it located on the motherboard then it is known as “External Cache Memory” as well as “L2”, and its speed is very high. External cache memory is available in different range like as 256 Kb, 512 Kb, 1 Mb, and 2 MB. If it is found on the processor then it is called the “Internal Cache Memory”, but its speed much high compare to External Cache Memory. This is found on the Pentium III and up to.

Types of Cache Memory

Read More – Page Fault in Operating System

Two types of Cache Memory are used in CPU. Such as –

Primary Cache Memory This cache memory is embedded directly on the processor (CPU), and it is small size but having less access time to registers.

Secondary Cache Memory This memory is located in between the primary cache and main memory. It has higher access time to Primary Cache Memory.

Level of Cache Memory

Level 1 (L1) cache

L1 is also known as “Primary Cache Memory”. This cache is developed with SRAM (Static RAM), and it has small size to left caches but larger then CPU’s registers. It has some limitation to storage is between the 2KB to 64KB but it totally depend upon the computer processor. It is located on the register in microprocessor. CPU firstly searches all instructions in the L1 cache then other. In L1, some registers are used like as accumulator, Program counter, address register etc.

Level 2 (L2) cache

L2 is also called “Secondary Cache Memory”, and it is placed between the CPU and Dynamic RAM. It is large size but slow speed to L1 cache. L2 has storage capacity between 64kb to 2MB. Both cache (L1 and L2) work simultaneously because if some data is missed in L1 then L1 instantly retrieves data from L2 cache memory. It is also made of SRAM.

Level 3 (L3) cache

L3 is also known as “Main Memory“. L3 has large size to L1 and L2 as well as slower to them, and its storage capacity between 1MB to 8MB. All data are deleted in

L3 when power gets turn off. It helps to decrease time delay between request and access of data from main memory.

Cache Memory Size

  • L1 Cache – Between 2KB to 64KB
  • L2 Cache – Between 64kb to 2MB
  • L3 Cache – 1MB to 8MB

Function of Cache Memory

function of cache-memory

Cache memory is used to perform various functions. So

Use of Cache Memory

  • CPU sends the numerous requests respect to content of different memory location.
  • Search entire cache for those data.
  • If, data is existed then fetches needed block of data from primary memory to cache memory.
  • Then move it from cache memory to CPU.
  • Cache makes communication to all tags, which are identified as well as exist in every cache slot.

Advantages of Cache Memory

  • Less access time than primary memory (RAM).
  • Temporary storage for execution instruction in short time duration.
  • Cache always ready to execution.
  • Enhance performance of computer system.

Disadvantages of Cache Memory

  • Less storage capacity
  • More expensive
  • Not permanent storage memory

What is Locality of Reference

Read More – Virtual Memory in OS | Demand Paging

Definition – Locality of reference is the tendency of computer system programs, which are tried to access those addresses location that are closest to another memory address.

The principle of locality of reference is based on their loops and subroutine calls of programs.

If, programs come in the loops then CPU sends various set of instructions, which are constructed by loop.

If, subroutine calls are fired then all group of instructions are retrieved from memory unit.

References to data items also get localized that means same data item is referenced again and again.

locality of reference

In this diagram, If CPU wish to obtain or fetch several data then firstly it prefers to cache memory because it is closest to it, as well as offers higher access speed. If appropriate data is found by CPU, then this data will be retrieved, and this condition is known as “Cache Hit”. But needed instructions are not searched in the cache memory area then this case is called the “Cache Miss”, then CPU finds the primary memory for searching required data, if data is found then one conditions is fired from two methods such as –

  • First method is that CPU must be read the appropriate data or instructions, and use it but in future if need same data then CPU again try to access the same primary memory for using it, but this memory unit is slowest to access data.
  • Second method, required data or instructions are saved in to cache memory unit because if in future same data is required then this data or instruction can be accessed with fastest.

Functions of Locality of Reference

Read More – Page Fault in Operating System

The principle of locality of reference is based on the five functions such as –

Types of Locality of Reference

Temporal Locality

In temporal locality, such data or instructions are fetched which are required in sooner for execution, so those data are saved in the cache memory because when we try to search same data in the primary memory, then it may be trashed. This process is called the “Temporal Locality”.

Spatial Locality

Spatial locality is totally different to temporal locality because in the Spatial Locality such data or instruction is traced , which are near to current memory location, that are easily fetched when they are demanded in near future. This entire process is known as “Spatial Locality”.

Memory locality

In the memory locality, memory is used as explicitly by spatial locality.

Branch locality

If the spatio-temporal coordinate space has only a few possible alternatives to the possible part of the path. This is the case when an instruction loop has a simple structure, or the possible result of a small system of conditional branching instructions is limited to a small set of possibilities. Branch areas are generally not a spatial locality because some possibilities may be located far away from each other.

Equidistant locality

It is half between the spatial locality and the branch locality. Consider locations accessing loops in an equilateral pattern, that is, the path in the spatio-temporal coordinate space is a dotted line. In this case, a simple linear function can predict which location will be reached in the near future

Leave a Reply

Your email address will not be published. Required fields are marked *