Z
Z
zodiac2012-12-08 22:38:33
linux
zodiac, 2012-12-08 22:38:33

Virtual memory in Linux?

Two processes can share a memory mapping, that is, two processes can use the same pages of physical memory loaded with data from a file, provided that the following conditions are met in both processes:

  • The mapping is readable but not writable.
  • The mapping is of type 'Private copy on write'.
  • The mapping starts at the same file offset and has the same size.
  • The mapping is relative to a file, i.e. the device number and inode number are not 0.
  • The mapping refers to the same file, that is, the device number and inode number are equal.

Do I understand correctly that for sharing a display within a single process, the requirements are exactly the same?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
J
jcmvbkbc, 2012-12-09
@jcmvbkbc

Under what conditions are two regions in the same process mapped to the same physical memory?

The mapping is readable but not writable.

- Yes.
The mapping is of type 'Private copy on write'.

— yes, if there were no records in this region.
If the mapping is of type shared, the physical pages reside in the page cache and are shared by all processes that map the file to memory as shared, as well as file systems that read from and write to it.

G
Gribozavr, 2012-12-09
@gribozavr

Within a single process, all memory is always shared.

A
Alexey Huseynov, 2012-12-09
@kibergus

I think it should be common. But you can, just in case, check: make two mmap'a in one process and see the amount of memory used.
But, perhaps, it is worth considering that the application does mmap once and then transfer pointers to memory to those places where the file is used.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question