Cache write back and write through collections
To ensure data consistency between cache and memory, there are usually three methods:
1> write through: When the CPU writes data to the cache, it also writes a copy to the memory to make the data of the cache and memory consistent. The advantage is that memory is accessed at a low speed every time.
2> post write: When the CPU updates the cache data, it writes the updated data to an update buffer and updates the memory only when appropriate. This improves the cache access speed. However, when data is continuously updated more than twice, the buffer is insufficient and memory is forced to be updated at the same time.
3> write back: When the CPU updates the cache, it only marks the updated cache area and does not synchronously update memory. Memory is updated only when the cache area is replaced by new data. The reason for this is that the cache is often stored in the intermediate result, and there is no need to synchronously update memory. The advantage is that the CPU execution efficiency is improved, and the disadvantage is that the technology is complicated to implement.
| Write-back and passthrough |
| |
| |
| For the cache algorithm. There are two main types: Write-through and write-back ). write-through, that is, the Data Processing request sent by the OS waits until all data in the memory is correctly written to the stable storage media (such as the hard disk), and then the report is returned to the OS for processing, then the OS will update its status. In this case, there is usually no dirty cache. write-back: After the OS sends a request to process data, the algorithm will store it in buffer and before it is correctly written to the stable storage media (such as hard disk, after the OS is processed, the OS will update. However, if the current power is down or other faults occur, the buffer data is not written to the stable storage media (such as the hard disk ), the OS update information is inconsistent with the information in media. to avoid this, NVRAM is used. After power-on, data is still not lost. However, after power-on, the data is dirty, which is the Dir Ty cache (how to update dirty cache to media is what write-back should do ). This is similar to buying and selling things. Write-through is equivalent to buying things by yourself, and you can get it by yourself when you buy things. Write-back is similar to the intermediary, and you give money to the intermediary, then it tells you that you have bought the item, and then you believe that you have got it, but in special circumstances, the intermediary ran (out of the chain), and you will check it again, something is not really ready. |
|
1. Two types of Cache
-- Write through
When writing data to the cache, the corresponding memory content is also updated.
-- Write back
It is only written to the cache. The memory content will be updated only when the cache is saved to be replaced by other data or when the system flush the cache.
2. Two cache Functions
-- Flush
Write the cache content back to memory. When the cache is write through, flush is not required.
-- Invalidate
Discard the cache content directly.
3. Cache Usage
Cache processing is generally used when DMA is used for memory. Because DMA does not pass through the cache when accessing memory. For example, in drivers such as Ethernet, wireless, and USB, DMA will operate descriptors and packet buffers, and driver will perform these operations.
-- If the descripter and Packet Buffer addresses used by the driver are both cache addresses
A ). when the driver reads the descripter status, such as owned by CPU/DMA, whether the package is received or not, it needs to cache the content in the current structure of the descripter. After receiving the packet, cache invalidate for packet buffer is also required
B ). when writing descripter status such as owned by DMA, the driver needs to flush the content in the current structure of the descripter when sending the packet. When sending the packet, it also needs to flush the packet buffer.
-- Some drivers use the uncache address for descripter, so invalidate/flush will not be used in the above two cases. Generally, the uncache address is rarely used for packet buffer, because the processing of packet content will be very frequent and the uncache usage will be slow. The descripter generally has a relatively small structure. If the cache address is used, the time consumed for invalidate/flush may be more than that for uncache.
Cache write back and write through