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.