Where is linux shared memory actually located?

前端 未结 1 1354
别那么骄傲
别那么骄傲 2020-12-30 07:34

I just wanted to know where shared memory resides in a Linux system? Is it in physical memory or virtual memory?

I am aware about the process\'s virtual memory send

相关标签:
1条回答
  • 2020-12-30 08:16

    All memory that is committed is physical.

    However processes cannot address physical memory directly. They have virtual addresses which the kernel will resolve to physical addresses. When a shared memory region is setup, the same physical memory location is addressed by the multiple processes. However the virtual addresses can be different though. Each process uses the virtual address it received only in its own context. Both the virtual addresses refer to the same physical memory.


    To elaborate, in case of a shared memory region, the same physical memory address is addressable by multiple processes simultaneously as both the processes have virtual addresses that point to the same physical address.

    For example consider the following :

    • virtual address V1 ( in process T1 context)
    • virtual address V2 ( in process T2 context)

    are both pointing to the shared memory region.
    This is actually a common physical address P.

    Now,
    Process T1 referencing virtual address V1
    OR
    Process T2 referencing virtual address V2

    will result in an access to physical address P as the kernel translates both the virtual address locations to the same physical location in memory.


    For example, in the following diagram, the physical memory PFN4 is shared by processes X and Y using VPFN3 and VPFN1 in their respective contexts (PFN stands for Page Frame Number).

    Virtual memory maps for 2 processes

    0 讨论(0)
提交回复
热议问题