虚拟内存澄清 - 大容量连续内存的分配 [英] Virtual memory clarification - allocation of large contiguous memory

查看:64
本文介绍了虚拟内存澄清 - 大容量连续内存的分配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,我必须在 Windows 上(使用 operator new)分配相当大的内存空间(数百 MB).该应用程序是 32 位的(我们现在不使用 64 位,即使在 64 位系统上也是如此)并且我启用了/LARGEADDRESSAWARE 链接器选项以便能够使用 4 GB 的用户空间内存.

I have an application where I have to allocate on Windows (using operator new) quite a large memory space (hundreds of MB). 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.

问题如果我需要分配 450 MB 的连续内存,进程的虚拟地址空间是否需要有足够大的连续空间另外还有物理空间?内存不必在系统上碎片化?我问这个是因为我可以这样做,以便我的应用程序保留足够大的连续空间,但不知道系统上的其他应用程序是否会以这种方式影响我.操作系统页表是否需要将应用程序看到的连续虚拟地址转换为连续物理地址?

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 ? 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 ?

推荐答案

如果内存只是在你的软件中使用,那么你的 450MB 分配只需要在虚拟空间中留出 450MB 的空洞.它可以满足来自内存系统每个角落的页面[只要系统中某处至少有 450MB 可用 - 包括交换空间].

If the memory is simply used in your software, then your 450MB allocation will only need a hole of 450MB in the virtual space. 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].

如果操作系统能够以 2MB 的连续块分配页面[一次使用 2MB 的大页面"],您的系统将获得更好的性能.但如果需要,系统将回退到单个 4KB 页面.

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]. But the system will fall back to individual 4KB pages if it needs to.

分页内存架构的几个好处之一是任何物理页面都可以放置在任何虚拟地址.在某些系统中,例如处于 Debug 模式的 Xen 虚拟化管理器,页面被故意乱序分配,以便更容易检测系统何时假设内存页面是连续的.

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.

这篇关于虚拟内存澄清 - 大容量连续内存的分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆