How to increase swap swap space on Ubuntu

How to increase swap swap space on Ubuntu

Step 1: Check for swap space information

Before starting, first run the following command, making sure to check whether the system has been available swap space.

How to increase swap swap space on Ubuntu

Check the swap space in Ubuntu

If you do not see any output, then your system is not currently available swap space.

You can also use the free command to confirm no available swap space.

How to increase swap swap space on Ubuntu
 
Ubuntu in swap space for 2G

You can see from the above output, there is no system activity on the exchange.

Step 2: Check the available space on the partition

To create a swap space, you first need to check the current disk usage, and make sure there is enough space to create the swap file on the system.

How to increase swap swap space on Ubuntu

Check the Ubuntu file system disk usage

Re / partition has enough space to create the swap file.

Step 3: Create swap file in Ubuntu

Now we will use fallocate command to create a swap file named "swap.img" (size is 1GB) on our Ubuntu root (/) directory, you can resize as needed. And ls command to verify the size of the exchange as shown in FIG.

How to increase swap swap space on Ubuntu

Create a swap file in Ubuntu

From the above output, you can see that we have created the swap file with the correct amount of space (ie 1GB) of.

Step 4: Enable the swap file in Ubuntu

To enable the swap file in Ubuntu, you first need to set the correct permissions on the file so that only the root user can access the file.

How to increase swap swap space on Ubuntu

In the swap file swap permissions

From the above output, you can see only the root user to have access.

Now run the following command will mark the file as swap swap space, and enable the swap file to start using it on your system.

How to increase swap swap space on Ubuntu

Enabling swap swap space in Ubuntu

By running the following command to verify the swap space is available.

Verification of swap space Ubuntu

Verification of swap space Ubuntu

As can be seen from the above output, our new swap file has been successfully created, our system Ubuntu will begin to use it when necessary.

Step 5: In the Ubuntu permanently mount the swap file

To swap space permanent, you need to add a swap file information in / etc / fstab file and verify it by running the following command.

Step 6: Adjust switch settings in Ubuntu

You need to configure some settings that affect your performance when using Ubuntu exchange.

Value adjustment Swappiness

Swappiness Linux kernel is a parameter that specifies the system to exchange data from RAM to a frequency swap space (and frequency). The default value for this parameter is "60", it can use "0" to any value between "100." The higher the value, the higher the swap space used by the kernel.

First, type the following command to check the current value of swappiness.

How to increase swap swap space on Ubuntu

Check the value Swappiness

 Swappiness current value of 60 is ideal for desktop, but the server, you must set it to a lower value, namely 10.

To make this setting permanent, you need to add the following line to /etc/sysctl.conf file. 

vm.swappiness=10

Cache adjust pressure settings

Another similar settings you might want to change is vfs_cache_pressure - This setting specifies the system to cache extent inode dentry detailed information and data on the other.

You can check the current value by querying the proc file system.

 How to increase swap swap space on Ubuntu

Check the pressure setting Cache

The current value is set to 100, which means that our system too quickly deleted inode information from the cache. I suggest that we should set it to a more stable settings, such as 50.

To make this setting permanent, you need to add the following line to /etc/sysctl.conf file.

vm.vfs_cache_pressure=50

After completing the save and close the file.

Step 7: Remove the swap file in Ubuntu

To remove or delete the newly created swap file, run the following command.

How to increase swap swap space on Ubuntu

 

Finally, delete the swap file entries from / etc / fstab file.

that's it! In this article, we have explained how to create a swap file on the swap Ubuntu release. If you have any questions about this article, please feel free to in the comments section below your question.

Guess you like

Origin www.linuxidc.com/Linux/2019-07/159580.htm