Linux Memory File system TMPFS (/DEV/SHM) Detailed introduction

Source: Internet
Author: User
Tags bind tmp folder

First,/dev/shm theory

The kernel configuration in the default Linux distribution will open Tmpfs and map to the SHM directory under/dev/. You can view the results through the DF command.

/dev/shm/is the next most useful directory for Linux because it's not on the hard drive, it's in memory. Therefore, under Linux, there is no need for a lot of trouble to build RAMDisk, direct use of/dev/shm/can achieve a very good optimization effect. The default system will load the/DEV/SHM, which is called the TMPFS, some say with RAMDisk (virtual disk), but not the same. Like a virtual disk, TMPFS can use your RAM, but it can also be stored using your swap partition. And the traditional virtual disk is a block device, and need a mkfs such commands to really use it, TMPFS is a file system, not a block device; you just install it and it's ready to use.

TMPFS has the following advantages:

1. The size of the dynamic file system,/dev/shm/need to note that a capacity problem, under Linux, it defaults to the largest memory half the size, using the df-h command can be seen. But it does not really occupy this block of memory, if the/dev/shm/without any files, it occupies the memory is actually 0 bytes, if it is the largest 1G, there are 100M files, the remaining 900M can still be used for other applications, but it occupies the 100M memory, is never going to be reclaimed by the system.

2. Another major benefit of TMPFS is its lightning speed. Because a typical TMPFS file system resides entirely in RAM, reading and writing can be almost instantaneous.

3. TMPFS data is not preserved after restarting, because virtual memory is inherently volatile. So it is necessary to do some scripting things like loading, binding operations.

  Second, modify the/DEV/SHM size

The default maximum half of the memory size may not be enough on some occasions, and the default number of Inode is generally low, and you can manage it with the Mount command.

#mount-o size=1500m-o nr_inodes=1000000-o noatime,nodiratime-o remount/dev/shm

On a 2G machine, the maximum capacity is transferred to 1.5G, and the inode number is set to 1000000, which means that it can be deposited in up to 1 million small files.

If you need to permanently modify the value of/DEV/SHM, you need to modify the/etc/fstab

The code is as follows:

Tmpfs/dev/shm Tmpfs defaults,size=1.5g 0 0


  Third,/DEV/SHM application

First create a TMP folder in/dev/shm and then bind to the actual/tmp

The code is as follows:


#chmod 1777/dev/shm/tmp

#mount –bind/dev/shm/tmp/tmp (–bind)

After you use the Mount–bind olderdir newerdir command to mount a directory to another directory, all information such as Newerdir permissions and owners will change. The mounted directory inherits all the attributes of the mounted directory, except for the name.

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.