7.6 Direct Cache Access
COS2621 - Computer Organisation · 7. Input/Output
Direct Cache Access
Overview of Cache Memory
Cache memory is a small, high-speed storage area located close to the CPU. It stores frequently accessed data to speed up processing. The cache operates on the principle of locality, which means that programs tend to access a relatively small portion of memory repeatedly.
Direct Cache Access Mechanism
Direct cache access involves a straightforward method of mapping memory addresses to cache locations. Each block of main memory is mapped to exactly one cache line. This mapping is determined by the formula:
Cache Line Index = (Memory Address) mod (Number of Cache Lines)
For example, if you have a cache with 4 lines and you want to access memory address 10:
Cache Line Index = 10 mod 4 = 2This means that the data from memory address 10 will be stored in cache line 2.
Cache Hit and Miss
A cache hit occurs when the CPU finds the requested data in the cache, while a cache miss happens when the data is not available. The performance of the cache is measured by the hit ratio, which is the number of cache hits divided by the total number of memory accesses.
Remember: A high hit ratio indicates efficient cache performance.
Example of Direct Cache Access
Consider a cache with 4 lines and the following memory addresses are accessed in sequence: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. Let's see how these addresses map to the cache:
- Address 0: Cache Line Index = 0 mod 4 = 0 (Cache Miss)
- Address 1: Cache Line Index = 1 mod 4 = 1 (Cache Miss)
- Address 2: Cache Line Index = 2 mod 4 = 2 (Cache Miss)
- Address 3: Cache Line Index = 3 mod 4 = 3 (Cache Miss)
- Address 4: Cache Line Index = 4 mod 4 = 0 (Cache Hit)
- Address 5: Cache Line Index = 5 mod 4 = 1 (Cache Hit)
- Address 6: Cache Line Index = 6 mod 4 = 2 (Cache Hit)
- Address 7: Cache Line Index = 7 mod 4 = 3 (Cache Hit)
- Address 8: Cache Line Index = 8 mod 4 = 0 (Cache Miss)
- Address 9: Cache Line Index = 9 mod 4 = 1 (Cache Miss)
In this example, the first four accesses result in cache misses, while the next four accesses yield cache hits, demonstrating the effectiveness of the cache.
Watch out: If the cache is too small or poorly configured, it can lead to a high miss rate, which degrades performance.
Conclusion
Direct cache access is a fundamental concept in computer architecture that enhances data retrieval speed. Understanding how cache lines are indexed and the implications of cache hits and misses is crucial for designing efficient systems.
Check your understanding
- What is the formula for calculating the cache line index?
- Explain the difference between a cache hit and a cache miss.
- In the example provided, how many cache hits occurred?
- What are the potential downsides of a poorly configured cache?
Test yourself
4 quick questions on this lesson. Pick an answer to see if you're right.
1. What occurs when the CPU finds the requested data in the cache?
2. In the example provided, how many cache hits occurred?
3. What is the formula for calculating the cache line index in direct cache access?
4. What is a potential downside of a poorly configured cache?