Configure Swap File
Guide to create and configure a swap file on a Linux machine.
Configuring a Swap File on a Linux machine
Swap files provide more efficient resource allocation by allowing the operating system to prioritize memory usage based on application requirements
- Check your current swap file storage. Run command
free -h
- Create a swapfile. Run command
sudo fallocate -l 1G /swapfile - Only the root user should have permissions to read and write to the swap file. Update permissions by running the command
sudo chmod 600 /swapfile - Use the mkswap command to setup the file as a swap area. Run command
sudo mkswap /swapfile - Enable the swap file with the swapon command. Run command
sudo swapon /swapfile - Verify that the swapfile is on and configured correctly. Run command
sudo swapon --show - Running the command from step 1 will now show the new available swap memory.
