Tmpfs and/dev/shm

Source: Internet
Author: User
Tags tmp folder
An Introduction
/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. One of the/dev/shm/to note is the capacity problem, which, under Linux, defaults to a maximum of half the size of memory, and can be seen using the df-h command. 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 not going to be recycled by the system, or who dares to deposit documents into it.

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.

Another major benefit of 2,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-onr_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

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

#mount-O REMOUNT/DEV/SHM


third,/DEV/SHM application

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

Mkdir/dev/shm/tmp

Chmod1777/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. ORACLE11G's AMM memory management mode is to use/DEV/SHM, so sometimes modifying memory_target or memory_max_target can cause ORA-00845 errors.

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: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.