In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
How to discuss linux tmpfs and / or dev/shm and what its application is, many novices are not very clear about this. In order to help you solve this problem, the following editor will explain it in detail. People with this need can come and learn. I hope you can get something.
What is tmpfs?
Tmpfs is a memory-based file system on Linux/Unix systems. Tmpfs can use your memory or swap partition to store files. Thus it can be seen that temfs mainly stores temporary files.
The VM subsystem in the linux kernel is responsible for managing the virtual memory resources Virtual Memory, namely RAM and swap resources, in the background, transparently moving RAM pages to or from swap partitions to RAM pages, and the tmpfs file system needs pages from the VM subsystem to store files.
VM consists of two parts of RM+Swap, so the maximum storage space of tmpfs can reach (The size of RM+ The size of Swap). But for tmpfs itself, it doesn't know whether the space it uses is RM or Swap, all managed by the kernel's vm subsystem. Tmpfs itself doesn't know whether the pages are in swap or RAM; it's the job of the VM subsystem to make this decision. All the tmpfs file system knows is that it is using some form of virtual memory.
The default size of tmpfs is half that of RM. If your physical memory is 1024m, then the default size of tmpfs is 512m.
In general, it is configured less than the physical memory size.
The size of the tmpfs configuration does not really take up this piece of memory, if there are no files under / dev/shm/, it actually occupies 0 bytes of memory; if it has a maximum of 1G and contains 100m files, then the remaining 900m can still be used by other applications, but the 100m of memory it occupies will not be reclaimed and redivided by the system.
Tmpfs is based on memory, so the speed is quite high. In addition, the VM resources used by tmpfs are dynamic. When deleting files in tmpfs, the tmpfs file system driver will dynamically reduce the file system and release VM resources. Of course, it will also dynamically allocate VM resources when creating files. In addition, tmpfs is not persistent and data is not retained after reboot, for obvious reasons that it is memory-based.
When compiling the kernel, you can use tmpfs,linux kernel by enabling "Virtual memory file system support". Tmpfs has been supported since 2.4. At present, mainstream linux systems have enabled tmpfs by default, such as Redhat.
Tmpfs application
Tmpfs is based on memory, the speed is needless to say, the hard disk can not be compared with it.
The Automatic Memory Management feature in Oracle uses / dev/shm.
In addition, if you make good use of tmpfs in the operation and maintenance of the website, there will be unexpected gains.
Let's first build a tmp in / dev/shm and bind it to / tmp.
[root@GoGo shm] # mkdir / dev/shm/tmp
[root@GoGo shm] # chmod 1777 / dev/shm/tmp / / pay attention to permissions
[root@GoGo shm] # mount-bind / dev/shm/tmp / tmp
[root@GoGo tmp] # ls-ld / tmp
Drwxrwxrwt 2 root root 40 Aug 29 23:58 / tmp
Of course, you can also use tmpfs on existing mount points without binding, such as: mount
# umount / tmp
# mount tmpfs / tmp-t tmpfs-o size=512M
It is also very convenient, do not need to use commands such as mkfs to create.
The following / tmp uses the tmpfs file system.
(1) put the cache directory cache_dir of squid under / tmp
Cache_dir ufs / tmp 256 16 256
Restart the squid service so that the cache directories are placed in the tmpfs file, needless to say.
(2) put the session file of php under / tmp
Check your php session storage location through the phpinfo test file. If it is not under / tmp, modify the php.ini file as follows:
Session.save_path = "/ tmp"
Of course, if you have a large number of visitors to your website, you can set hierarchical directory storage session under / tmp. The syntax is as follows:
Session.save_path= "N _ blank _ save _ path", where N is the series of grades, and save_path is the starting directory.
(3) put the socket file of the service under / tmp
Such as nginx.socket and mysql.sock
Tmpfs Sizing
Sometimes, when the application uses Tmpfs, and if you do not make enough assessment of the memory consumed by the application during deployment, it is possible to use up the Tmpfs. At this time, you need to resize the Tmpfs, of course, the size cannot be larger than the memory size of your machine, otherwise, you will have to change the machine or optimize your application.
You can see that the size of the tmpfs is 3G, for example, we want to adjust to 5G.
1) umount tmpfs
Note here that since umount will unmount the tmpfs file system, it means that the shared memory used by your application will be deleted, and if the data is important, remember to back it up before umount.
Root@TENCENT64 / dev] # umount / dev/shmumount: / dev/shm: device is busy. (In some cases useful info about processes that usethe device is found by lsof (8) or fuser (1))
As you can see here, umount failed for obvious reasons. / dev/shm is used by other processes, so all processes using / dev/shm need to be stopped before umount.
If the error is described, you can use the command fuser-km / dev/shm to kill all loaded processes before umount
Fuser-km / dev/shmumount / dev/shm
2) resize tmpfs
Modify the capacity of / dev/shm by modifying the / etc/fstab file, and modify the tmpfs line in the file, as follows:
Tmpfs / dev/shm tmpfs defaults,size=600M 00
Tmpfs / tmp tmpfs defaults,size=25M 0 0
After modification, re-mount tmpfs can be done.
There are roughly three ways to resize tmpfs:
1. Mount directly to the desired directory-- such as the temporary directory of the system-- where you can mount the temporary files of a program according to your actual needs.
[root@bys3] # mount-t tmpfs-o size=20m tmpfs / tmp
[root@bys3] # 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 0502m 0% / dev/shm
Tmpfs 20m 0 20m 0% / tmp
Since files in the / tmp directory may be in use before mounting, some programs on the system may not work properly after mounting. You can write / etc/fstab, which is also valid after reboot.
2./etc/fstab file to modify the capacity of / dev/shm (add size=100M option). After modification, you can mount it again:
[root@bys3 ~] # cat / etc/fstab
LABEL=/ / ext3 defaults 1 1
LABEL=/boot / boot ext3 defaults 1 2
Tmpfs / dev/shm tmpfs defaults,size=600M 00
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
[root@bys3 ~] # mount-a-Test / etc/fstab without error, restart OS system
The information after the restart of [oracle@bys3 ~] $df-h 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 99m 21m 74m 22% / boot
Tmpfs 600m 0 600m 0% / dev/shm
Tmpfs 25m 0 25m 0% / tmp
3./dev/shm builds a tmp currently and binds with / tmp. This method is a bit cumbersome and is not as convenient and fast as method 1.
[root@bys3 ~] # mkdir / dev/shm/tmp
[root@bys3 ~] # chmod 1777 / dev/shm/tmp
[root@bys3] # mount-- bind / dev/shm/tmp / tmp-pay attention to mount-- bind here there are two before bind-
[root@bys3 ~] # ls-ld / tmp
Drwxrwxrwt 2 root 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 99m 21m 74m 22% / boot
Tmpfs 600m 0 600m 0% / dev/shm
Tmpfs 600m 0600m 0% / tmp-you can see that / tmp uses the space of / dev/shm.
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 271
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.