zoukankan      html  css  js  c++  java
  • 23、深入理解计算机系统笔记,虚拟存储器,存储器映射

    1、Linux通过将一个虚拟存储器区域与一个磁盘上的对象(object)关联起来,以初始化这个虚拟存储器区域的内容,这个过程称为存储器映射(memory mapping)。虚拟存储器区域可以映射到两种类型的对象:

    1)unix文件系统中的普通文件:一个区域可以映射到一个普通磁盘文件的连续部分。

    2)匿名文件:一个区域也可以映射到一个匿名文件,匿名文件是由内核创建的,包含的全是二进制零。

        一旦一个虚拟页面被初始化了,它就在一个由内核维护的专门的交换文件(swap file)间换来换去。

    2、共享对象

        一个对象可以被映射到虚拟存储器的一个区域,要么作为共享对象,或作为私有对象。If a process maps a shared object into an area of its virtual address space, then any writes that the process makes to that area are visible to any other processes that have also mapped the shared object into their virtual memory. Further, the changes are also reflected in the original object on disk.

    Changes made to an area mapped to a private object, on the other hand, are not visible to other processes, and any writes that the process makes to the area are not reflected back to the object on disk. A virtual memory area that a shared object is mapped into is often called a shared area. Similarly for a private area.

    wps_clip_image-8344[4]

    A shared object. (a) After process 1 maps the shared object. (b) After process 2 maps the same shared object. (Note that the physical pages are not necessarily contiguous.)

    3、私有对象,写时拷贝(copy-on-write)

        私有对象是使用一种叫做写时拷贝的技术被映射到虚拟存储器中的。如图中所示:two processes have mapped a private object into different areas of their virtual memories, but share the same physical copy of the object. For each process that maps the private object, the page table entries for the corresponding private area are flagged as read-only, and the area struct (vm_area_struct) is flagged as private copy-on-write.只要有一个进程试图写私有区域内的某个页面,那么这个写操作就会触发一个保护策略。它就会在物理存储器中创建这个页面的一个新拷贝,更新页面条目指向这个新的拷贝,然后恢复这个页面的可写权限。

    wps_clip_image-28980[4]

    process 2 writes to a page in the private area

    4、unix进程可以使用mmap函数来创建新的虚拟存储器区域,并将对象映射到这些区域中。

  • 相关阅读:
    Effective C++笔记:继承与面向对象设计
    华为手机连不上adb解决方法
    android手机出现sqlite3 not found的解决方法
    adb permission denied
    Apache2.4为什么启动报错Cannot load php5apache2_4.dll into server
    界面排版-TableLayout的stretchColumns方法
    java中静态代码块的用法 static用法详解(转)
    Activity not started, its current task has been brought to the front
    (转)在低版本的SDK里使用高版本函数@SuppressLint("NewApi") or @TargetApi?
    Android笔记:解决 Your project contains error(s),please fix them before running your application问题
  • 原文地址:https://www.cnblogs.com/mydomain/p/2090451.html
Copyright © 2011-2022 走看看