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
First create a TMP folder in/dev/shm and then bind to the actual/tmp
The code is as follows:
#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.