IA32中的5种caching type(也叫memory type)

大部分内容来至于IA32手册第三卷10.3 METHODS OF CACHING AVAILABLE

英文部分是绝对正确的,因为是原文。中文部分是一些自己的总结与理解,凑活着看吧。

IA32现在一共有5种caching type(也叫memory type)
Table 10-2. Memory Types and Their Properties
Memory Type and Mnemonic Cacheable Write Cacheable
Allows Speculative Reads
Memory Ordering Model
Strong Uncacheable(UC)
No No No Strong Ordering
Uncacheable (UC-)
No No No
Strong Ordering. Can only be selected through the PAT. Can be overridden by WC in MTRRs.
Write Combining (WC)
No No Yes
Weak Ordering. Available by programming MTRRs or by selecting it through the PAT.
Write-through (WT)
Yes No Yes
Speculative Processor Ordering
Write Back(WB) Yes Yes Yes Speculative Processor Ordering
Write protected(WP)
Yes for reads, no for writes No Yes
Speculative Processor Ordering. Available by programming MTRRs.










  1. Strong Uncacheable(UC) : 对于UC的内存读写操作都不会写到cache里,不会被reordering.这种类型的内存适用于memory-mapped I/O device,比如说集成显卡。对于被memory-mapped I/O device使用的内存,由于会被CPU和I/O device同时访问,那么CPU的cache就会导致一致性的问题(Note1)。reordering也会导致I/O device读到dirty data,比如说I/O device把这些内存作为一些控制用的寄存器使用.
    对于普通用途的内存,UC会导致性能的急剧下降。
    Note: 一种例外是,有些I/O device支持bus coherency protocol,可以和CPU保持cache一致性,这样的话是可以使用cacheable的内存的,但是这种总线协议也是有代价的。
  2. Uncacheable (UC-): 和UC类型一样,除了UC- memory type可以通过设置MTRRs被改写为WC memory type.
  3. Write Combining (WC): WC内存不会被cache, bus coherency protcoal不会保证WC内存的读写。对于WC类型的写操作,可能会被延迟,数据被combined in write combining buffer, 这样可以减少总线上的访存操作。Speculative reads are allowed(Note)。
    对于video frame buffer, 适合使用WC类型的内存。因为CPU对于frame buffer一般只有写操作,没有读,并不需要cache。对frame buffer而言,的写操作是否按顺序没有关系。
    (Note:  Speculative read是指读之前并不验证内存的有效性,先冒险的读进来,如果发现不是有效数据再取消读取操作,并更新内存后再读取. 比如说数据还是被buffer在WC buffer中)
  4. Write-through (WT) and Write-back(WB)





    WT
    Writes and reads to and from system memory are cached.
    Reads come from cache lines on cache hits
    read misses cause cache fills
    Speculative reads are allowed
    Write combining is allowed.
    All writes are written to a cache line (when possible) and through to system memory. 
    When writing through to memory, invalid cache lines are never filled
    and valid cache lines are either filled or invalidated. Write combining is allowed.
    (Write misses doesn't cause cache line fills)
    适用于bus上的设备只读取内存而不需要写
    (Note: Windows上似乎没有使用这种类型的内存)
    WB Same as WT
    Write combining is allowed.
    Write misses cause cache line fills
    and writes are performed entirely in the cache, when possible
    最普通的只会被CPU使用的内存,由于write操作是在cache中进行的,只有必要的时候才会被写会memory,可减少了bus的上的压力
  5. Write protected(WP): 读操作和WT/WB没有什么区别,读会被cache. 写不一样,写的时候会在bus上传播这个操作,并且导致其他处理器上的cache lines被更新。
    主要用于多处理器的情况。WP的内存,在写的时候就会更新其他处理器上的cache,而WB/WT类型的内存需要等到其他处理读的时候才会去更形无效的cache
原文地址:https://www.cnblogs.com/aoaoblogs/p/1917009.html