简体   繁体   English

澄清虚拟内存-分配大的连续内存

[英]Virtual memory clarification - allocation of large contiguous memory

I have an application where I have to allocate on Windows (using operator new) quite a large memory space (hundreds of MB). 我有一个应用程序,我必须在Windows上分配很大的内存空间(数百MB)(使用operator new)。 The application is 32 bit (we don't use 64 bit for now, even on 64 bit systems) and I enabled /LARGEADDRESSAWARE linker option to be able to use 4 GB of user space memory. 该应用程序是32位的(即使在64位系统上,我们现在也不使用64位),并且我启用了/ LARGEADDRESSAWARE链接器选项,以便能够使用4 GB的用户空间内存。

Question If I need to allocate, say 450 MB of contiguous memory does the virtual address space of the process need to have a contiguous large enough space and additionally the physical memory does not have to be fragmented on the system ? 问题如果我需要分配,例如说450 MB的连续内存,进程的虚拟地址空间是否需要具有足够大的连续连续空间而且物理内存不必在系统上分割? I ask this because I can make it so that my application reserves a large enough contiguous space but don't know if other applications on the system can affect me in this way. 我之所以这样问,是因为我可以这样做,以便我的应用程序保留足够大的连续空间,但是不知道系统上的其他应用程序是否会以这种方式影响我。 Does OS page tables need to translate contiguous virtual addresses seen by the application into contiguous physical addresses ? OS页表是否需要将应用程序看到的连续虚拟地址转换为连续物理地址?

If the memory is simply used in your software, then your 450MB allocation will only need a hole of 450MB in the virtual space. 如果仅在您的软件中使用内存,那么您的450MB分配将只需要在虚拟空间中留出450MB的空间。 It can be satisfied with pages from every corner of the memory system [as long as there is at least 450MB available somewhere in the system - including swapspace]. 内存系统各个角落的页面都可以满足[只要系统中某处至少有450MB可用空间-包括交换空间]。

Your system will get a little bit better performance if the OS is able to allocate the pages in contiguous blocks of 2MB a piece [using "large pages" of 2MB at a time]. 如果操作系统能够以每块2MB的连续块分配页面(一次使用2MB的“大页面”),则系统将获得更好的性能。 But the system will fall back to individual 4KB pages if it needs to. 但是如果需要,系统将退回到单个4KB页面。

One of several benefits with a paged memory architecture is that any physical page can be placed at any virtual address. 分页内存体系结构的几个好处之一是,任何物理页都可以放在任何虚拟地址上。 In some systems, for example Xen virutalization manager in Debug mode, pages are INTENTIONALLY allocated out of sequence, to make it easier to detect when the system makes assumptions about memory pages being contiguous. 在某些系统中,例如在Debug模式下的Xen虚拟化管理器,页面是按顺序故意分配的,以使系统在有关内存页面的假设连续时更容易检测到。

You don't need to be concerned about contiguity of the physical memory. 您无需担心物理内存的连续性。 That's one thing that virtual to physical address translation helps you with. 这是虚拟地址到物理地址转换可以帮助您的一件事。 As long as you can reserve a chunk of the address space and back it with physical memory, wherever it happens to be, things are going to work. 只要您可以保留一部分地址空间并用物理内存备份它,无论它在哪里,事情都将起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM