linux redhat + swapoff is stuck not return prompt

Solution 1:

The swapoff command needs to flush all of the swapped memory from the swap file (/dev/mapper/rootvg-swap) back to main memory (or perhaps somewhere else) before it can disable the swap file. This can take time to complete and you may not have sufficient free memory.

You can increase the amount of free swap space that you have by adding more swap files

  • create a swap file/LV depending on what you have available
  • use mkswap to configure it
  • use swapon to enable it

The swapon man page contains more information about multiple swap files that may be helpful in particualar look at priorites.

The safest way to solve your problem is likely to reboot to single user mode and carry out the porcess you outline when the system is not under memory pressure.

The best solution is to size your system appropriately for its workload and to add more memory.

Solution 2:

I experienced this problem recently on a Centos 7 VM. I stopped and started swapoff several times because I was impatient and thought "nothing was happening".

On the last effort I tried running swapon --show on a separate terminal a few minutes apart and saw that the amount of swap being used was reducing, albeit at a snail's pace - i.e. 1.5MB/s, so it took about an hour and a quarter to finish as about 6.5GB were in swap - although there was plenty of main memory available. Eventually it finished successfully.