x86 设置脏页位时如何提示?

发布于 2024-12-12 11:27:37 字数 188 浏览 0 评论 0原文

从软件的角度来看,弄脏内存页面的指令与内核实际在页表条目 (PTE) 中将该页面标记为脏页面之间的延迟是多少?

换句话说,如果一条指令弄脏了一页,下一条指令是否可以读取 PTE 并看到脏位设置?

我不关心实际经过的周期,仅当存在一个尚未设置脏位的软件可见窗口时。我似乎在参考手册中找不到任何保证。

From a software point of view, what is the latency between an instruction that dirties a memory page and when the core actually marks the page dirty in the Page Table Entry (PTE)?

In other words, if an instruction dirties a page, can the very next instruction read the PTE and see the dirty bit set?

I don't care about the actual elapsed cycles, only if there is a software visible window in which the dirty bit is not yet set. I can't seem to find any guarantees in the reference manuals.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我爱人 2024-12-19 11:27:37

来自 AMD 手册(大约 2005 年),第 2 卷:系统编程:

5.4 页面转换表条目字段 ...脏 (D) 位。位 6。该位仅出现在页面转换层次结构的最低级别中。表示是否进行页面翻译
该入口点已写入的表或物理页。
第一次写入时,处理器将 D 位设置为 1
到物理页面。

Intel 的同上(大约 2006 年),第 3-A 卷:系统编程指南,第 1 部分:

3.7.6 页目录和页表条目 ...脏 (D) 标志,位 6 指示设置时是否已写入页。
(此标志不用于指向页面的页面目录条目
表。)内存管理软件通常会在发生以下情况时清除此标志:
页最初加载到物理内存中。然后处理器设置
第一次访问页面进行写操作时会使用此标志。

更新

来自最新的英特尔手册(第 3A 卷,系统编程指南):

8.1.2.1 自动锁定 处理器自动遵循 LOCK 语义的操作如下: ... 当
更新页目录和页表条目 - 更新时
页目录和页表条目,处理器使用锁定
周期在页目录中设置已访问和脏标志以及
页表条目。

从第 8.1 节和第 8.2 节中的其余文本可以看出,一旦 CPU 使用锁定操作设置了脏位,其他 CPU 就应该开始看到更新后的值。

当然,您可能会遇到竞争条件,因为您首先在一个 CPU(或其一个线程)上将脏位读取为 0,然后另一个 CPU(或同一 CPU 上的另一个线程)导致该位设置为1,但这并不奇怪。

From the AMD's manual (circa 2005), Volume 2: System Programming:

5.4 Page-Translation-Table Entry Fields ... Dirty (D) Bit. Bit 6. This bit is only present in the lowest level of the page-translation hierarchy. It indicates whether the pagetranslation
table or physical page to which this entry points has been written.
The D bit is set to 1 by the processor the first time there is a write
to the physical page.

Ditto from Intel (circa 2006), Volume 3-A: System Programming Guide, Part 1:

3.7.6 Page-Directory and Page-Table Entries ... Dirty (D) flag, bit 6 Indicates whether a page has been written to when set.
(This flag is not used in page-directory entries that point to page
tables.) Memory management software typically clears this flag when a
page is initially loaded into physical memory. The processor then sets
this flag the first time a page is accessed for a write operation.

UPDATE:

From the latest Intel manual (vol 3A, System Programming Guide):

8.1.2.1 Automatic Locking The operations on which the processor automatically follows the LOCK semantics are as follows: ... When
updating page-directory and page-table entries — When updating
page-directory and page-table entries, the processor uses locked
cycles to set the accessed and dirty flag in the page-directory and
page-table entries.

From the rest of the text in sections 8.1 and 8.2 it follows that once the CPU sets the dirty bit using the locked operation, the other CPUs should start seeing the updated value.

Of course, you may have a race condition in that you first read the dirty bit as 0 on one CPU (or in one of its threads) and later another CPU (or another thread on the same CPU) causes this bit to be set to 1, but that isn't any unusual.

高冷爸爸 2024-12-19 11:27:37

AMD64 架构程序员手册第 2 卷:系统编程(修订版 3.22,2012 年 9 月)

一般来说,脏位更新是相对于其他负载进行排序的
和商店,尽管不一定涉及厕所的使用
记忆;特别是,它们可能不会导致 WC 缓冲区被刷新。
然而,为了确保与未来处理器的兼容性,序列化
操作应在读取D位之前插入。

(强调我的。)

AMD64 Architecture Programmer’s Manual Volume 2: System Programming (revision 3.22, Sept. 2012)

In general, Dirty bit updates are ordered with respect to other loads
and stores, although not necessarily with respect to accesses to WC
memory; in particular, they may not cause WC buffers to be flushed.
However, to ensure compatibility with future processors, a serializing
operation should be inserted before reading the D bit.

(Emphasis mine.)

千柳 2024-12-19 11:27:37

根据 此文档,Intel x86缓存有关页表的信息。文中指出,如果脏位被软件清除,则CPU仍有可能将其视为等于1。

现在,对于问题:如果CPU缓存了脏位,则有可能对PTE进行更新(页表项)不会立即发生。它可能会被缓存写回策略延迟。

同一文档的第 1651 页描述了刷新内部高速缓存的 WBINVD 指令。它并没有说这包括CPU缓存的所有数据。

According to page 2033 of this document, Intel x86 caches information about the page table. The text states that if the dirty bit is cleaned by software, there's a possibility that the CPU still sees it as equal to 1.

Now, for the question: if the CPU caches the dirty bit, there's a possibility that the update to the PTE (page-table-entry) does not take place immediately. It could be delayed by a cache-write-back policy.

Page 1651 of the same document describes the WBINVD instruction, that flushes internal caches. It does not say that this includes all data cached by the CPU.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文