Clearing Swap Memory Cache

Many time we may encounter with RAM overloads filling all the RAM memory and then using the swap memory(partition). Once you fixed the RAM usage problem and if you want to clear the cache on SWAP memory(disk). Just follow the simple steps.

 

Find out the exact swap partition on the server by using

 

  • # cat /etc/fstab

 

Search for the lines swap    defaults        0 0 the first right colum shows you the exact swap partiton (In the below example /dev/sda2 is the swap partiton):

 

/dev/sda2  swap  swap defaults  0 0

 

And if you are on LVM it may looks similar to (/dev/VolGroup00/LogVol01 is the swap volume for example)

 

/dev/VolGroup00/LogVol01 swap    swap    defaults        0 0

 

Now just turn off and turn using swapoff and swapon to clear the cache

 

  • # /sbin/swapoff /dev/sdax
    # /sbin/swapon  /dev/sdax

 

For LVM

 

  • # /sbin/swapoff /dev/VolGroup00/LogVolXX
    # /sbin/swapon  /dev/VolGroup00/LogVolXX

 

Use the top or free -m command to make sure the cache is cleared.