Linux memory mapped files

sys463

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
ctrl-alt-delor

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.

So how is this done?

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.

edited at
0

Comments

0 comments
Login to comment

Related

What are memory mapped files?

Memory-mapped files in Java

Linking boost memory mapped files

Java Memory-mapped files?

Atomic operations on memory mapped files

Are multiple memory mapped files bugged?

Do memory mapped files in Docker containers in Kubernetes work the same as in regular processes in Linux?

Monitoring page cache / memory mapped files access

Memory-mapped files: pros and cons?

Named memory-mapped files in Python?

How to create and write to memory mapped files?

memory mapped files and pointers to volatile objects

Is boost memory mapped file zeroed on Linux

Questions about anonymous mapped memory in linux

How To Use Memory Mapped File in Python Linux

Observing shared mapped file memory in linux

How to work with memory mapped files (numpy.memmap) in PyFilesystem?

How to share memory mapped files between Python and another language?

Is it possible to store python objects (specifically sklearn models) in memory mapped files?

What updates mtime after writing to memory mapped files?

Do memory mapped files provide advantage for large buffers?

Advantages to using FILE_FLAG_NO_BUFFERING with memory mapped files?

Access non-persisted memory-mapped files

Memory-Mapped Files & Transparent Persistence of Java Objects

Correct way to dispose memory mapped files in C#

IPC Using Protobuf and Memory Mapped Files C#

Function address not in the range of memory-mapped files for the lisp image process

Can I pass a pointer using memory mapped files?

WRITE and READ memory mapped device registers in Linux on ARM