swap
Swap-RAM
(Use swap to increase RAM 1.5 times or double: 2G to 3G/4G)
As an advanced computer engineer, I'd be happy to guide you through the process of installing Swap and increasing your VPS's RAM to 8GB. Let's take it step by step:
Step 1: Check Available Disk Space Before proceeding, check if you have enough available disk space to create the Swap file. Run the following command to see the disk usage:
Step 2: Create Swap File
Assuming you have enough space, create a Swap file with the following command:
This command will create an 8GB Swap file named "swapfile" with a block size of 1MB and a count of 8192 blocks (8GB).
Step 3: Set Permissions Change the permissions of the Swap file to ensure it is accessible only by the root user:
Step 4: Format the Swap File Use the mkswap command to format the Swap file:
Step 5: Activate the Swap File Activate the Swap file using the swapon command:
Step 6: Enable Swap on Boot To enable the Swap file at every boot, add an entry in the /etc/fstab file:
Step 7: Verify Swap Configuration To verify that the Swap file is correctly configured and in use, run the following command:
You should see the total available memory increased to 8GB, including the added Swap space.
Step 8: Set Swap threshold
To achieve the behavior you're looking for, where your system starts using swap when your physical RAM is nearly 90% full, you can use a combination of tools and configurations. Here's a general outline of the steps you can follow:
Step 9: Reboot (optional) It's optional, but you can reboot your VPS to ensure all changes are applied correctly:
After the reboot, your VPS should have 8GB of RAM, including the Swap space. Remember that Swap is slower than physical RAM, so it's still recommended to optimize your applications and consider upgrading your VPS if required for better performance.
Last updated