In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
1. What is swap Partition
When the physical memory of the system is insufficient, the Swap partition frees up a portion of the physical memory for use by the currently running program. The free space may come from programs that have been inactive for a long time, and the free space is temporarily saved in the Swap partition, and when those programs are about to run, the saved data is recovered from the Swap partition to memory. Swap partitions are partitioned from disk space, either using a single partition or treating a large file as a swap.
two。 Official information about swap settings
Redhat6.4 official recommendation (we use CentOS 6.4)
Recommended system swap space
Number of RAM in the system recommended swap space if hibernation is allowed, it is recommended to use swap space
2 times the number of 2GB RAM and 3 times the number of RAM
> 2GB-8GB is equal to twice the number of RAM RAM
> 8GB-64GB at least 1.5 times of 4GB RAM
> 64GB at least 4GB does not recommend hibernation
Because some systems allow hibernation, you cannot start without setting swap, just as windows systems use hibernation to set virtual memory.
Recommendations of Mysql 5.6and 5.7,
Mysql5.6
This means that swap can be deleted when there is enough physical memory, because in some cases, the system will have enough memory to use swap, and if used, it will cause mysql failure due to the increase of I 0. Mysql recommends deletion.
Oracle recommendation
In addition, I saw the following recommended setting in other blogs, but of course I don't know how it got this standard. There is no way to prove whether it is reasonable. It can be used as a reference.
For physical memory within 4G, SWAP is set to 2 times the amount of memory.
4-8 gigabytes of physical memory, SWAP equal to memory size.
8-64 GB of physical memory, SWAP set to 8 GB.
64-256g physical memory, SWAP set to 16G.
Of course, there are so many suggested standards that people are at a loss as to what to do and don't know how to set them. In fact, according to the actual situation of the system and the load of memory, but what is the actual situation?
Personal suggestions are as follows:
Whether the physical memory space is at the peak can also meet the requirements. It does not meet the recommended setting of swap to prevent memory overflow from causing host downtime. Of course, the setting should not be too large and take up disk space. It is not recommended to set swap if the disk I / O is sufficient, the disk I / O value is too low or other business requirements are high. Because using swap requires frequent writes to disk, it is not recommended to use solid state disks. Specific applications installed on the server, such as Mysql, are not recommended and can be controlled without setting or modifying the parameter swappiness. The default value of 60 means that swap space is used when 40% of the memory is used. You can set the value to 10 or set 0, giving priority to the use of physical memory.
3. How to add or delete swap partitions
1. View swap space and usage
[root@localhost-zabbix] # swapon-sFilename Type Size Used Priority/dev/dm-1 partition 2097144 0-1 [root@localhost-zabbix] # free-m total used free shared buffers cachedMem: 1877 565 1311 0132 188 + buffers/cache: 244 1632Swap: 2047 0 2047
2. Close swap
[root@localhost-zabbix ~] # swapoff / dev/dm-1 [root@localhost-zabbix ~] # swapon-sFilename Type Size Used Priority
3. Close the partition before enabling it.
[root@localhost-zabbix ~] # swapon / dev/dm-1 [root@localhost-zabbix ~] # swapon-sFilename Type Size Used Priority/dev/dm-1 partition 2097144 0-1
4. Reduce the Swap partition
If you are increasing the size of the Swap partition, you need to extend the logical volume of the swap partition you are using, here use the lvreduce command to shrink the logical volume
[root@getlnx14uat] # lvreduce-L 8G / dev/mapper/VolGroup00-LogVol01 WARNING: Reducing active logical volume to 8.00 GB THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce LogVol01? Y Reducing logical volume LogVol01 to 8.00 GB Logical volume LogVol01 successfully resized [root@getlnx14uat ~] # mkswap / dev/mapper/VolGroup00-LogVol01 # format Setting up swapspace version 1, size = 8589930 kB [root@getlnx14uat ~] # swapon-sFilename Type Size Used Priority [root@getlnx14uat ~] # swapon / dev/mapper/VolGroup00-LogVol01 [root@getlnx14uat ~] # swapon-sFilename Type Size Used Priority/dev/mapper/VolGroup00-LogVol01 partition 8388600 0-1
5. Increase the swap space.
If there is unallocated space left on the disk, you can either partition swap or increase the previous swap.
If there are no unallocated disks, you can create a new partition file to increase the swap
[root@localhost-zabbix ~] # dd if=/dev/zero of=/home/swap bs=1024 count=1024000 recorded 1024000x0 read-in, 1024000x0 write-out 1048576000 bytes (1.0GB) replicated, 2.69212 seconds 389 MB/ seconds [root@localhost-zabbix ~] # df-hFilesystem Size Used Avail Use% Mounted on/dev/mapper/vg_localhostzabbix-lv_root 18G 4.7G 12G 29% / tmpfs 939M 0939M 0% / dev/shm/dev/sda1 485m 33M 427M 8% / boot [root@localhost-zabbix ~] # mkswap / home/swapmkswap: / home/swap: warning: don't erase bootbits sectors on whole disk. Use-f to force.Setting up swapspace version 1, size = 1023996 KiBno label, UUID=74c16b0d-7d88-4384-b41e-b12cc93d4bbf [root@localhost-zabbix ~] # cd / home/ [root@localhost-zabbix home] # lsswap [root@localhost-zabbix home] # mkswap swap mkswap: swap: warning: don't erase bootbits sectors on whole disk. Use-f to force.Setting up swapspace version 1, size = 1023996 KiBno label UUID=7677912c-b337-4e83-9003-b736dec93d31 [root@localhost-zabbix home] # free-m total used free shared buffers cachedMem: 1877 1611 265 0135 1192 buffers/cache: 283 1593Swap: 2047 0 2047 [root@localhost-zabbix home] # swapon swap [root@localhost-zabbix home] # free-m total used free shared buffers cachedMem: 1877 1612 265 0135 1192 free m total used free shared buffers cachedMem + buffers/cache: 284 1592Swap: 3047 03047 [root@localhost-zabbix home] # swapon-sFilename Type Size Used Priority/dev/dm-1 partition 2097144 0-1/home/swap file 1023992 0-2
We can see that there are partition files above to increase the swap space. But there is also a problem here, that is, after rebooting the system, swap will still change back. You need to modify / etc/fstab here.
Increase: / home/swap swap swap default 0 0
Delete just added swap
Swapoff / home/swaprm-rf / home/swapvi / etc/fstab/home/swap swap swap default 0 0
Yes, there is a new partition, create a new swap:
Use fdisk to create a swap partition (assuming / dev/sdb2 is a created swap partition)
Mkswap / dev/sdb2swapon / dev/sdb2vi / etc/fstab/dev/sdb2 swap swap defaults 0 0
6. Modify swappiness
The swappiness parameter value indicates that vm.swappiness = 0 is used only when there is insufficient memory-- swap space is used when the remaining free memory is lower than vm.min_free_kbytes limit. Vm.swappiness = 1 kernel version 3.5 and above, Red Hat kernel version 2.6.32-303 and above, with a minimum amount of swapping, but swapping is not disabled. Vm.swappiness = 10 when the system has enough memory, it is recommended to set this value to improve performance. Vm.swappiness= 60 default value vm.swappiness= 100Kernel will actively use swap space # sysctl-a | grep vm.swappiness view swappinessvm.swappiness = 3percent echo 10 > / proc/sys/vm/swappiness temporary modification # sysctl-a | grep vm.swappiness# vm.swappiness=10 # sysctl-w vm.swappiness=10 temporary modification vm.swappiness=10 # cat / proc/sys/vm/swappiness10 edited in / etc/sysctl.conf Add the following parameter (if any) vm.swappiness = 10 permanent modification requires restart
Pay special attention to:
If the business and system are not affected and the physical memory is sufficient, it is recommended to use the last modified swappiness to ensure that physical memory is used first and swap is used to prevent memory overflow when there is insufficient physical memory. It is suggested to set a value of 10 according to the query data.
Summary
The above is the whole content of this article, I hope that the content of this article has a certain reference and learning value for your study or work, if you have any questions, you can leave a message and exchange, 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: 0
*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.