/Dev/SHM/in Linux/

Source: Internet
Author: User
Tags php website tmp folder
Reprinted from heyuejuan and finally edited heyuejuan

/Dev/SHM/is a very useful directory in Linux, because this directory is not on the hard disk, but in the memory. Therefore, in Linux, you do not need to pay a weekly discount to create ramdisk. You can directly use/dev/SHM/to achieve good optimization results.
/Dev/SHM/one thing to note is the capacity problem. In Linux, the maximum size is half the memory size by default. You can see it by running the DF-H command. But it does not really occupy this memory. If there is no file in/dev/SHM/, it actually occupies 0 bytes of memory. If it is 1 GB at the maximum, if there is a M file in it, the remaining m can still be used by other applications, but the M memory it occupies will never be recycled and re-divided by the system, otherwise, who dared to store files in it?
The default maximum size of half of the memory may not be enough in some cases, and the default inode quantity is very low. Generally, you need to increase it. In this case, you can use the mount command to manage it. Mount-O size = 1500 m-o nr_inodes = 1000000-O noatime, nodiratime-O remount/dev/SHM

On 2 GB machines, the maximum capacity is increased to 1.5 GB, and the number of inode is increased to 1000000, which means that up to 1 million small files can be stored.

 

In order to occupy swap space when/dev/SHM space is insufficient, do not worry about insufficient storage space. How fast will PHP read/write sessions be from disk I/O operations to memory operations? Note that all data stored in/dev/SHM is lost after the server is restarted.

 

By default, the system will load/dev/SHM, which is called tmpfs. Some people say it is different from ramdisk (Virtual Disk. Like a virtual disk, tmpfs can use your RAM, but it can also use your swap partition for storage. In addition, a traditional virtual disk is a block device and requires commands such as mkfs to actually use it. tmpfs is a file system, not a block device. You only need to install it, it can be used.
Tmpfs has the following advantages:
1. Size of the dynamic file system.
2. Another major benefit of tmpfs is its lightning speed. Because the typical tmpfs file system will completely reside in Ram, reading and writing can be almost instantaneous.
3. tmpfs data will not be retained after restart, because the virtual memory is essentially easy to lose. Therefore, it is necessary to execute some scripts such as loading and binding.
Let's talk about the application:
Create a tmp folder in/dev/STM and bind it to the actual/tmp folder.
Mkdir/dev/SHM/tmp
Chmod 1777/dev/SHM/tmp
Mount -- bind/dev/SHM/tmp (-- bind)
After you use the Mount -- bind olderdir newerdir command to mount a directory to another directory, the newerdir permission and owner information will change. The mounted directory inherits all the attributes of the mounted directory except the name.
The clever use of tmpfs to accelerate your Linux server is to use a virtual disk to store Squid cache files and PHP seesion. Fast!
The system will load/dev/SHM, which is called tmpfs. Some people say it is different from ramdisk (Virtual Disk. Like a virtual disk, tmpfs can use your RAM, but it can also use your swap partition for storage. In addition, a traditional virtual disk is a block device and requires commands such as mkfs to actually use it. tmpfs is a file system, not a block device. You only need to install it, it can be used.
Tmpfs has the following advantages:
1. The size of the dynamic file system,
2. Another major benefit of tmpfs is its lightning speed. Because the typical tmpfs file system will completely reside in Ram, reading and writing can be almost instantaneous.
3. Tmpfs data will not be retained after restart, because the virtual memory is essentially easy to lose. Therefore, it is necessary to execute some scripts such as loading and binding.
Well, I have explained some things and I am tired of reading them. Let's talk about my applications :)
Create a tmp folder in/dev/SHM and bind it to the actual/tmp folder.
Mkdir/dev/SHM/tmp
Chmod 1777/dev/SHM/tmp
Mount -- bind/dev/SHM/tmp

1. Squid cache directory settings
VI/etc/squid. conf
Modify
Cache_dir ufs/tmp 256 16 256
The first 256 in this indicates using M memory, I think the ramdisk method in http://www.linuxaid.com.cn/articles/4/4/441672019.shtml is better than directly using tmpfs, at least each start without mkfs, you can also dynamically change the size. In this case,/tmp is actually/dev/SHM/tmp.
Then restart the service. OK. Now all the Squid cache files are saved in the tmpfs file system, and soon.

2. php Performance Optimization
For an Apache + PhP website with a large access volume, there may be a lot of temporary files under TMP, such as seesion or some cached files, you can save it to the tmpfs file.
The method for saving the seesion is simple. You only need to modify PHP. INI is enough. Since I have bound/dev/STM/tmp to/tmp, I can do it without rewriting, as for the cache files generated by the PHP program, you can only change your PHP program :)
As for other tmpfs applications, I think you may be inspired by this article.

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.