Solved

Curious about tmpfs filesystem

Posted on 2010-11-21
10
1,455 Views
Last Modified: 2012-05-10
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]#
0
Comment
Question by:ashsysad
  • 6
  • 3
10 Comments
 
LVL 35

Accepted Solution

by:
torimar earned 500 total points
ID: 34185520
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
 

Author Comment

by:ashsysad
ID: 34185694
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
 

Author Comment

by:ashsysad
ID: 34185760
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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
LVL 35

Expert Comment

by:torimar
ID: 34185782
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
 
LVL 35

Expert Comment

by:torimar
ID: 34185798
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
 

Author Comment

by:ashsysad
ID: 34185809
Can I know how can I make the /tmp folder to use the tmpfs filesystem or /dev/shm device?
0
 

Author Comment

by:ashsysad
ID: 34185853
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
 

Author Closing Comment

by:ashsysad
ID: 34185986
Thanks for clarifying me about tmpfs filesystem.
0
 
LVL 9

Expert Comment

by:expert_tanmay
ID: 34186010
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
 

Author Comment

by:ashsysad
ID: 34186022
Thanks Tanmay !
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SCP a file to multiple machines using a script 4 68
LINUX backups with VEEAM 8 121
what do I need to host my own web sites? 13 51
Check for Linux process in script 7 49
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question