Re: sharing memory map between processes (same parent)



In article <fv2m7o01es1@xxxxxxxxxxxxxxxxx>, phil-news-nospam@xxxxxxxx
wrote:

I have forked two processes from the same parent. I'd like to have one of
them
do open() and mmap() to map a file into memory (madvise would also be used).
Then I would like the other process to be able to access that mapping. Is
there a way to get that mapping shared with another process (much like it
would be had the parent mapped it first then forked the two child processes)
or at least transfer the mapping from one process to another? Note that it
will not necessarily be a mapping of the entire file, and the first process
may be keeping the descriptor open for later mapping of another part of the
file. Also, it may be possible to make it so the first process never does
any access of the mapped pages.

I don't know of any way to transfer a mapping. Processes don't
generally have the ability to change anything about other properties,
other than through low-level manipulation like ptrace().

Why not just have both processes mmap() the same file?

--
Barry Margolin, barmar@xxxxxxxxxxxx
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
.



Relevant Pages

  • [PATCH, RFD] Unbreaking nommu mmap, v2
    ... A while ago I sent out a patch to change mmap behaviour on nommu targets. ... Currently, the kernel requires a munmap call for every mmap, with the exact same address range; this is inconsistent with behaviour on mmu systems, and complicates the malloc implementation in uClibc. ... Every VMA can be in two states: either it manages a power-of-2 sized compound ... mapping we're capable of supporting ...
    (Linux-Kernel)
  • Re: sharing memory map between processes (same parent)
    ... | 'warm the cache' by getting the inode into memory. ... It might make a difference if the memory remained mapped to some process ... How about we take a look at the approximate steps that mmap needs to ... So, whether the mapping is transferred to a second process, or the second ...
    (comp.unix.programmer)
  • Re: sharing memory map between processes (same parent)
    ... |> I don't know what you mean by slave processes. ... Of course mmap() needs ... file mapping. ... The amount of work for the kernel ...
    (comp.unix.programmer)
  • Re: sharing memory map between processes (same parent)
    ... reference in terms of an open descriptor because the descriptor can be ... closed after mmap(), and the file is still mapped. ... | file content has been loaded into memory, and it won't be until referenced. ... | So, whether the mapping is transferred to a second process, or the second ...
    (comp.unix.programmer)
  • Re: sharing memory map between processes (same parent)
    ... |> I have forked two processes from the same parent. ... |> Then I would like the other process to be able to access that mapping. ... it may be possible to make it so the first process never does ... | Why not just have both processes mmap() the same file? ...
    (comp.unix.programmer)