Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.os.linux.development.system > #814
| From | Rainer Weikusat <rweikusat@talktalk.net> |
|---|---|
| Newsgroups | comp.os.linux.development.system |
| Subject | Re: Understanding the working of Shared memory using mmap() |
| Date | 2023-03-13 17:35 +0000 |
| Message-ID | <87h6uomu5v.fsf@doppelsaurus.mobileactivedefense.com> (permalink) |
| References | <6ad837bd-745e-4b01-b19c-0acf88687d9dn@googlegroups.com> |
Pavankumar S V <pavankumarsv96@gmail.com> writes: > As per my understanding, I can explain the working of mmap() briefly > like this: When a process(let's call it process1) calls mmap on a > regular file, that file is first copied to the page cache. Then the > region of page cache which contains the file is mapped to virtual > address space of the process1(This memory region is called > memory-mapped file). If another process(let's call it process2) calls > mmap on the same file, then the same page cache that was mapped to > process1 will get mapped to the virtual address space of process2. > When the processes wants to access the file, they simply access this > memory mapped file which is very faster. Also the data modified by > process1 can be seen by process2. It *may* be faster. But address space manipulations, page faults occurring while populating some part of the virtual address space of a process and cache- and TLB-misses are all expensive operations, hence, it may well be not. > I have a query here. Please clarify it: > When the process1 wants to write some data to the file, it will write > to this memory mapped file. Then these dirty pages that are private to > the process1 should be copied to the page cache. When will the kernel > do this copying to page cache and how frequently? Not at all. If the mapping is done as MAP_PRIVATE, the process will gets its own copy of each page as soon as it starts writing to it. For MAP_SHARED mappings, all processes mapping the same file plus the kernel page cache will write to the same page.
Back to comp.os.linux.development.system | Previous | Next — Previous in thread | Find similar
Understanding the working of Shared memory using mmap() Pavankumar S V <pavankumarsv96@gmail.com> - 2023-03-09 04:19 -0800 Re: Understanding the working of Shared memory using mmap() Richard Kettlewell <invalid@invalid.invalid> - 2023-03-10 16:30 +0000 Re: Understanding the working of Shared memory using mmap() Rainer Weikusat <rweikusat@talktalk.net> - 2023-03-13 17:35 +0000
csiph-web