How to increase swap memory in Centos 7

Linux has the facility to divide its physical RAM into tiny chunks of memory called as pages. Swapping is a method by which a page of memory can be copied to the pre-configured space on the hard disk which is called swap space, to free that particular page of memory. Thus, the combination of physical memory and the swap space is the actual amount of virtual memory available.

Swapping is critical for two obvious reasons. First, if the system needs more memory than physically available memory, the kernel swaps out less utilized pages and provides memory to the current application(process) that requires the memory instantly. Next, a significant number of pages utilized by an application or process during its initial phase may only be used for initialization and then be never used again. The system shall swap out those pages and free the memory for other applications(process) or even the disk cache.

There are two methods by which we can increase the swap space:

1. swap partition

2. swap File

First method : Swap Partition

check the available swap space use this command “ swapon -s “

swap memory in Centoscheck the system overall space use this following use the command “ free -m “

swap memory in Centosbefore allocating swap, check the space on availability of drive use the command “ df -h “

swap memory in CentosNow Create a partition for swap space using the following command “ fdisk /dev/sda “

swap memory in CentosType “ n “ for New partition created command……..press the enter.

Select which type of partition you want ( Primary, Extended ). Now that we have selected the primary Partition, Press enter & select a Partition Number press enter.

Select the First sector and last sector to be Default………….. Press enter

List the Partition command “ p “

swap memory in CentosPress “ l “ to listed the below ID

press ” t ” to change the partition ID and select 82 for Linux Swap / So

swap memory in CentosCommand (m for help) “ p “ below the created swap partition to be listed.

press ” w ” to save command.

Refresh the system settings use command “partprobe /dev/sda1

swap memory in Centosmkswap /dev/sda1” Use command to format the created partition

swap memory in CentosSwapon /dev/sda1”type command swap partition to activated.

swap memory in CentosCat /proc/swaps” use command to verify the activated partition to below

swap memory in CentosVim /etc/fstab” Type the command to add the newly created partition to fstab configuration file

swap memory in CentosSave and exit the fstab page.

Reboot the System.

After reboot, check the created partition to be listed or Not use command “cat /proc/swaps “

swap memory in CentosSecond Method: Using File

No additional hard drive available in system, create a file for use the swap space increase.

Use the command to create a swap File ” dd if=/dev/zero of=/root/vembuswap bs=1M count=1024 “ and press the enter.

swap memory in CentosCheck the newly created swap File permission use command ‘ “ ls -l /root/vembuswap “

swap memory in CentosSet a swap File permission use command ” chmod 600 /root/vembuswap “

swap memory in CentosMake the file as swap file using command “mkswap /root/vembuswap ”

swap memory in CentosActivate the newly created swap file command “swapon /root/vembuswap “

swap memory in CentosAdd a newly created swap file entry to fstab page use command ” vim /etc/fstab ”

swap memory in Centosswap memory in CentosOnce add the fstab page Save & exit

Verify the newly created swap file in available use command ” swapon -s ”
and “ free -m “check the free memory also.

swap memory in Centosswap memory in CentosConclusion

Managing swap space is a critical aspect of system administration. With proper planning and usage, swapping can provide more benefits to Linux users.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.