Introduction and use of Linux under Tmpfs

Source: Internet
Author: User

TMPFS Introduction

TMPFS is a virtual memory file system, not a block device. is a memory-based file system that is created without the need to initialize with MKFS, etc.
Its biggest feature is its storage space in VM (virtual memory), the VM is managed by the VM subsystem inside the Linux kernel.
The size of the VM under Linux is made up of RM (Real memory) and swap, and the size of the RM is the size of the physical RAM, and the size of the swap is up to you.
Swap is a virtual memory space through the hard disk, so its read and write speed relative to RM (Real memory) is much slower, when a process to request a certain amount of memory, such as the kernel of the VM subsystem found that there is not enough RM, will be the RM in some of the infrequently used data exchange into the swap inside, If you need to re-use the data and swap them from swap to RM. If you have large enough physical memory, you can not partition the swap.

For more on swap see: Click to Open link http://www.linuxidc.com/Linux/2013-12/93746.htm

The VM is made up of two parts of Rm+swap, so the maximum storage space for TMPFS is up to (the size of RM + the size of Swap). But for TMPFS itself, it does not know whether the space it uses is RM or swap, which is managed by the kernel's VM subsystem.
Tmpfs default size is half of RM, if your physical memory is 1024M, then tmpfs default size is 512M
In general, the configuration is less than the physical memory size.
The size of the TMPFS configuration does not really occupy this memory, if the/dev/shm/does not have any files, it occupies the memory is actually 0 bytes, if it is a maximum of 1G, there are 100M files inside, the remaining 900M can still be used for other applications, However, it consumes 100M of memory and is not re-partitioned by system recycling.
When you delete a file in Tmpfs, the Tmpfs file system driver dynamically reduces the file system and frees the VM resources.
#########################

Use of TMPFS

For example:
The automatic Memory management feature in Oracle uses/DEV/SHM.
Linux can put some of the temporary files of the program in the TMPFS, the use of TMPFS faster than the characteristics of the drive to improve system performance.

There are three ways to adjust the Tmpfs size: 1. Mount directly to the desired directory-such as the system's temporary directory-the directory where you can mount a temporary file of a program according to your actual needs

[Email protected] ~]# mount-t tmpfs-o size=20m tmpfs/tmp
[Email protected] ~]# df-h
Filesystem Size used Avail use% mounted on
/dev/sda2 16G 10G 4.7G 69%/
/DEV/SDA1 99M 21M 74M 22%/boot
Tmpfs 502M 0 502M 0%/dev/shm
Tmpfs 20M 0 20M 0%/tmp
Because the files in the/tmp directory may be in use before they are mounted, the system may not function properly after mounting. Can be written to/etc/fstab, which is also valid after a reboot.

2./etc/fstab file to modify the capacity of the/DEV/SHM (add size=100m option), after modification, re-mount it:

[Email protected] ~]# Cat/etc/fstab
label=//ext3 Defaults 1 1
Label=/boot/boot ext3 Defaults 1 2
Tmpfs/dev/shm tmpfs defaults,size=600m 0 0
Tmpfs/tmp tmpfs defaults,size=25m 0 0
Devpts/dev/pts devpts gid=5,mode=620 0 0
Sysfs/sys Sysfs Defaults 0 0
PROC/PROC proc Defaults 0 0
Label=swap-sda3 swap swap defaults 0 0
/DEV/SDA5 swap swap defaults 0 0
[[email protected] ~]# mount-a--Test/etc/fstab error-free, restart OS system
[[email protected] ~]$ Df-h--The information after the restart is as follows, the corresponding entries for the Tmpfs file system have been changed to the configured
Filesystem Size used Avail use% mounted on
/dev/sda2 16G 10G 4.7G 69%/
/DEV/SDA1 99M 21M 74M 22%/boot
Tmpfs 600M 0 600M 0%/dev/shm
Tmpfs 25M 0 25M 0%/tmp

3./DEV/SHM builds a TMP current and binds with/tmp. -This method is a bit cumbersome, not as easy as Method 1.

[Email protected] ~]# mkdir/dev/shm/tmp
[Email protected] ~]# chmod 1777/dev/shm/tmp
[email protected] ~]# Mount--bind/dev/shm/tmp/tmp-Note that Mount--bind here before bind is two-
[Email protected] ~]# ls-ld/tmp
DRWXRWXRWT 2 root root 8 12:15/tmp
[Email protected] ~]# df-h
Filesystem Size used Avail use% mounted on
/dev/sda2 16G 10G 4.7G 69%/
/DEV/SDA1 99M 21M 74M 22%/boot
Tmpfs 600M 0 600M 0%/dev/shm
Tmpfs 600M 0 600M 0%/tmp----can see that the/TMP is used in the/DEV/SHM space.

Related reading :

Modify TMPFS size and make it effective under Oracle Linux (OEL) http://www.linuxidc.com/Linux/2013-04/83262.htm

Use the Tmpfs file system to do MySQL tmpdir potential problems http://www.linuxidc.com/Linux/2013-03/80696.htm

The difference between TMPFS and Ramfs under Linux http://www.linuxidc.com/Linux/2012-11/74356.htm

Fedora 18 will be used by default TMPFS when/tmp http://www.linuxidc.com/Linux/2012-04/58271.htm

Oracle Linux 6.1 Modified/etc/fstab make Tmpfs effective method description Http://www.linuxidc.com/Linux/2012-03/55605.htm

Source: http://www.linuxidc.com/Linux/2013-12/93747.htm

Introduction and use of Linux under Tmpfs

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.