先决条件 – 在缓存中直写和回写
在读操作期间,当 CPU 确定缓存中的一个字时,主存不包括在传输中。因此,当操作是写操作时,系统可以通过两种方式进行。
1. 直写法:最简单的方法是当缓存在指定地址包含字时并行更新时,每次内存写操作都更新主内存。这可以称为直写方法。
2.回写方法:
在写操作期间,在回写方法中仅更新缓存位置。然后,该位置由一个标志标记,以便稍后在从缓存中删除该字时将其复制到主内存中。对于回写方法,原因是在一个字留在缓存中的时间内,它可以被多次更新。因此,只要该字保留在缓存中,副本是否在主缓存中都没有关系。这只是当字从缓存中移出时,缓存需要重写到主内存中的精确副本。
直写和回写方法的区别:
S.No. | Write Through Method | Write Back Method |
---|---|---|
1 | In this method main memory is updated with every memory write operation as well as cache memory is updated in parallel if it contains the word at the specified address. | In this method only cache location is updated during write operation. |
2 | Main memory always contains same data as cache. | Main memory and cache memory may have different data. |
3 | Number of memory write operation in a typical program is more. | Number of memory write operation in a typical program is less |
4 | When I/O device communicated through DMA would receive most recent data. | When I/O device communicated through DMA would not receive most recent data. |
5 | It is a process of writing cache and main memory simultaneously. | It is a process of writing cache and data is removed from cache, first copied to main memory. |