Swap partition
Usually memory is the physical RAM of the machine, which reads and writes slower than the CPU, but is higher than the disk by more than one order of magnitude. Therefore, the program and data if in memory, there will be very fast read and write speed. However, the cost of the memory is higher than the disk, although the relative price has been decreasing. In addition, the loss of data in memory is also a reason to say that all data and programs cannot be stored in memory. Since it is not possible to use all of the memory, the data and programs must not always be occupied in memory. When memory is not available, it must be kicked out of a program that does not run frequently in memory. But when it kicks in, the swap appears. swap is all called swap place, which is the swap area, when the memory is not enough, the process being kicked out is temporarily stored in the swap area. When this kicked out process is needed, it is reloaded from swap to memory, otherwise it will not be actively swapped into real memory.
The computer divides the memory into physical memory and virtual memory (note the difference between virtual memory and virtual address space). Physical memory is the actual memory size of the computer, which is made up of RAM chips. Virtual memory is virtual and uses disk instead of memory. The advent of virtual memory, so that the machine memory is not enough to be partially resolved. When the program is run by the operating system to make specific virtual memory to the replacement and loading of physical memory (corresponding pages and segments of virtual memory management). the virtual memory here is called swap.
When the user submits the program, it then generates the process to run on the machine. The machine will determine if the current physical memory is free to allow the process to run into memory, if any, then directly into the memory to run, if not, then select a process to suspend according to the priority, swap the process to swap to wait, and then transfer the new process into the memory to run. According to this swap-in and swap-out, memory recycling is realized, so that users do not feel the limit of memory. It is also possible to see that swap plays a very important role, that is, the process of staging the swap. Between memory and swap is the amount of data exchanged per memory page, and the size of the page in Linux is set to 4KB. and the memory and the disk is to exchange data according to the block. So how the swap size is determined. The following formula can be obtained according to the CentOS website: M = Amount of RAM in GB, and s = Amount of swap in GB, then If M < 2, s = m * * Else s = m + 2
Adjust swappiness parameters
Ref: 53339991
The size of the swappiness value is very much associated with how the swap partition is used. Swappiness=0 means to maximize the use of physical memory, then the swap space, swappiness=100 when the active use of the swap partition, and the memory of the data in a timely manner into the swap space. The basic default setting for Linux is 60, as follows:
The general default value is 60
[Email protected] ~]# cat/proc/sys/vm/swappiness
60
In other words, when your memory is used to 100-60=40%, it starts to appear with the swap partition. This will increase the system IO, at the same time create a large number of pages in the swap out, seriously affect the performance of the system, so we at the operating system level, to use as much memory as possible.
The current settings of the parameters can be viewed through sysctl-q vm.swappiness:
[Email protected] ~]$ sysctl-q vm.swappiness
Vm.swappiness = 30
The temporary adjustment method is as follows, we tune to 10:
[Email protected] ~]# sysctl vm.swappiness=10
Vm.swappiness = 10
[Email protected] ~]# cat/proc/sys/vm/swappiness
10
This is only a temporary adjustment method, and will return to the default settings after reboot.
If you want to make a permanent adjustment, you need to
Need to be modified in/etc/sysctl.conf, plus:
[Email protected] ~]# cat/etc/sysctl.conf
# Controls The maximum number of shared memory segments, in pages
Kernel.shmall = 4294967296
vm.swappiness=10
Activation settings
[Email protected] ~]# sysctl-p
In Linux, you can improve the performance of your system by modifying the Swappiness kernel parameters to reduce the system's use of swap.
Large-scale cluster requires swappiness kernel parameter tuning