enable swap space

Here's how to enable swap space:

  1. Create a swap file (swap file) or swap partition (swap partition), and format it as a swap file system type supported by Linux. For example, a swap file of size 4GB can be created with the following command:

    sudo fallocate -l 4G /swapfile
    sudo chmod 600 /swapfile
    sudo mkswap /swapfile
    
  2. Enable swap space, and configure swap files or swap partitions into the system. For example, a previously created swap file can be added to the swap space with the following command:

    sudo swapon /swapfile
    
  3. Configure swap space to be automatically enabled. Edit /etc/fstabthe file and add the following lines to it:

    /swapfile none swap sw 0 0
    

    In this way, the system will automatically add the swap file or swap partition to the swap space at each boot.

Please note that enabling swap space can relieve memory pressure, but it will also bring some performance overhead. Therefore, before enabling swap space, make sure you have tried other ways to reduce memory usage and have identified the need for enabling swap space.

Guess you like

Origin blog.csdn.net/weixin_37787043/article/details/130847971
Recommended