Home >Operation and Maintenance >Linux Operation and Maintenance >How to set up swap virtual memory on Linux cloud server

How to set up swap virtual memory on Linux cloud server

WBOY
WBOYforward
2023-05-15 23:52:131784browse

swap swap memory mainly means that when the physical memory is not enough, the system will enable part of the hard disk space to serve as server memory. By default, swap memory will have some setting standards, which are also related to the size of the physical memory.

View memory space: free -h

How to set up swap virtual memory on Linux cloud server

Create swap partition file: dd if=/dev/zero of=/data/swap bs=1M count =4096

Code explanation: bs is the size of the block, count is the number of blocks, it is known that bs=1M, count=4096, 1M*1024=4G swap partition virtual memory, /data/swap is swap The path for file creation. The above parameters can be modified according to your own needs.

How to set up swap virtual memory on Linux cloud server

mkswap /data/swap #Convert the created file to a swap partition

chmod 600 /data/swap Set permissions

sysctl -p Refresh the system settings to make them effective

How to set up swap virtual memory on Linux cloud server

#swapon /data/swap Start the swap partition virtual memory

free -h View the memory space, the virtual memory in the picture The memory has taken effect

How to set up swap virtual memory on Linux cloud server

echo "/data/swap swap swap defaults 0 0" >> /etc/fstab Add automatic mounting at boot

How to set up swap virtual memory on Linux cloud server

The above is the detailed content of How to set up swap virtual memory on Linux cloud server. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete