14

I get alert emails whenever swap usage is at 100%. In my case, swap usage doesn't reduce later on (even though memory is free) so I get an alert email every hour.

How can I reduce swap usage without rebooting my Linux server?

Christian Siegert
  • 241
  • 1
  • 2
  • 3
  • 1
    If your swap is regularly filling up, then you need to increase the amount of RAM in your server. – EEAA Jan 27 '12 at 14:30
  • I'd rather know what process is using the swap rather than throwing more ram at it, e.g. run top(press Op). – Mark Jan 27 '12 at 18:15
  • What is your swappiness set to? `cat /proc/sys/vm/swappiness` A high swappiness and small swap file means it will be full often. Reduce swappiness or increase the size of the swap file, or both. – Brian Sep 17 '14 at 19:27
  • @EEAA not necessarily. For instance the swap may be used although there is plenty of "free" memory, but the RAM is used largle for cached memory and buffers (to reproduce this I just need to make a tar file of a large disk). – Nemo Jul 01 '17 at 10:04

2 Answers2

15

You can run swapoff -a as root to swap all memory back in. Don't forget to run swapon -a afterwards to make swap available again. Note that swapoff will fail if there is not enough physical memory available to swap everything back in.

Lars Kotthoff
  • 646
  • 4
  • 10
0

I don't have an enough free RAM to clear swap space, then how can i troubleshoot it. please help me on it.

          total        used        free      shared  buff/cache   available

Mem: 31G 24G 4.7G 203M 1.7G 5.8G Swap: 23G 23G 13M

cat /proc/sys/vm/swappiness
10