Suppose I:
opena read-only fileFofNbyte length from a processAmmapitsfdread-only (PROT_READ) andMAP_SHAREDmlockthe returned memory range.- go into an infinite loop.
My understanding is the data from the file is now resident and backed by N bytes of physical memory pages, due to the mlock. The read performance of the memory range should be the same as normal memory allocated with, say, malloc.
Now, if I create a second process B while the process A is still running and do exactly the same steps from process B, will the N bytes of physical memory pages that back the mmaped file be the same physical pages from process A?
That is, will A and B together use N bytes of physical memory? Or will they use 2*N bytes of physical memory?
vmtouchfor a command that does this intentionally.mmapunintentionally?vmtouch -lintentionally 1)open()'s, 2)mmap()s, 3)mlock()s and 4) "goes into an infinite loop"/waits indefinitely, precisely as OP described, for precisely one of the effects OP was wondering about: Allowing other processes to use this memory knowing it has been prefaulted in.