如何知道在Windbg中得到Memory type(也叫做caching type)

这来源工作中的一个真实的例子。由于错误的使用了cache type导致了程序整体性能降低了大约30%。这里记录了如何在Win7+Atom CPU上获取memory type的方法,由于cache机制的复杂性,本文所写的未必适合你的情况。具体问题你可能需要参阅
1.你的CPU的手册,比如说Intel IA32手册的3A卷的10.3 METHODS OF CACHING AVAILABLE
2.操作系统的资料,比如说Windows Internals
3.Windbg的手册。

---------------------------我分分分---------------------------------
1.你需要在living kernel debug的情况下把process context换到你关心的process上,这是由于需要访问进程的page table。

2.使用!pte拿到虚拟地址的page table entry.
1: kd> !pte 0f2c430c  //这里0f2c430c就是我关心的虚拟地址。
VA 0f2c430c
PDE at 00000000C06003C8 PTE at 00000000C0079620
contains 000000001C690867 contains 800000001CE9586F

3. 需要看PTE(page table entry)中的PAT(bit 7), PCD(bit 4), PWT(bit 3)位。
1: kd> .formats 1CE9586F
Evaluate expression:
Hex: 1ce9586f
Decimal: 485054575
Octal: 03472254157
Binary: 00011100 11101001 01011000 01101111

所以pat = 0,pcd = 0,pwt = 1

4.在Atom CPU上cache type是由PTE中的这三位指定的,并且是可编程的。
还好Windbg提供了一个便利的命令。
1: kd> !pat
PAT_Index PCD PWT Memory Type
  0        0   0    WB
  0        0   1    USWC
  0        1   0    WEAK_UC
  0        1   1    STRONG_UC
  1        0   0    WB
  1        0   1    USWC
  1        1   0    WEAK_UC
  1        1   1    STRONG_UC

那么0 0 1就说明Memory type是USWC,也就是
Write Combining - System memory locations are not cached (as with uncacheable memory) and coherency is not enforced by the processor’s bus coherency protocol.

原文地址:https://www.cnblogs.com/aoaoblogs/p/1606067.html