Output of lsof
on my RHEL7 shows that one file with file descriptor mem
is used by 40 processes. Does it mean that this file is mapped in memory 40 times or what? Could someone please explain what does memory mapped files mean? Does it mean that it 40 times in my memory?
# lsof /usr/lib/locale/locale-archive COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME vmtoolsd 605 root mem REG 8,5 106070960 50808629 /usr/lib/locale/locale-archive agetty 656 root mem REG 8,5 106070960 50808629 /usr/lib/locale/locale-archive tuned 963 root mem REG 8,5 106070960 50808629 /usr/lib/locale/locale-archive iostat 1199 adm mem REG 8,5 106070960 50808629 /usr/lib/locale/locale-archive chkMtaMem 1205 root mem REG 8,5 106070960 50808629 /usr/lib/locale/locale-archive snmpd 4704 root mem REG 8,5 106070960 50808629 /usr/lib/locale/locale-archive sleep 5461 root mem REG 8,5 106070960 50808629 /usr/lib/locale/locale-archive cmsubagt 6487 root mem REG 8,5 106070960 50808629 /usr/lib/locale/locale-archive sleep 6649 root mem REG 8,5 106070960 50808629 /usr/lib/locale/locale-archive proc1 6803 root mem REG 8,5 106070960 50808629 /usr/lib/locale/locale-archive proc2 6835 root mem REG 8,5 106070960 50808629 /usr/lib/locale/locale-archive proc3 6836 root mem REG 8,5 106070960 50808629 /usr/lib/locale/locale-archive proc4 6856 root mem REG 8,5 106070960 50808629 /usr/lib/locale/locale-archive proc5 6884 root mem REG 8,5 106070960 50808629 /usr/lib/locale/locale-archive proc6 6889 usr mem REG 8,5 106070960 50808629 /usr/lib/locale/locale-archive proc7 6893 usr1 mem REG 8,5 106070960 50808629 /usr/lib/locale/locale-archive cmfpagt 7704 root mem REG 8,5 106070960 50808629 /usr/lib/locale/locale-archive proc8 7943 root mem REG 8,5 106070960 50808629 /usr/lib/locale/locale-archive crond 8001 root mem REG 8,5 106070960 50808629 /usr/lib/locale/locale-archive sh 8005 adm mem REG 8,5 106070960 50808629 /usr/lib/locale/locale-archive iostat 8014 adm mem REG 8,5 106070960 50808629 /usr/lib/locale/locale-archive crond 20427 root mem REG 8,5 106070960 50808629 /usr/lib/locale/locale-archive proc9 20648 root mem REG 8,5 106070960 50808629 /usr/lib/locale/locale-archive proc10 20649 root mem REG 8,5 106070960 50808629 /usr/lib/locale/locale-archive proc10 20760 usr2 mem REG 8,5 106070960 50808629 /usr/lib/locale/locale-archive proc9 20777 usr2 mem REG 8,5 106070960 50808629 /usr/lib/locale/locale-archive proc11 21353 root mem REG 8,5 106070960 50808629 /usr/lib/locale/locale-archive proc12 21354 root mem REG 8,5 106070960 50808629 /usr/lib/locale/locale-archive proc13 21355 root mem REG 8,5 106070960 50808629 /usr/lib/locale/locale-archive proc14 21356 root mem REG 8,5 106070960 50808629 /usr/lib/locale/locale-archive proc15 21357 root mem REG 8,5 106070960 50808629 /usr/lib/locale/locale-archive proc16 21358 root mem REG 8,5 106070960 50808629 /usr/lib/locale/locale-archive proc17 21554 root mem REG 8,5 106070960 50808629 /usr/lib/locale/locale-archive proc18 21569 usr2 mem REG 8,5 106070960 50808629 /usr/lib/locale/locale-archive proc19 21590 usr2 mem REG 8,5 106070960 50808629 /usr/lib/locale/locale-archive proc20 21647 usr2 mem REG 8,5 106070960 50808629 /usr/lib/locale/locale-archive proc21 22016 root mem REG 8,5 106070960 50808629 /usr/lib/locale/locale-archive proc22 22017 root mem REG 8,5 106070960 50808629 /usr/lib/locale/locale-archive proc23 22104 usr2 mem REG 8,5 106070960 50808629 /usr/lib/locale/locale-archive proc24 22122 usr2 mem REG 8,5 106070960 50808629 /usr/lib/locale/locale-archive
Have a look at the difference between virtual and physical memory.
Many processes can map the same physical memory. If 10 processes map the same file, then at most one copy will be cached in RAM.
If memory is not-shared, then if one process changes it, then this one page (with the change), is duplicated before committing the write. (So not all of the memory is copied. This is called copy on write or COW).
A memory mapped file is when you ask the OS to map a file into memory. It does not load the file until you start reading/writing and then only what is needed. Memory mapping is just a different interface to read/write/seek/etc. You can also access memory through read/write/seek.
It is done by realizing that some things are the same: That is swap and files are the same; and ram and file cache are the same. So when you open a file it is mapped as swap (don't worry it won't be used to swap out other stuff). When you start reading a seg-fault is generated, and the OS swaps it in, from the file (The exception (seg-fault) is handled by the OS so not passed on to a process) (actually it is not a segmentation fault, it is a page fault). It does not matter what interface you use memory or file. They are just interfaces over the same functionality.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments