23、深入理解電腦系統筆記,虛擬儲存空間,儲存空間映射

來源:互聯網
上載者:User

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.

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.只要有一個進程試圖寫私人地區內的某個頁面,那麼這個寫操作就會觸發一個保護原則。它就會在實體儲存體器中建立這個頁面的一個新拷貝,更新頁麵條目指向這個新的拷貝,然後恢複這個頁面的可寫入權限。

process 2 writes to a page in the private area

4、unix進程可以使用mmap函數來建立新的虛擬儲存空間地區,並將對象映射到這些地區中。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.