Search code examples
linuxfilesystemsembedded-linuxtmpfs

why tmpfs used shared memory


this is output of df command in my embedded linux:

root@mcu-v1:~# df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/root               160.0M    116.7M     43.3M  73% /
devtmpfs                 61.0M         0     61.0M   0% /dev
tmpfs                    61.0M     80.0K     61.0M   0% /run
tmpfs                    61.0M      9.1M     52.0M  15% /var/volatile
/dev/mtdblock2           96.0M      3.0M     93.0M   3% /mnt/app

when I monitor state of memory with free command I see that every file that I copy to /var/volatile used shared memory and shared memory increasing. my log stores in this directory and after some our my free memory increased because of increasing shared memory!

why tmpfs file system used shared memory ? What processes is this memory shared between?


Solution

  • It's called "Shmem" because tmpfs started as shmfs, the pool from which shared anonymous mappings and SYSV shared memory were taken, and was later exported as a filesystem:

    1. Some people (including me) find it very convenient to mount it
      e.g. on /tmp and /var/tmp and have a big swap partition.

    That link also calls out what it looks like to the user:

    Since tmpfs lives completely in the page cache and on swap, all tmpfs pages will be shown as "Shmem" in /proc/meminfo and "Shared" in free(1).