میخواهیم ببینیم که چگونه حافظه ها میتوانند پرفورمنس را تحت تاثیر قرار بدهند


پس ما برای این به سلسله مراتب حافظه نیاز داریم .
پس در کل به صورت یک حافظه ی بزرگ میبیند . در کل

Locality is a fundamental concept in the design and performance optimization of memory hierarchies in computer systems. It refers to the tendency of a processor to access the same set of memory locations repeatedly over a short period of time. There are two main types of locality: temporal locality and spatial locality.
Types of Locality
- Temporal Locality:
- Definition: Temporal locality refers to the reuse of specific data or resources within a relatively short period of time.
- Example: If a program accesses a particular memory location, it is likely to access the same location again in the near future. This is common in loops and frequently called functions.
- Spatial Locality:
- Definition: Spatial locality refers to the use of data elements within relatively close storage locations.
- Example: If a program accesses a particular memory location, it is likely to access nearby memory locations soon. This is common in array processing, where elements are stored in contiguous memory locations.
Memory Hierarchy
The memory hierarchy in computer systems is designed to take advantage of locality to optimize performance. It consists of multiple levels of memory, each with different speed, size, and cost characteristics. Here is a typical structure of the memory hierarchy from fastest to slowest:
- Registers:
- Speed: Fastest memory available.
- Size: Very limited (usually in the order of kilobytes).
- Location: Inside the CPU.
- Locality: Both temporal and spatial locality are highly leveraged.
- L1 Cache:
- Speed: Very fast, but slower than registers.
- Size: Small (usually tens of kilobytes).
- Location: On the CPU chip.
- Locality: Temporal and spatial locality are crucial for its effectiveness.
- L2 Cache:
- Speed: Slower than L1 cache but still fast.
- Size: Larger than L1 cache (hundreds of kilobytes to a few megabytes).
- Location: On the CPU chip or close to it.
- Locality: Temporal and spatial locality are important.
- L3 Cache:
- Speed: Slower than L2 cache.
- Size: Larger (several megabytes to tens of megabytes).
- Location: On the CPU chip or shared among multiple CPU cores.
- Locality: Designed to capture a wider range of locality.
- Main Memory (RAM):
- Speed: Slower than caches.
- Size: Much larger (gigabytes).
- Location: Separate from the CPU.
- Locality: Less temporal locality, more spatial locality due to larger data blocks (pages).
- Secondary Storage (HDDs, SSDs):
- Speed: Much slower than RAM.
- Size: Very large (terabytes).
- Location: Separate from the main memory.
- Locality: Spatial locality is significant; temporal locality is less effective due to access times.
- Tertiary Storage (Tape Drives, Remote Storage):
- Speed: Slowest.
- Size: Can be extremely large (multiple terabytes to petabytes).
- Location: Often offsite or in different physical devices.
- Locality: Mainly used for archival purposes, where locality is less of a concern.
Exploiting Locality
Cache Design:
- Cache Lines: Typically, data is moved between memory levels in blocks called cache lines. Larger cache lines exploit spatial locality by fetching adjacent memory locations together.
- Prefetching: Mechanisms to predict future data accesses and load data into the cache before it is requested by the CPU, thus exploiting both temporal and spatial locality.
Software Optimization:
- Loop Optimizations: Techniques such as loop unrolling and blocking to ensure that data used within loops fits into the cache, maximizing temporal locality.
- Data Structure Layout: Arranging data structures in memory to ensure that related data is stored contiguously, thereby enhancing spatial locality.
By understanding and leveraging locality, both hardware and software can be optimized to improve the performance and efficiency of computer systems.
بحث مدیریت حافظه در پردازنده ها خیلی مهم است
on this we have direct mapping :


به طور مثال تا اینجا امده ایم

حال دیگر کش گنجایش حافظه های دیگر را ندارد

