Requirements: Virtual memory is a double-edged sword, there is no good or bad, only whether it is suitable or not, and it is appropriate in that scenario. For high-traffic, low-latency, and high-concurrency calculations, turning on virtual memory may not help the entire system and may even become a negative optimization. For servers with small memory, small compute, and decent hard disk read and write performance, turning on virtual memory may improve the overall performance and experience.
In Linux systems, swap partitions (swap space) are used when the system needs more memory resources and the physical memory is full. Use swap space to provide temporary storage for inactive processes and data, and prevent running out of memory when physical memory is full. Swap space acts as an extension of physical memory and allows the system to continue running smoothly when physical memory is depleted.
Enable the virtual memory swap partition
To check whether the swap partition configuration is enabled, the command is as follows:
IfThe echo message is empty, indicating that there is no swap partition in the system, you can configure the swap partition according to your needs.
Create a file for swapping partitions with the following command:
The value of /var/swap is a variable that represents the identity of the swap partition, and you can customize the value of this variable to be the same as the existing partition ID.
The values of bs and count indicate the size of the created interchange file, you can customize the settings, in this command bs=1M count=4096 means that the size of the interchange file is set to 4 GB.
To format the file as a swap partition, the command is as follows:
Run the following command to open the swap partition:
The opening is successful, as shown in the figure below:
Write the new partition information in the /etc/fstab file and configure the swap partition to be automatically mounted on boot with the following command:
Turning it on does not mean using it, it must beConfigure the swappiness parameter to determine the principle of the system's use of swap partitions, the swappiness parameter ranges from 0 to 100.
To edit the /etc/sysctl.conf file, for example, you need to adjust the following parameters when the physical memory is less than 80% of the space.
Run the following command to make the configuration take effect:
The summary command is as follows:
Close the virtual memory swap partition
Execute the following command to close the swap partition:
etc/fstab file, andDeleteSimilar to the following swap-related mounting information, cancel the automatic mounting of swap.
Save and exit, then execute the following command to confirm that the swap partition is closed.
The echo message is empty, indicating that the swap partition has been closed.
Reference:
The hyperlink login is visible.
The hyperlink login is visible.
The hyperlink login is visible.
The hyperlink login is visible. |