Cache Memory in Computer Systems, Techniques & Formulas

Cache memory or CPU memory is a form of computer memory that is used to store frequently used instructions and data for quick retrieval. It is typically used in a processor-memory hierarchy, along with main memory, to increase the speed at which data can be accessed and processed by the central processing unit (CPU). Cache memory is significantly faster than main memory, allowing the CPU to quickly access frequently used data. It is usually divided into a number of levels, with each level storing a larger, more comprehensive set of data.

But why do we need RAM instead of storing this entire information and data in the Cache memory directly? The answer is space and cost. Cache memory is very limited and exceptionally expensive compared to its volatile counterpart – RAM. The storage space of cache memory is determined by the cache memory size.

What makes cache memory in computer systems so vital and faster?

As we know that cache memory can access frequently-used data with highly optimized hardware and a logical approach. It optimizes the process of choosing the right set of data that it can easily store and make it accessible for your CPU in no time.

Cache Memory Levels
Image source – educba.com

The cache memory is divided into three more different cache memory types namely L1, L2, and L3 cache with the leading ones faster and near to the CPU than the preceding ones. The purpose of using these cache memory types is to further optimize the performance of cache memory in computer systems.

Now that you have enough understanding of cache memory and how it serves as an integral part of computer architecture, the following blog post will further discuss how Cache mapping plays a vital role in the transition of content from the main memory to the cache memory.

Let’s dive deep into the details.

3 Cache Mapping Techniques

Cache mapping denotes the approach that helps in transiting the content present in your RAM to the cache memory in computer systems. There are three different types of memory mapping in today’s time:

  1. Direct Mapping
  2. Full Associative Mapping
  3. Set Associative Mapping (N-way)

1. Direct Mapping

The simplest memory mapping approach is direct mapping which is used to copy the block of main memory to the available cache line.

In this methodology, the algorithm assigns each memory block to a particular cache line directly without any middleware process. If the cache line is already occupied by another memory block, the previous block is emptied to load the new block.

The memory address space is divided into two segments namely the index field and the tag field with the main memory holding the index field address and the cache storing the later tag field as a reference.

Algorithmeatically,

  • x = y mode z
  • whereas,
  • x = cache line index
  • y = main memory block index
  • z = total number of lines available in the cache memory

2. Full Associative Mapping

In Full-associative mapping, associative memory is included as a middleware to store the content and addresses of the main memory. In this approach, any memory block can be aligned with any cache line freely to allow the placement of any word at any location of cache memory. This approach is highly optimized, flexible, and faster compared to direct mapping.

3. Set-Associative Mapping (N-way)

In this cache mapping, the experts tried to resolve the limitations and downsides of direct mapping by making some adjustments to the direct mapping algorithm. Set associative cache mapping fundamental eliminates the need to thrash or erase the occupied block as prevalent in the direct mapping approach.

The algorithm works by mapping the multiple lines together instead of mapping each line one by one. Then the entire memory block can be mapped to any of the cache lines. It’s basically a hybrid of the above two mapping techniques and serves as the best of two mapping worlds.

Algorithmically,

  • a = b * c
  • x= y mod b
  • where
  • i=cache set number
  • j=main memory block number
  • a=number of lines in the cache number of sets
  • b=number of sets
  • c=number of lines in each set

Read More: FE Exam Prep Course

Conclusion

As we see in modern computer architecture, Cache Memory in Computer Systems is the determining factor behind all the remarkable performance of computer systems we experience today. Cache mapping plays a vital role by mapping main memory contents into cache memory so it can be forwarded quickly to the processor for instant processing.

It’s simply like storing your frequently bought warehouse items on the store shelf for faster delivery and fulfillment of purchase orders. Cache memory does the same by creating a mapping of content saved in the RAM, making it closer to the CPU and faster than RAM.

We hope you now have a solid understanding of Cache Memory and how it compares to its volatile counterpart – RAM.

wasim-smal
Wasim Asghar – P.E, P.ENG, M.ENG

Licensed Professional Engineer in Texas (PE), Florida (PE) and Ontario (P. Eng) with consulting experience in design, commissioning and plant engineering for clients in Energy, Mining and Infrastructure.