Memory - pyramid hierarchy: the closer the faster CPU, the smaller the capacity, the more expensive price

Memory - pyramid hierarchy: the closer the faster CPU, the smaller the capacity, the more expensive price

Principles of Computer Composition catalog: https://www.cnblogs.com/binarylei/p/12585607.html

1. pyramid hierarchy

Modern computer storage devices generally Cache, memory, HDD (SSD) hard drives. These storage devices closer to the faster CPU, the smaller the capacity, the more expensive price.

  • Register (the Register) : register memory is not so much, in fact, more like a part of the CPU itself, only very limited information is stored, but very fast, and the CPU-sync.
  • Cache (the CPU the Cache) : using SRAM (Static Random-Access Memory, Static Random Access Memory) chips.
  • Memory (a DRAM) : use DRAM (Dynamic Random Access Memory, Dynamic Random Access Memory) chips, than SRAM, the higher its density, with a greater volume, but it is a lot cheaper than SRAM chips.
  • Hard : The SSD (Solid-state drive or Solid-state disk, solid state drive), HDD (Hard Disk Drive, a hard disk).
Figure 1: Memory Hierarchy Pyramid

Different levels of memory devices features:

  1. The closer the faster CPU, the smaller the capacity, the more expensive price.
  2. Each memory device and only dealing with its adjacent storage device. For example, CPU Cache is loaded from memory comes, or need to write back to memory, and does not directly write data back to the hard disk, it will not load data from the hard disk to the CPU Cache, but is loaded directly into memory first, and then from memory into the Cache.

1.1 Cache (SRAM)

Cache SRAM circuit is simple, so the access speed is very fast, but the data can be stored is limited. In the CPU, there is usually L1, L2, L3 for three-cache. Each one has its own CPU core L1 cache, usually divided into instruction cache and data cache , separate instruction and data storage used by the CPU.

  • L1 Cache: often embedded inside the CPU core.
  • L2 Cache: Each CPU core has also, but it is often not in the CPU inner core. Therefore, L2 Cache access speed will be slightly slower than the number L1.
  • L3 Cache, it is generally common to a plurality of CPU cores, the size will be even greater, the access speed slower naturally.
Figure 2: Structure Cache

1.2 Memory (DRAM)

1.3 hard drive

2. The principle of locality - How to choose the best storage

2.1 Comparison of different memory

Figure 3: Comparison of different memory cost table

You can see that in a real computer inside, the more quickly the device, the smaller capacity. A total of 10M Cache, cost just tens of dollars here. The 8GB of RAM, SSD 128G and 1T of HDD, probably retail price together, and we will cache the price almost.

Different memory access latency of data:

2.2 principle of locality

We can not only enjoy the speed of CPU Cache, and enjoy the memory, hard drive huge capacity and low prices? Predecessors have explored the answer, that is, the principle of locality of data in memory (Principle of Locality). We can use this principle of locality, to develop strategies to manage and access data.

  • Temporal locality (temporal locality) : If the data is accessed, then it will be accessed again in a short time. As LRU caching mechanism, frequently accessed data will be stored in memory.
  • Spatial locality (Spatial locality) : If the data is accessed, then it and the adjacent data will soon be accessed. If the array of CPU pre-reading function.

2.3 actual combat - how to spend the least money, hold all goods Amazon

Understand the principle of locality, here we come to a real, take a look through the principle of locality, use a combination of different levels of memory, exactly what kind of benefits will be. Assuming that Amazon this electricity supplier website has 600 million of goods, if each item requires 4MB of storage space (taking into account the commodity picture, then, 4MB is already a relatively small estimate), it needs a total 2400TB (= 6 Yi × 4MB ) is stored. What kind of storage device should you choose?

  • All goods in memory. It would need $ 36 million (= 2400TB × US $ 0.015 / USD 1MB = 3600 million). However, this is 600 million in commodities, not every piece of merchandise will be frequently accessed.
  • Assumption 1% of the popular goods into memory. That is 6 million hot commodity, and the rest of the commodity on the mechanical HDD hard drive, then we would need storage costs down to $ 456,000 (= $ 36 million × 1% + 2400TB × US $ 0.00004 / 1MB ).

Description: This is the temporal locality , the following two issues is what we need major concern.

  • LRU (Least Recently Used) caching algorithm : data is loaded into memory user has visited, once out of memory, the data will not be accessed longest in memory is removed from memory. Thus, the hot commodity is much more accessible, it will always be retained in memory, and is accessed less popular commodity, it is only stored on the HDD hard disk. The more popular commodity, the more easy to find in memory, it makes better use of random access memory performance.

  • Cache hit rate (Hit Rate / Hit Ratio) occupies a proportion of LRU caching strategy, data access can be found in memory:

So, just put six million really meet our actual merchandise online service request? The number of users in 2017 to 300 million in the Amazon, we estimate daily active users to 100 million, which will be 100 million users per capita access to 100 commodities, then the average number of items per visit is 120,000.

  • Random-access memory requests require 100ns, that is, in extreme cases, memory can support 10 million (= 1s / 100ns) random access. We used 24TB of memory, if a 8G, then, means that there are 3000 memory, can support 30 billion times per second (= 24TB / 8GB × 1s / 100ns) access.
  • HDD hard drive can only support random access of 100 times per second. 2400TB data to a disk 4TB is calculated, there is a disk 600, which is able to support the random access per 60,000 (= 2400TB / 4TB × 1s / 10ms) of.
  • If all goods access request directly to disk HDD, HDD disk can not support such pressure. We want at least 50% cache hit rate, the number of visits to support the corresponding HDD disk. Otherwise, we either choose to add more number of HDD hard drive, so random access 120,000 times per second, or HDD to SSD to replace the hard disk, so that a single hard drive can support more random access requests.

Of course, here we are just a simple estimation. In practical application, view a data item could mean random access memory or a random disk more than once. The corresponding data storage space than to consider the data, but also need to consider the maintenance of spatial data structures, and cache hit rate and access requests should also consider the mean and peak.


The intentions of recording a little bit every day. Perhaps the content is not important, but the habit is very important!

Guess you like

Origin www.cnblogs.com/binarylei/p/12588928.html