When we map a file to memory, a system call is required. Do subsequent accesses to the file require system calls or is the virtual memory page of the process mapped to the actual page cache in memory?
update: what i also want to know is that if multiple processes are accessing the same file through mmap. they will be accessing the same physical memory portion write.
No need for additional system calls ( by your process ), you just access it like regular memory. When you're done with the file, just call munmap
.
Return Value
On success,
mmap()
returns a pointer to the mapped area. On error, the valueMAP_FAILED
(that is, (void *) -1) is returned, and errno is set appropriately. On success,munmap()
returns 0, on failure -1, anderrno
is set (probably toEINVAL
).
See the man page here for details.
Edit For clarification:
I'm saying that the function maps the file into the calling process's memory space and returns a pointer to the beginning of the memory block.
For example, if you have two different processes map the same file with the MAP_SHARED
flag then each process will be accessing the same physical memory, but that memory may be mapped at a different location in each process's virtual memory space, i.e. the pointers returned by mmap in each process's virtual memory space may not be equal.
This brings up the point that if you for instance need to store pointers inside the shared memory block those pointers would only be useful if they were stored as offsets relative to the beginning of the block / file and they would only be able to usefully point to locations internal to the block / file.