Curious about tmpfs filesystem

Hello,

Please look at the below details of a RHEL 5.3 server. I wish to know about this 'tmpfs' filesystem. Why do a Linux server have this filesystem and it mounted on /dev/shm?  When I checked in /dev/shm, nothing is there?  Please explain in detail. Thanks.

[root@pmclsb01 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                       51G  7.8G   40G  17% /
/dev/xvda1             99M   19M   75M  21% /boot
tmpfs                 3.1G     0  3.1G   0% /dev/shm                   <------ ?
[root@pmclsb01 ~]# free -m
             total       used       free     shared    buffers     cached
Mem:          6144       4561       1582          0        179       4174
-/+ buffers/cache:        207       5936
Swap:         8159          0       8159
[root@pmclsb01 ~]# cd /dev/shm
[root@pmclsb01 shm]# ls
[root@pmclsb01 shm]# du -sh .
0       .
[root@pmclsb01 shm]#
[root@pmclsb01 shm]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 5.3 (Tikanga)
[root@pmclsb01 shm]#
ashsysadAsked:
Who is Participating?
 
torimarConnect With a Mentor Commented:
Tmpfs is a filesystem for temporary storage which does not reside on the physical disk, but in the computer's memory (RAM).
In the Linux device system it is often bound to /dev/shm simply because its name once used to be SHMFS (=Shared Memory File System).

More here: http://en.wikipedia.org/wiki/Tmpfs
0
 
ashsysadAuthor Commented:
Thanks Torimar. I did a small testing on 'tmpfs' filesystem and looks like even a normal user can create files in /tmp or /dev/shm filesystem. If thats being the case, can't a hacker or a normal user (who has an account in the server) simply do continous write on thise filesystem and crash the server by filling the entire RAM space ?
0
 
ashsysadAuthor Commented:
I checked the size of tmpfs in few servers and noticed the value various in each servers.

[adevaraju@orallm06-tx ~]$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                      810G  545G  224G  71% /
/dev/sda1              99M   16M   79M  17% /boot
tmpfs                  17G     0   17G   0% /dev/shm

[adevaraju@sysllm01 shm]$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                      130G   51G   73G  42% /
/dev/sda1              99M   42M   53M  45% /boot
tmpfs                 4.0G  0     4.0G  0% /dev/shm


I created files more than 4 GB in the second server and made it full. But still the server runs fine.

[adevaraju@sysllm01 tmp]$ mv testfile /dev/shm/
mv: writing `/dev/shm/testfile': No space left on device
[adevaraju@sysllm01 tmp]$ free -m
             total       used       free     shared    buffers     cached
Mem:          8116       7832        284          0         93       6905
-/+ buffers/cache:        832       7283
Swap:         1983          0       1983
[adevaraju@sysllm01 tmp]$
[adevaraju@sysllm01 shm]$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                      130G   51G   73G  42% /
/dev/sda1              99M   42M   53M  45% /boot
tmpfs                 4.0G  4.0G     0 100% /dev/shm                   <-- Its full but server is running.


My simple question is, Is it advisable to save files in /tmp or /dev/shm filesystem?  In my organization, many users are habitual to store the file under /tmp.
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
torimarCommented:
No.
The size of tmpfs may dynamically grow or shrink according to requirements, but for normal users it cannot grow beyond the size specified in fstab (which in your case is 3.1 GB). Only root is able to increase that limit via a mount order.

0
 
torimarCommented:
The above comment answers your first question.

As to the next question:
The size of tmpfs may vary depending on the amount of RAM on a server. Once full, swap space is used to accommodate for additional needs.

You should never save (or let users save) anything of importance in the /tmp folder. It is not meant for persistent storage in any way.
If your /tmp folder is set to use the tmpfs filesystem or the /dev/shm device, you not only should not, but simply cannot use it for "saving" anything. Reboot, and all will be lost.
0
 
ashsysadAuthor Commented:
Can I know how can I make the /tmp folder to use the tmpfs filesystem or /dev/shm device?
0
 
ashsysadAuthor Commented:
Please ignore my last question. I guess i got the answer. So in fstab if we mount tmpfs filesystem on /tmp, then /tmp will use RAM space for saving the files, which isn't acceptable.
0
 
ashsysadAuthor Commented:
Thanks for clarifying me about tmpfs filesystem.
0
 
expert_tanmayCommented:
You might have also come across a line as given below
none                 1004M     0 1004M   0% /dev/shm
this is the partition where Linux keeps the swap(virtual memory) file system. For every device on Linux a interface is created like /dev/... They allow software to interact with a device driver using standard input/output  system calls, which simplifies many tasks.

Similarly
tmpfs                 3.1G     0  3.1G   0% /dev/shm
/dev/shm is the device interface for reading or writing tmp files. Tmpfs does not use traditional non-volatile media to store file data; instead, tmpfs files exist solely in virtual memory maintained by the Linux kernel. Because tmpfs file systems do not use dedicated physical memory for file data but instead use VM system resources and facilities, they can take advantage of kernel resource management policies.

regards
0
 
ashsysadAuthor Commented:
Thanks Tanmay !
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.