How does the Memory Hierarchy work?

Source: Internet
Author: User

 

The only purpose of the Memory Hierarchy Is to quickly access a large amount of memory. If we only need a small amount of memory, we would rather use all the fast static RAM; if the speed is not a problem, we can use all the virtual memory. The significance of the Memory Hierarchy Is to put frequently accessed data into the memory using the referenced spatial locality and the referenced temporal locality principle, however, you can leave infrequently accessed data in a slow External Store. However, frequently used and infrequently used datasets change dynamically during program execution, we cannot simply distribute data to the layers of the Memory Hierarchy when the program is started, and then remain unchanged during program execution. On the contrary, different memory subsystems must be able to adapt to changes and dynamically move data between subsystems based on changes in the spatial locality referenced during program execution and the referenced temporal locality.

Except for a few exceptions, most memory subsystem access occurs transparently between a layer of the Memory Hierarchy and its lower or upper adjacent layers.

For example, the CPU seldom accesses the memory directly. On the contrary, when the CPU requests data in the memory, the L1 cache takes over the access. If the requested data is in the cache, L1 cache provides the data to the CPU and ends the memory access. If the requested data is not in L1 cache, then L1 cache passes the request to L2 cache.

If the L2 cache has the required data, it returns the data to L1.
Cache and L1 cache then return the data to the CPU. In a short period of time
The cache is not satisfied with the L2 cache, because when the cache is missing, most cache systems will read some consecutive bytes in the primary storage (this data is called cache line, for example, the 80x86 CPU reads 16 to 64 bytes when a cache is missing). Now the L1 cache has copies of the data.

If both the L1 cache and L2 cache do not contain the required data, the request is sent to the primary storage. If the requested data is found in the primary storage, the primary storage subsystem transmits the data to the L2 cache, then the L2 cache passes the data to the L1 cache, and finally the L1 cache passes the data to the CPU. Similarly, the data is already in the L1 cache. Therefore, the requests to access the data in a short period of time will be satisfied by the L1 cache.

If the data is not in the primary storage, but in the virtual storage, on a storage device, the operating system will take over the access operation and read data from disks or other devices (such as network storage servers, and transmit the data to the primary storage subsystem. The master memory then transmits data to the CPU through the cache, as described above.

 

 

-- A deep understanding of computers

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.