Enable Linux Fedora Swapfile
Precursor
RAM (Random Access Memory) is the place where the programs instructions live usually on the Computer. The code that are ready for execution will be placed here, before moving to faster memory that are too close to the processor and then the execution
When there is no enough memory/space on the RAM for all the programs that are running, the OS intelligently swaps the few of the execution instructions from RAM to slower speed secondary memory or persistence storage areas like Harddisk.
Note: This will cost the performance/ throughput on the computation due to swaping in and out the instructions of RAM to a slower speed devices. However this will enable programs that require more than the physical RAM to live and continue execution slowly.
How to enable Swapfile on Fedora
Determine the size of the new swap file in megabytes and multiply by 1024 to determine the number of blocks. For example, the block size of a 16Gb swap file is 16777216(16×1024×1024).
Create an empty file:
dd if=/dev/zero of=/swapfile bs=1024 count=
16777216
Replace count with the value equal to the desired block size. Set up the swap file with the command:
# mkswap /swapfile
Restrict the access to all users
# chmod 0644 /swapfile
To enable the swap file at boot time, edit /etc/fstab
as root to include the following entry:
/swapfile swap swap defaults 0 0
To add priority if there are multiple swap devices available on the machine, setup pri=<<required priority>>. Higher the priority, the first will be the swap’s to be taken by OS
/swapfile swap swap defaults,pri=100 0 0
The next time the system boots, it activates the new swap file. Regenerate mount units so that your system registers the new /etc/fstab
configuration:
# systemctl daemon-reload
To activate the swap file immediately:
# swapon /swapfile
To test if the new swap file was successfully created and activated, inspect active swap space:
$ cat /proc/swaps
$ swapon -s # to display all swaps available
$ free -h # display human readable swaps file size of all swaps enabled
Reference to RHEL 7 can be found here
Thanks for Reading! Hope this helped. Provide your comments and feedback to improve.