how to fix swap issues in azure vm
Red Hat Linux virtual machine gets build in azure either via portal or via some kind of automation (using script ) to avoid any manual mistakes .But due to any possible reason if swap is either not configured properly or you have requirement to update swap configuration keeping in view of application demand of swap this procedure how to fix swap issues in Azure VM.
What is swap?
Swap space in Linux is used when the amount of physical memory (RAM) is full. If the system needs more memory resources and the RAM is full, inactive pages in memory are moved to the swap space. While swap space can help machines with a small amount of RAM, it should not be considered a replacement for more RAM. Swap space is located on hard drives, which have a slower access time than physical memory. Swap space can be a dedicated swap partition (recommended), a swap file, or a combination of swap partitions and swap files.
What is the standard swap recommendations ?
Recommended amount of swap space increased linearly with the amount of RAM in the system. However, modern systems often include hundreds of gigabytes of RAM. Below are the general recommendations of swap for RHEL systems.File systems and LVM2 volumes assigned as swap space should not be in use when being modified. Any attempts to modify swap fail if a system process or the kernel is using swap space. You can use the free and cat /proc/swaps commands to verify how much and where swap is in use.
Using top command you can validate the swap configuration of server. #top [Output is truncated to focus only line related to swap line] top - 03:16:25 up 21:27, 4 users, load average: 0.81, 0.71, 0.63 KiB Swap: 0 total, 0 free, 0 used. -> Swap memory is set to 0 which is not recommended for any server running applications.
First you need to verify the configuration setting of azure RHEL 7 VM and you can resize the swap space by doing the below steps.
1 #Modifying the waagent.conf 2 # Size of the swapfile.ResourceDisk.SwapSizeMB=0 //change this value to “8192” to make it 6 GB as example.// 3 #Restart the Azure Linux Agent service: systemctl restart waagent.service
#cp –p /etc/waagent.conf /etc/waagent.conf.$date # cat /etc/waagent.conf |egrep "ResourceDisk.EnableSwap|ResourceDisk.SwapSizeMB" ResourceDisk.EnableSwap=n ResourceDisk.SwapSizeMB=0
Step2 : Change the configuration as below
ResourceDisk.EnableSwap=n //Change this value to y.// Change the configuration as below ResourceDisk.SwapSizeMB=8192 //Change this value as per your requirement.Value should be in MB.//
Step 3 : Finally restart waagent service.considering you already have root privilege .
# systemctl restart waagent.service
Validation After Change
# cat /etc/waagent.conf |egrep "ResourceDisk.EnableSwap|ResourceDisk.SwapSizeMB" ResourceDisk.EnableSwap=y ResourceDisk.SwapSizeMB=8192 #top //This will also show new value for swap as configured above.//
That,s it about how to fix swap issues Azure VM. Using this procedure you can fix the swap issue with system.This process you can use to increase / decrease swap space if it is configured low or high to make you meet the requirement of applications running on server.
Learn more stuff about Azure VM as a bonus,like How to Resize VM in Azure.
For those who are interested to expand their knowledge in Azure Cloud which is being preferred cloud by enterprise clients. Below are few azure related e-books you can refer from one of the great global education brand –Inform IT which is part of Pearson Education.