23. in-depth understanding of computer system notes, virtual memory, and memory ing

Source: Internet
Author: User

1. Linux associates a virtual memory area with an object on a disk to initialize the content of the virtual memory area. This process is called memory mapping ). The virtual memory area can be mapped to two types of objects:

1) common files in UNIX file systems: a region can be mapped to the continuous part of a common disk file.

2) Anonymous File: a region can also be mapped to an anonymous file. The anonymous file is created by the kernel and contains binary zero.

Once a virtual page is initialized, It is exchanged between a dedicated swap file maintained by the kernel.

2. shared object

an object can be mapped to an area of virtual storage, either as a shared object or as a private object. 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. Private object: Copy-on-write)

Private objects are mapped to virtual memory using a technique called copy-at-write. As shown in: 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 flaggedRead-Only, And the area struct (vm_area_struct) is flagged as private copy-on-write. if a process tries to write a page in a private zone, this write operation triggers a protection policy. It creates a new copy of the page in the physical storage, updates the page entry to the new copy, and restores the writeable permission on the page.

Process 2 writes to a page in the private area

4. UNIX processes can use the MMAP function to create new virtual memory regions and map objects to these regions.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.