windows - 大内存块分配和 4K block

标签 windows memory virtual internals win64

请考虑 Mark Russiniovich 关于 Windows 内部结构的书籍中的这句话。这是关于大页面分配机制,用于在物理内存中分配大的非分页内存块

http://books.google.com/books?id=CdxMRjJksScC&pg=PA194&lpg=PA194#v=onepage

Attempts to allocate large pages may fail after the operating system has been running for an extended period, because the physical memory for each large page must occupy a significant number (see Table 10-1) of physically contiguous small pages, and this extent of physical pages must furthermore begin on a large page boundary. (For example, physical pages 0 through 511 could be used as a large page on an x64 system, as could physical pages 512 through 1,023, but pages 10 through 521 could not.) Free physical memory does become fragmented as the system runs. This is not a problem for allocations using small pages but can cause large page allocations to fail.

如果我没有理解错的话,他是说分散的 4K 页面产生的碎片会阻止在物理内存 中成功分配 2M 大页面。但为什么?普通的 4K 物理页很容易重定位,也很容易换出。换句话说,如果我们有一个未被其他 2M 页面占用的物理内存区域,我们总是可以“清理它”:通过将任何干扰 4K 页面从该物理内存区域重新定位到其他位置来使其可用。 IE。从“天真”的角度来看,2M 分配应该“总是成功”,只要我们有足够的可用物理 RAM。

我的逻辑有什么问题?当 Mark 说 4K 页面导致的物理内存碎片会阻止成功分配大页面时,他到底在说什么?

最佳答案

它在 Windows XP 中实际上是这样工作的。但是成本太高,而且 Vista 中的设计更改禁用了这种方法。在 this blog post 中解释得很好,我将引用重要部分:

In Windows Vista, the memory manager folks recognized that these long delays made very large pages less attractive for applications, so they changed the behavior so requests for very large pages from applications went through the "easy parts" of looking for contiguous physical memory, but gave up before the memory manager went into desperation mode, preferring instead just to fail.

关于windows - 大内存块分配和 4K block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21999406/

相关文章:

c++ - 如何正确使用 _snprintf_s()?

python - 如何在主进程退出后保持子进程运行?

c++ - Visual Studio 2012 错误 0xC0000005 数组输出

c++ - 在所有架构上 sizeof(float) 总是等于 sizeof(int) 吗?

c++ - "virtual base class in the case of multilevel inheritance"有意义吗

c++ - 像 ListView 这样的资源管理器

java - 无法弄清楚如何设置 java.library.path

java - JDBC 连接池内存问题(Java EE 应用程序)

c++ - MSVC 对象布局怪癖

php - Python 相当于 php 的 virtual()