本文介绍了是否具有MAP_NORESERVE储备物理内存的mmap?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

借助文档说以下有关旗MAP_NORESERVE。

The mmap documentation says following about the flag MAP_NORESERVE.

不要预留交换空间这种映射。当交换空间
  保留一有保证,这是可以修改
  映射。当交换空间不保留了一个后可能损害得到SIGSEGV
  写如果没有物理内存可用。

我真正想要的是只保留虚拟内存地址,没有实际的物理内存分配。可这与MAP_NORESERVE MMAP做什么?如果我想使用的任何物理内存,我会再次MAP_FIXED的mmap它的地址范围之一通过与MAP_NORESERVE的MMAP获分配之内。

What I want actually is to only reserve virtual memory addresses and not have actual physical memory allocated. Can this be done with mmap with MAP_NORESERVE? If I want to use any physical memory, I would mmap it again with MAP_FIXED in the address range within the one alloted through the mmap with MAP_NORESERVE.

要总结,我想内核没有保留任何物理页面与MAP_NORSERVE标志的mmap分配的内存。它是否真的像这样工作还是做内核分配物理页面,如果它有足够的物理内存?

To summarize, I want the kernel to not reserve any physical page for memory allocated with mmap with MAP_NORSERVE flag. Does it really work like this or do the kernel allocates physical pages if it has enough physical memory?

推荐答案

mmap()的是管理{地址,物理内存,磁盘块}该协会的三名成员是资源之间的关系的方式之一。该协会保持页表项内(PTE公司)

Mmap() is one of the ways to manage the association between {address, Physical memory, disk-blocks} All three members of this association are resources. The association is kept inside Page Table Entries (PTE's)

什么mmap()的实际执行,方法是:

What mmap() actually does, is:


  • [也许]分配用户进程内的地址范围。此范围必须包含连续的地址(不应该与现有范围重叠)

  • 请求的范围内创建的PTE并使其指向地址范围内页

  • 请在PTE的指向文件被mmap()的主编

  • [也许]分配和prefetch(部分)页

  • [也许]储备一些后备存储。

很多(3出5)上述步骤是可选的,并依赖于mmap()的调用提供的实际参数和标志。 (在FD可能是-1:创建一个匿名的映射,启动ADRESS可以为NULL:MMAP应该pviously分配($ P $)的内存使用的范围)

Many (3 out of 5) of the above steps are optional and depend on the actual arguments and flags supplied in the mmap() call. (the fd may be -1: creating an anonymous mapping, the start-adress may be NULL: mmap should allocate a (previously) unused range of memory)

在调用mmap()的,在内核中的页缺失处理程序应该能够找出该怎么做。 (附加物理内存的页面;冲洗和分离;分配和牛,...)

After a call to mmap(), the pagefault-handler inside the kernel should be able to find out what to do. (attach physical ram to a page; flush and detach; allocate and COW, ...)

的保留交换空间是指主叫相信,会有足够的交换空间的在任何时间在未来的。交换空间是由所有进程共享的,所以永远不能保证有足够的了。 preallocating它(或多或少)给出的担保调用进程的将始终有足够的了。 (不用时:保留mmap()会失败)

not reserving swapspace means that the caller trusts that there will be enough swap space at any time in the future. Swap space is shared by all the processes, so there can never be a guarantee that there is enough of it. Preallocating it (more or less) gives a guaranty that the calling process will always have enough of it. (when not: the mmap() should have failed)

这篇关于是否具有MAP_NORESERVE储备物理内存的mmap?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 23:37