Introduction and use of tmpfs in LINUX

Source: Internet
Author: User
Tmpfs introduces tmpfs as a virtual memory file system, rather than a block device. It is a memory-based file system. when you create a file system, you do not need to use mkfs to initialize it. The biggest feature is that its storage space is in VM (virtualmemory ), VMS are managed by the VM subsystem in the Linux kernel. Lin tmpfs introduces tmpfs as a virtual memory file system, rather than a block device. It is a memory-based file system and does not need to be initialized using mkfs.
Its storage space is virtual memory (VM), which is managed by the VM subsystem in the Linux kernel.
In linux, the VM size is composed of RM (Real Memory) and swap. the RM size is the physical Memory size, and the Swap size is determined by yourself.
Swap is the Memory space virtualized by the hard disk, so its read/write speed is much slower than RM (Real Memory). when a process requests a certain amount of Memory, if the kernel vm subsystem finds that there is not enough RM, it will exchange some of the uncommon data in RM to Swap, if you need to re-use the data and then switch them from Swap to RM. If there is enough physical memory, no Swap partition can be divided.
For more information about SWAP, see:Http://blog.csdn.net/haibusuanyun/article/details/16336593click to open the link
The VM consists of RM + Swap, so The maximum storage space of tmpfs is reachable (The size of RM + The size of Swap ). However, for tmpfs itself, it does not know whether the space it uses is RM or Swap, which is all managed by the kernel's vm subsystem.
The default size of tmpfs is half of RM. if your physical memory is 1024 MB, the default size of tmpfs is 512 MB.
Generally, it is configured to be smaller than the physical memory size.
The size configured by tmpfs does not really occupy this memory. If no file exists in/dev/shm/, the memory occupied by tmpfs is actually 0 Bytes. if it is 1 GB at most, if there is a M file in it, the remaining M can still be used by other applications, but the M memory occupied by it will not be recycled and re-divided by the system.
When files in tmpfs are deleted, the tmpfs file system driver dynamically reduces the file system and releases VM resources.
#########################
The usage of tmpfs is as follows:
The Automatic Memory Management feature in Oracle uses/dev/shm.
In LINUX, temporary files of some programs can be placed in tmpfs, and the system performance can be improved by using tmpfs features faster than hard disk speed.
There are three ways to adjust the size of tmpfs: 1. directly mount the file to the required Directory. for example, the temporary directory of the system. you can mount the Directory of the temporary file of a program as needed. [root @ bys3 ~] # Mount-t tmpfs-o size = 20 m tmpfs/tmp
[Root @ bys3 ~] # Df-h
Filesystem Size Used Avail Use % Mounted on
/Dev/sda2 16G 10G 4.7G 69%/
/Dev/sda1 99 M 21 M 74 M 22%/boot
Tmpfs 502 M 0 502 M 0%/dev/shm
Tmpfs 20 M 0 20 M 0%/tmp
Because files in the/tmp directory may not be used after mounting, some programs in the system may not work normally after mounting. It can be written to/etc/fstab, which is also valid after restart.

2. modify the/dev/shm capacity in the/etc/fstab File (add the size = M option). after modification, remount the file: [root @ bys3 ~] # Cat/etc/fstab
LABEL = // ext3 defaults 1 1
LABEL =/boot ext3 defaults 1 2
Tmpfs/dev/shm tmpfs Defaults, size = 600 M0 0
Tmpfs/tmp tmpfs Defaults, size = 25 M0 0
Devpts/dev/pts devpts gid = 5, mode = 620 0 0
Sysfs/sys sysfs defaults 0 0
Proc/proc defaults 0 0
LABEL = SWAP-sda3 swap defaults 0 0
/Dev/sda5 swap defaults 0 0
[Root @ bys3 ~] # Mount-a -- Test/etc/fstab without error. restart the OS.
[Oracle @ bys3 ~] $ Df-h -- the information after the restart is as follows. the corresponding entry of the tmpfs file system has been changed to the configured
Filesystem Size Used Avail Use % Mounted on
/Dev/sda2 16G 10G 4.7G 69%/
/Dev/sda1 99 M 21 M 74 M 22%/boot
Tmpfs 600 M 0 600 M 0%/dev/shm
Tmpfs 25 M 0 25 M 0%/tmp

3. create a tmp current in/dev/shm and bind it to/tmp. -- This method is a little cumbersome. it is not as convenient as method 1. [Root @ bys3 ~] # Mkdir/dev/shm/tmp
[Root @ bys3 ~] # Chmod 1777/dev/shm/tmp
[Root @ bys3 ~] # Mount -- bind/dev/shm/tmp-note mount -- bind here the first two bind-
[Root @ bys3 ~] # Ls-ld/tmp
Drwxrwxrwt 2 root 40 Dec 8 12:15/tmp
[Root @ bys3 ~] # Df-h
Filesystem Size Used Avail Use % Mounted on
/Dev/sda2 16G 10G 4.7G 69%/
/Dev/sda1 99 M 21 M 74 M 22%/boot
Tmpfs 600 M 0 600 M 0%/dev/shm
Tmpfs 600 M 0 600 M 0%/tmp ---- you can see that/tmp uses/dev/shm space.


Related Article

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.