我可以从一个进程的PTE这表明物理内存碎片等过程中创造适当的PTE? [英] Can I with PTEs from one process which indicate to fragments of physical memory to create appropriate PTEs in other process?

查看:175
本文介绍了我可以从一个进程的PTE这表明物理内存碎片等过程中创造适当的PTE?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们在Linux中使用功能的mmap(,,, MAP_ANON | MAP_SHARED); ,然后分段物理内存(其中分配)的相同区域的进程之间分配虚拟内存页面(PTE的)。即这些PTE的是从页表中复制一个进程到另一个进程的页表(与物理地址分配的内存片段的顺序相同),这是真的吗?

的mmap()之前需要要做叉()。如果我们已经有两个工作的过程中(即在叉()),那么我们需要使用的文件作为 mmap()的。用于复制两个已经建立的过程之间的PTE机制,创建共享内存哪些功能?

我可以用的PTE / SGL(分散 - 集中列表),它指示已通过使用Linux内核分配在其他过程中创造适当的PTE的物理内存碎片,该怎么办呢?

我想了解如何的mmap()在较低水平的作品。


解决方案

  

当我们在Linux中使用功能的mmap(,,, MAP_ANON | MAP_SHARED); ,然后
  对于零散物理内存的同一区域(其中分配)
  流程之间分配的虚拟内存页面(PTE的)。


重述问题/声明,请,上面没有任何意义。


  

即这些PTE的是从一个进程的页表复制到页
  另一种方法的表(用的片段的相同序列
  物理地址分配的内存),这是真的吗?


没有,这是不正确的。

当您建立一个新的映射,​​内核首先查找
在进程的虚拟地址空间中的足够大的未使用的地址范围。然后,它修改相应的页表项,以表明该地址范围是有效的,但物理页有没有present。

当你试图在这个范围内访问一个地址时,会产生一个页面错误。内核看起来在其数据结构,并且确定所述访问是否有效。然后,它分配一个
新鲜的物理页面,修改页面进入建立之间的映射
虚拟地址和物理地址和标志的页面present。当从返回
页面故障异常,违规指令重新启动,这一次成功执行。


  

但是需要叉之前完成MMAP()()。如果我们已经有
  两个工作过程中(即后叉()),那么我们需要使用一个文件
  保留mmap()。用于之间进行复制的PTE机制功能
  这两个已经建立的过程,以创建共享内存?


如果你做了 MMAP 之后,这两个进程将创建和初始化
完全彼此独立的页表条目。然而,当你 MMAP 的文件,
内核将不会分配只是一个免费的物理页 - 这将分配一个页面,
从文件中的数据填充它,并把该页面在页面/缓冲区高速缓存。当第二
过程mmaps相同的文件,内核看起来在页面缓存中,发现有物理
页,其对应的同一文件和所需的文件偏移量和点PTE
到该页面。现在,将有两个完全独立创建PTE,刚刚指向同一个物理页。


  

我可以用的PTE / SGL(分散 - 集中列表),它指示片段
  其中已分配给创建适合物理内存
  PTE的在使用Linux内核,以及如何做到这一点其他的过程吗?


重述这也,这是你的要求不明确的东西。


  

我想了解它的mmap()如何工作在一个较低的水平。


我会建议一个操作系统的书,对虚拟内存管理一章,
像<一个href=\"http://www.amazon.co.uk/Operating-System-Concepts-Abraham-Silberschatz/dp/1118112733/ref=sr_1_5?ie=UTF8&qid=1386065707&sr=8-5&keywords=Operating%20System%20Concepts,%20by%20Silberschatz,%20Galvin,%20and%20Gagne\"相对=nofollow>由Silberschatz EL AL操作系统概念。

<一个href=\"http://www.amazon.co.uk/Operating-System-Concepts-Abraham-Silberschatz/dp/1118112733/ref=sr_1_5?ie=UTF8&qid=1386065707&sr=8-5&keywords=Operating+System+Concepts%2C+by+Silberschatz%2C+Galvin%2C+and+Gagne\" rel=\"nofollow\">http://www.amazon.co.uk/Operating-System-Concepts-Abraham-Silberschatz/dp/1118112733/ref=sr_1_5?ie=UTF8&qid=1386065707&sr=8-5&keywords=Operating+System+Concepts%2C+by+Silberschatz%2C+Galvin%2C+and+Gagne

When we in Linux use function mmap (,,, MAP_ANON | MAP_SHARED);, then for the same region of fragmented physically memory (which allocated) between processes are allocating virtual memory pages (PTEs). Ie these PTEs are copied from page table of one process to the page table of another process (with the same sequence of fragments of physical addresses allocated memory), is this true?

But mmap () needs to be done before fork (). And if we already have two working process (ie after fork ()), then we need to use a file for the mmap(). Which functions used to copying mechanism of PTEs between the two already established processes to create a shared memory?

Can I with PTEs/SGL(scatter-gather-list) which indicate to fragments of physical memory which have been allocated to create appropriate PTEs in other process by using linux-kernel, and how to do it?

I want to understand how it mmap() works at a lower level .

解决方案

When we in Linux use function mmap (,,, MAP_ANON | MAP_SHARED);, then for the same region of fragmented physically memory (which allocated) between processes are allocating virtual memory pages (PTEs).

Restate the question/statement, please, the above does not make sense.

Ie these PTEs are copied from page table of one process to the page table of another process (with the same sequence of fragments of physical addresses allocated memory), is this true?

No, it is not true.

When you establish a new mapping, a kernel first looks for a sufficiently large unused range of addresses in the virtual address space of the process. Then it modifies the corresponding page table entries to indicate that that address range is valid, but physical pages there are not present.

When you attempt to access an address in that range, a page fault is generated. The kernel looks in its data structures and determines that the access is valid. Then it allocates a fresh physical page, modifies the page entry to establish the mapping between the virtual address and the physical address and marks the page as present. Upon return from the page fault exception, the offending instruction is restarted and this time executes successfully.

But mmap () needs to be done before fork (). And if we already have two working process (ie after fork ()), then we need to use a file for the mmap(). Which functions used to copying mechanism of PTEs between the two already established processes to create a shared memory?

If you do a mmap after the fork, the two processes will create and initialize page table entries entirely independent of each other. However, when you mmap a file, the kernel will not allocate simply a free physical page - it will allocate a page, fill it with data from the file and put the page in the page/buffer cache. When a second process mmaps the same file, the kernel looks in the page cache, finds there the physical page, which corresponds the the same file and the required file offset and points the PTE to that page. Now, there will be two completely independently created PTE, which just point to the same physical page.

Can I with PTEs/SGL(scatter-gather-list) which indicate to fragments of physical memory which have been allocated to create appropriate PTEs in other process by using linux-kernel, and how to do it?

Restate this too, it's not clear what you are asking.

I want to understand how it mmap() works at a lower level .

I would recommend an operating systems book, a chapter on virtual memory management, something like Operating System Concepts by Silberschatz el al.

http://www.amazon.co.uk/Operating-System-Concepts-Abraham-Silberschatz/dp/1118112733/ref=sr_1_5?ie=UTF8&qid=1386065707&sr=8-5&keywords=Operating+System+Concepts%2C+by+Silberschatz%2C+Galvin%2C+and+Gagne

这篇关于我可以从一个进程的PTE这表明物理内存碎片等过程中创造适当的PTE?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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