In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what is the use of adding swap to the CentOS 7 system". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the use of adding swap to the CentOS 7 system"?
Swap is a special file (or partition) located on disk and is part of "virtual memory". The popular point is the spare tire of memory. when there is enough memory, there is basically nothing to do with swap (related to the setting); when there is not enough memory, the system moves part of the data in memory to swap to free up memory for running programs.
Using swap allows the system to run more or larger programs, but because the read and write speed of swap is much lower than memory, frequent use of swap may cause delayed stutters in the system and programs.
Is large memory computer swap necessary?
For computers with less memory, swap is necessary. The existence of swap makes it possible to execute memory-eating programs, and it is better to execute slowly than not to run or run. However, modern computers often have more than 8 gigabytes of memory, such as not running large or professional software, the memory is enough for daily use. In this case, is it necessary for swap to exist?
The answer depends on the usage scenario. If you run desktop Linux on your PC and turn on hibernation, you should divide swap partitions that are not less than memory; if the memory is large enough and the server does not shut down all the year round, there will be no problem without swap.
Do you want to set up swap for ssd hard drives?
Previous ssd hard drives have read and write life problems, so it is not recommended to put swap files or partitions on ssd hard drives.
The current ssd hard drive technology has been upgraded to be smarter, and if there is a need for swap, it will be no problem to put it on the ssd hard drive.
How big is the swap setting?
If hibernation is enabled, the swap partition should be divided, and the partition size should not be less than memory. The recommended value is "memory size + 2G".
Server without hibernation function, swap can be a file, a practical method to determine the size of swap is: 1G memory and less, swap size is twice the memory; 2-4G memory, the same size as memory; 5-16G memory, swap can be fixed for 4G swap;33 G and above 17-32G memory, fixed as 16G swap.
The above methods are not absolute, there are special needs can be appropriate to increase or decrease the size of swap.
How to add swap?
When installing the operating system, you can specify swap in the form of partitions (separate mount points), or you can add and remove dynamically after the system installation is complete.
View swap
The free command can view swap information about system activity, such as:
The output of $free-m # is as follows # total used free shared buff/cache available# Mem: 7976 4979 328 124 2669 270 Swap: 0 4979
The second line is the swap information, and you can see that there is no active swap.
You can also use the swapon command to view the active swap, for example:
$swapon-s # has no swap information, so no output # output with swap is # Filename Type Size Used Priority# / swap file 2097148 281052-2 add swap
Suppose we are going to run a very memory-intensive program, and 8G of physical memory is not enough, so we can increase the virtual memory available to the system with the help of swap. The method of operation is as follows:
Select or create a file as a swap (you can also use partitions). Common commands to create files of a specified size are fallocate and dd. For example, create an 8G file:
# fallocate
Sudo fallocate-l 8G / swap
Dd
Sudo dd bs=1GB count=8 if=/dev/zero of=/swap
Because the replication process of `dd` is slow, it is recommended to use `fallocate` in practice.
Swap files store data in memory, and access to other users should be restricted for security reasons: sudo chmod 0600 / swap
Format the file as a swap file: sudo mkswap / swap
Enable the swap file: sudo swapon / swap; if you don't want to use swap, uninstall it with the swapoff command: sudo swapoff / swap
If you want the swap file to be loaded automatically after the system starts, add a line to the * * / etc/fstab** file: / swap swap swap sw 0 0.
After adding swap, you can use the swapon-s or free-m command to view the swap information.
Swap related Settings
One of the setting parameters that is most directly related to swap and also affects system performance is vm.swappiness. The value is an integer from 0 to 100, indicating how many percent of the memory is used to start using swap. 100 means to use swap,0 whenever possible, which means that the swap spare is used only if there is not enough physical memory. For servers, between 10 and 30 is recommended.
The command to set and change swappiness is: sudo sysctl vm.swappiness=10. This command is only valid for the current system and returns to the default value after the system is rebooted. To make the setting permanent, add or change the corresponding setting line in / etc/sysctl.conf: vm.swappiness = 10.
Referenc
Https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-centos-7
Thank you for reading, the above is the content of "what is the use of adding swap to the CentOS 7 system". After the study of this article, I believe you have a deeper understanding of the use of adding swap to the CentOS 7 system, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.